title: binding socket to specific interface
body: <p>I am trying to bind a socket to the specific (loopback) interface <code>lo</code> to prevent outside traffic from interfering with it:</p>
  
  <pre><code>int bind_socket(uint8_t *iface, uint8_t port) {
          int rv;
          struct sockaddr_in addr;
          rv = socket(AF_INET, SOCK_STREAM, 0);
          if (rv &lt; 0) return -1;
          if (setsockopt(rv, SOL_SOCKET, SO_BINDTODEVICE, iface, strlen(iface)) &lt; 0) {
                  return -2;
          }
          bzero((char *) &amp;addr, sizeof(addr));
          addr.sin_family = AF_INET;
          addr.sin_addr.s_addr = INADDR_ANY;
          addr.sin_port = htons(port);
          if (bind(rv, (struct sockaddr *) &amp;addr, sizeof(addr)) &lt; 0)
                  return -3;
          return rv;
  }
  
  ...
  
  int ss;
  ss = bind_socket("lo", 100);
  </code></pre>
  
  <p>However, if I run <code>nmap localhost -e wlpXsX</code>, I should not be getting output indicating the socket is available through that interface. It is instead being reported as available; and I can't seem to be able to deduce why. Why is this interface globally available with a program designed to make it unavailable to all other interfaces?</p>