Question

I'm trying to find programmatically the inet address of an Infiniband interface whose name is not know a priori.

I'm on Linux, and I would like to avoid the parsing of ifconfig (8) output. I've read the second comment on this answer, that suggests to use getifaddrs() to retrieve the interfaces, but then I cannot select the Infiniband one.

Any help is very appreciated.

Was it helpful?

Solution

getifaddrs() returns one entry of type AF_PACKET for each interface, which has hardware address details, as described in this answer. In particular, the iface->ifa_addr holds a struct sockaddr_ll, and the sll_hatype member of that structure holds the hardware address type. So to figure out which interfaces are IPoIB you can just check which ones have hardware type ARPHRD_INFINIBAND.

OTHER TIPS

You could try parsing some file under /proc/net/ like /proc/net/if_inet6 & /proc/net/dev. You can learn what ifconfig does by strace-ing it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top