Python:获取IPv6套接字以接收目标为子网路由器任播地址的数据包(Python: Getting an IPv6 socket to receive packets destined for t

编程入门 行业动态 更新时间:2024-10-27 07:24:02
Python:获取IPv6套接字以接收目标为子网路由器任播地址的数据包(Python: Getting an IPv6 socket to receive packets destined for the Subnet-Routers Anycast address)

你如何得到一个套接字接收去往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!

更多推荐

本文发布于:2023-07-18 11:38:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1159803.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:子网   路由器   数据包   目标   地址

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!