I want to get all the physical interfaces on a system, I saw a lot of references to getifaddrss but it gets all interfaces, disregarding whether it's vlan / macvlan or physical interface.
I can only assume netlink
will be able to do so (when a socket is created out of a network namespace).
Asked
Active
Viewed 560 times
1

SagiLow
- 5,721
- 9
- 60
- 115
1 Answers
0
Use sysfs -- simply walk over /sys/class/net
. It will also show relationship between devices such as bonding, bridges. However VLAN may only be guessed from device name (there are patches that bind 8021q
to sysfs, but they were not accepted to kernel).
Here is my code that does this: https://github.com/myaut/tsload/blob/master/agent/lib/libhostinfo/plat/linux/netinfo.c

myaut
- 11,174
- 2
- 30
- 62