在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
最满意答案
是的,
this.props.children
将返回一个数组,所以如果你总是想加载特定的子this.props.children
,那么只需在你的包装器中通过索引引用这些子this.props.children
。 然后你可以将icons
和fields
转换为包装组件。 这是一个工作的jsfiddle 。 了解App
的render
方法是如何完全符合您的要求。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 turnicons
andfields
into wrapper components. Here is a working jsfiddle. See how therender
method ofApp
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>
相关问答
更多-
您需要将键传递给正在迭代的任何DOM元素。 您在
-
这是一个已知的问题 。 如果他们尚未报告,请始终首先检查GitHub并报告错误。 This is a known issue. Always check GitHub first and report bugs there if they aren’t reported yet.
-
const childrenProps = React.Children.map(this.props.children, (child) => React.cloneElement(child, { data : this.state, method : this.method.bind(this) // here you can pass state or method of parent component to child components })); // to ...
-
在React你做 const Comp = ({ children }) => ({children}); 在Angular2中你做到了 @Component({ selector: 'comp', template: `` }) class Comp {} in React you do c ...
-
一组中的两组数据(Two sets of data in one component)[2020-01-23]
使用Object.keys(component).map(function(attributes){}迭代id。我已经将它呈现为一个组件,你可以像函数一样使用它。我希望你可以把它转换成你想要的方式它。 class ListGroup extends React.Component { constructor(props) { super(props); } render() { return ({this.props.value.map(( ...React道具只有在React文档中说明才是真正的。 您可以遵循JSX方法,它总是创建新元素,而不是更改现有的元素道具。 在稍后阶段,元素与虚拟DOM中的现有React组件协调一致。 要通过JavaScript更改元素的道具,可以使用React.cloneElement方法克隆元素。 请注意,在这种情况下,您不应呈现this.props.children,而应渲染新的结果元素树: render() { const func = (children) => { return React.Chil ...在路由反应组件内无法呈现子项(更不用说路由子项)(Can't render children (let alone routed children) inside routed react component)[2023-05-14]
AuthenticatedFrame是一个功能组件,因此无法访问this关键字,您需要像访问功能参数那样访问道具 export const AuthenticatedFrame = (props) => ({props.children}设置contenteditable html属性允许在浏览器中修改该元素的内容。 React警告您在该元素中有React管理的子节点。 React仅从上到下工作。 这意味着它管理顶级模型并维护表示该数据的虚拟DOM,然后基于该虚拟DOM呈现DOM树。 您在React之外对DOM所做的任何更改(例如设置contenteditable并允许用户直接在浏览器中编辑内容)都可能会在更新这些托管元素时被泄露或导致React出现问题。 在你的情况下,你并不关心{this.props.children}节点被吹走,因为你 ...是的, this.props.children将返回一个数组,所以如果你总是想加载特定的子this.props.children ,那么只需在你的包装器中通过索引引用这些子this.props.children 。 然后你可以将icons和fields转换为包装组件。 这是一个工作的jsfiddle 。 了解App的render方法是如何完全符合您的要求。 CreditCardForm呈现:codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)- 在计算机拍照在哪里进入
- 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
- No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
- 单页应用程序:页面重新加载(Single Page Application: page reload)
- 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
- System.StackOverflow错误(System.StackOverflow error)
- KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
- 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
- android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
- TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
- 企业安全培训的各项内容
- 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
- C#类名中允许哪些字符?(What characters are allowed in C# class name?)
- NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
- 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
- 将多个行和可变行移动到列(moving multiple and variable rows to columns)
- 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
- 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
- Angular $资源不会改变方法(Angular $resource doesn't change method)
- 在Angular 5中不是一个函数(is not a function in Angular 5)
- 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
- 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
- 常见的python rpc和cli接口(Common python rpc and cli interface)
- Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
- 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)