linuxudpsendmsg

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.

If the packet is a response to a datagram received with recvmsg() I can get the interface value from there.

If I just know that the interface if 'eth0' or 'eno1', how can I look up the corresponding `in_pktinfo.ipi_ifindex' value?


Solution

  • Use if_nametoindex() to convert the interface name to an index.

    if_indextoname() does the reverse.