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.
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
.