title: How can I find the bridge device name for my tap adapter in C?
body: <p>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 <code>ioctl()</code> calls I need to make to find the master bridge device?</p>
  
  <p>My C program knows the device name of my TAP adapter from a configuration file (in this case, <code>tap0</code>). 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 <code>bridge</code> device that has the IP address.</p>
  
  <p>I have a TAP device and VETH device bridged together. <code>ip a</code> shows the following:</p>
  
  <pre><code>1: lo: &lt;LOOPBACK&gt; 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: &lt;NO-CARRIER,BROADCAST,MULTICAST,UP&gt; 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: &lt;NO-CARRIER,BROADCAST,MULTICAST,UP&gt; 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: &lt;NO-CARRIER,BROADCAST,MULTICAST,UP&gt; 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
  </code></pre>
  
  <p>Note the <code>tap0</code> and <code>veth0</code> entries: each of their bridge master is <code>br0</code> (i.e., they have bridge <code>master br0</code>).</p>
  
  <p>When I call <code>ioctl(SIOCGIFFLAGS)</code>, and subsequently <code>ioctl(SIOCGIFPFLAGS)</code> when <code>ifr_name</code> is <code>tap0</code>, the only flags that are set are <code>IFF_UP</code> and <code>IFF_BROADCAST</code>. I'm at a loss of where to go from here.</p>