0

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.

Community
  • 1
  • 1
Luca Martini
  • 1,434
  • 1
  • 15
  • 35

2 Answers2

2

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.

Community
  • 1
  • 1
Roland
  • 6,227
  • 23
  • 29
  • Thank you very much. I recovered the ib interface name and then iterated again on the list (returned by `getifaddrs`) to get the entry with the type `AF_INET`. – Luca Martini Nov 28 '11 at 09:44
0

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.

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547