简体   繁体   English

如何获取sendmsg()的ipi_ifindex值?

[英]How to get values for ipi_ifindex for sendmsg()?

Using sendmsg() it is possible to specify from which interface a datagram will be sent, if a value is set for in_pktinfo.ipi_ifindex . 如果为in_pktinfo.ipi_ifindex设置了值,则可以使用sendmsg()指定从哪个接口发送数据报。

If the packet is a response to a datagram received with recvmsg() I can get the interface value from there. 如果数据包是对使用recvmsg()接收到的数据报的响应,则可以从那里获取接口值。

If I just know that the interface if 'eth0' or 'eno1', how can I look up the corresponding `in_pktinfo.ipi_ifindex' value? 如果我只知道接口为'eth0'或'eno1',我如何查找相应的'in_pktinfo.ipi_ifindex'值?

Use if_nametoindex() to convert the interface name to an index. 使用if_nametoindex()将接口名称转换为索引。

if_indextoname() does the reverse. if_indextoname()进行相反的操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM