你如何得到一个套接字接收去往IPv6子网路由器任播地址的数据包?
我一直无法找到关于如何做到这一点的任何信息。
在绝望中,我尝试使用socket.setsockopt来加入一个多播组:
# 7 is the interface number s = socket(AF_INET6, SOCK_DGRAM) packed_iface_num = struct.pack("I", 7) group = inet_pton(AF_INET6, 'fd36:d00d:d00d:47cb::') + packed_iface_num # socket.error: (22, 'Invalid argument') s.setsockopt(IPPROTO_IPV6, IPV6_JOIN_GROUP, group)并且还使用绑定
# socket.error: (99, 'Cannot assign requested address') s.bind(('fd36:773e:6b4c:47cb::', 9876))正如所料,这些都没有奏效。 有没有办法做到这一点?
How do you get a socket to receive packets destined for the IPv6 Subnet-Routers Anycast address?
I haven't been able to find any informationn on how to do this.
In a fit of desparation, I've tried using socket.setsockopt as you would to join a multicast group:
# 7 is the interface number s = socket(AF_INET6, SOCK_DGRAM) packed_iface_num = struct.pack("I", 7) group = inet_pton(AF_INET6, 'fd36:d00d:d00d:47cb::') + packed_iface_num # socket.error: (22, 'Invalid argument') s.setsockopt(IPPROTO_IPV6, IPV6_JOIN_GROUP, group)And also using bind
# socket.error: (99, 'Cannot assign requested address') s.bind(('fd36:773e:6b4c:47cb::', 9876))As expected, neither of these worked. Is there a way to do this?
最满意答案
尝试将IPV6_JOIN_ANYCAST传递给s.setsockopt()代码,而不是IPV6_JOIN_GROUP 。 不幸的是,Python socket模块没有定义它,但你应该能够传递相应的整数。 在Linux中, IPV6_JOIN_ANYCAST是27 , IPV6_LEAVE_ANYCAST是28 。 (在/usr/include/linux/in6.h中定义)
我能找到的最好的文档是从这个lkml电子邮件描述Linux内核的anycast补丁 :
加入和离开任播组的应用程序接口是2个新的setsockopt()调用:IPV6_JOIN_ANYCAST和IPV6_LEAVE_ANYCAST。 参数与相应的多播操作相同。
愿舞蹈与你同在!
Instead of IPV6_JOIN_GROUP, try passing IPV6_JOIN_ANYCAST to your s.setsockopt() code. Unfortunately the Python socket module doesn't define it but you should be able to pass the integer equivalent instead. In Linux IPV6_JOIN_ANYCAST is 27 and IPV6_LEAVE_ANYCAST is 28. (defined in /usr/include/linux/in6.h)
The best documentation I could find is from this lkml e-mail describing the anycast patch to the Linux kernel:
The application interface for joining and leaving anycast groups is 2 new setsockopt() calls: IPV6_JOIN_ANYCAST and IPV6_LEAVE_ANYCAST. The arguments are the same as the corresponding multicast operations.
May the dancing kame be with you!
更多推荐
发布评论