On Linux, using C, how can I find the find the name of the bridge device my ethernet interface is attached to? Is there a sequence of ioctl()
calls I need to make to find the master bridge device?
My C program knows the device name of my TAP adapter from a configuration file (in this case, tap0
). Ultimately, I need the IP address that my TAP adapter responds to. Because it is bridged, the TAP adapter does not have an IP address; it is the bridge
device that has the IP address.
I have a TAP device and VETH device bridged together. ip a
shows the following:
1: lo: <LOOPBACK> mtu 65536 qdisc noop state DOWN group default
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: tap0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast master br0 state DOWN group default qlen 500
link/ether 22:d4:fa:a4:89:81 brd ff:ff:ff:ff:ff:ff
3: br0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default
link/ether 22:8c:ee:b8:e3:30 brd ff:ff:ff:ff:ff:ff
inet 10.20.30.40/24 scope global br0
valid_lft forever preferred_lft forever
45: veth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast master br0 state DOWN group default qlen 1000
link/ether 22:8c:ee:b8:e3:30 brd ff:ff:ff:ff:ff:ff
Note the tap0
and veth0
entries: each of their bridge master is br0
(i.e., they have bridge master br0
).
When I call ioctl(SIOCGIFFLAGS)
, and subsequently ioctl(SIOCGIFPFLAGS)
when ifr_name
is tap0
, the only flags that are set are IFF_UP
and IFF_BROADCAST
. I'm at a loss of where to go from here.