title: How to find the scope_id for an IPv6 socket
body: <p>I use a IPv6 UDP socket connection in my code. The execution fails, because the device does not exist. </p>
  
  <pre><code>strerror(errno)
  </code></pre>
  
  <p>responded with</p>
  
  <pre><code>No such device
  </code></pre>
  
  <p>I use a link local address. </p>
  
  <p>Server</p>
  
  <pre><code>fe80::213:afff:fe94:d75
  </code></pre>
  
  <p>Client</p>
  
  <pre><code>fe80::f2d5:bfff:fe10:f1b1
  </code></pre>
  
  <p>I got the scope_id by ifconfig:</p>
  
  <pre><code>bt0: flags=4177&lt;UP,POINTOPOINT,RUNNING,MULTICAST&gt;  mtu 1280
          inet6 fe80::f2d5:bfff:fe10:f1b1  prefixlen 64  scopeid 0x20&lt;link&gt;
          unspec F0-D5-BF-FF-FE-10-F1-B1-00-00-00-00-00-00-00-00  txqueuelen 1000  (UNSPEC)
          RX packets 3  bytes 84 (84.0 B)
          RX errors 0  dropped 0  overruns 0  frame 0
          TX packets 11  bytes 370 (370.0 B)
          TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
  </code></pre>
  
  <p>Since another interface has the same scope_id, I guess the scope_id means here the IPv6 scope. 0x20 = link_local. </p>
  
  <pre><code>enp0s31f6: flags=4163&lt;UP,BROADCAST,RUNNING,MULTICAST&gt;  mtu 1500
          inet 192.168.0.4  netmask 255.255.255.0  broadcast 192.168.0.255
          inet6 fe80::fb58:43b9:10fa:101  prefixlen 64  scopeid 0x20&lt;link&gt;
          inet6 2a02:8109:b6bf:ca24:ae7f:b967:932e:b2f4  prefixlen 64  scopeid 0x0&lt;global&gt;
          inet6 2a02:8109:b6bf:ca24:51f:6c37:66c4:5282  prefixlen 64  scopeid 0x0&lt;global&gt;
          ether c8:5b:76:98:55:bf  txqueuelen 1000  (Ethernet)
          RX packets 16413820  bytes 20299047086 (20.2 GB)
          RX errors 18  dropped 0  overruns 0  frame 16
          TX packets 6110718  bytes 714537636 (714.5 MB)
          TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
          device interrupt 16  memory 0xf1200000-f1220000  
  </code></pre>
  
  <p>So, I used this scope_id in my code:</p>
  
  <pre><code>#define CLIENT_ADDRESS { 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf2, 0xd5, 0xbf, 0xff, 0xfe, 0x10, 0xf1, 0xb1 };
  
  struct sockaddr_in6 client_addr;
  unsigned int client_addr_len = sizeof(client_addr);
  memset(&amp;client_addr, 0, client_addr_len);
  client_addr.sin6_family = AF_INET6;
  client_addr.sin6_port = htons(PORT);
  client_addr.sin6_scope_id = 0x20;
  uint8_t address[16] = CLIENT_ADDRESS;
  memcpy(&amp;client_addr.sin6_addr, address, 16);
  </code></pre>
  
  <p>This is not the correct interface. </p>
  
  <p>So my question: Where can I find the correct scope_id for my interface? </p>
  
  <p>Is there some linux tool to get it? </p>