How to get values for ipi_ifindex for sendmsg()?

314 views Asked by At

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?

1

There are 1 answers

0
fadedbee On BEST ANSWER

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

if_indextoname() does the reverse.