首页 \ 问答 \ 在Linux上接收所有组播ICMPv6数据包(Receive all multicast ICMPv6 packets on Linux)

在Linux上接收所有组播ICMPv6数据包(Receive all multicast ICMPv6 packets on Linux)

我希望接收到达某个接口的所有多播IPv6数据包,如果可能的话,不需要在第2层上操作。

我为原始ICMPv6数据包打开一个套接字,并且接收专用于我的机器的单播数据包工作正常。 然而,许多ICMPv6分组是链路本地多播(例如,邻居请求)。 侦听所有多播流量的正确方法是什么,包括请求节点多播? 目前我尝试使用IPV6_ADD_MEMBERSHIP添加多播组,但这似乎不起作用。 这是我的代码:

/* open RAW socket to receive on */
if ((sockfd = socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6)) < 0) {
    perror("socket");
}

/* get device index */
memset(&if_idx, 0, sizeof(struct ifreq));
strncpy(if_idx.ifr_name, DEVNAME, IFNAMSIZ-1);
if (ioctl(sockfd, SIOCGIFINDEX, &if_idx) < 0) {
    perror("SIOCGIFINDEX");
}

/* configure to receive all multicast packets on this interface */
memset(&mreq, 0, sizeof(struct ipv6_mreq));
inet_pton(AF_INET6, "ff02::", &mreq.ipv6mr_multiaddr);
mreq.ipv6mr_interface = if_idx.ifr_ifindex;
if (setsockopt(sockfd, SOL_SOCKET, IPV6_ADD_MEMBERSHIP, &mreq,
            sizeof(struct ipv6_mreq)) < 0) {
    perror("setsockopt");
}

我究竟做错了什么? 我想要的东西必须以某种方式。 我尝试将ff02 ::和ff02 :: 1:ff00:0作为组,后者甚至使setsockopt失败。 这是怎么回事? 遗憾的是,关于IPv6多播编程的文档很少。


I would like to receive all multicast IPv6 packets arriving on a certain interface, without resorting to operate on layer 2, if that is possible.

I open a socket for raw ICMPv6 packets, and receiving unicast packets dedicated for my machine works just fine. However many ICMPv6 packets are link-local multicast (e.g. neighbor solicitations). What's the right way to listen for all multicast traffic, including solicited-node multicast? Currently I try to add a multicast group with IPV6_ADD_MEMBERSHIP, but this does not seem to work. Here's my code:

/* open RAW socket to receive on */
if ((sockfd = socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6)) < 0) {
    perror("socket");
}

/* get device index */
memset(&if_idx, 0, sizeof(struct ifreq));
strncpy(if_idx.ifr_name, DEVNAME, IFNAMSIZ-1);
if (ioctl(sockfd, SIOCGIFINDEX, &if_idx) < 0) {
    perror("SIOCGIFINDEX");
}

/* configure to receive all multicast packets on this interface */
memset(&mreq, 0, sizeof(struct ipv6_mreq));
inet_pton(AF_INET6, "ff02::", &mreq.ipv6mr_multiaddr);
mreq.ipv6mr_interface = if_idx.ifr_ifindex;
if (setsockopt(sockfd, SOL_SOCKET, IPV6_ADD_MEMBERSHIP, &mreq,
            sizeof(struct ipv6_mreq)) < 0) {
    perror("setsockopt");
}

What am I doing wrong? What I want must be possible somehow. I tried ff02:: and ff02::1:ff00:0 as groups, and the latter even made setsockopt fail. What's going on? Unfortunately there's very little documentation on IPv6 multicast programming.


原文:https://stackoverflow.com/questions/12628953
更新时间:2022-03-08 17:03

最满意答案

是的, this.props.children将返回一个数组,所以如果你总是想加载特定的子this.props.children ,那么只需在你的包装器中通过索引引用这些子this.props.children 。 然后你可以将iconsfields转换为包装组件。 这是一个工作的jsfiddle 。 了解Apprender方法是如何完全符合您的要求。

CreditCardForm呈现:

<div>
    <div className='some'>
      <div className='special'>
        <div className='nesting'>
          {this.props.children[0]}
        </div>
      </div>
    </div>
    {this.props.children[1]}
 </div>

字段和图标呈现:

<div>{this.props.children}</div>

应用渲染:

<CreditCardForm>
    <Icons>
        <IconBogus />
    </Icons>
    <Fields>
      <FieldCardNumber />
      <FieldName />
    </Fields>
</CreditCardForm>

Yes, this.props.children will return an array so if you always want to load specific children, then just reference those children by index in your wrapper. Then you could just turn icons and fields into wrapper components. Here is a working jsfiddle. See how the render method of App is exactly what you want.

CreditCardForm render:

<div>
    <div className='some'>
      <div className='special'>
        <div className='nesting'>
          {this.props.children[0]}
        </div>
      </div>
    </div>
    {this.props.children[1]}
 </div>

Fields and Icons render:

<div>{this.props.children}</div>

App render:

<CreditCardForm>
    <Icons>
        <IconBogus />
    </Icons>
    <Fields>
      <FieldCardNumber />
      <FieldName />
    </Fields>
</CreditCardForm>

相关问答

更多