title: Error 97 when calling socket() on Debian inside VirtualBox
body: <p>I am working on creating a simple server in C. Right now I'm having trouble creating the socket to listen for incoming connections.
  I am on an x86 <strong>Debian</strong> distro running inside <strong>VirtualBox</strong>.
  My code is as follows: </p>
  
  <pre><code>#define _POSIX_SOURCE
  
  #include &lt;stdio.h&gt;
  #include &lt;pthread.h&gt;    /* threads, yo */
  #include &lt;stdlib.h&gt;
  #include &lt;memory.h&gt;     /* memset */
  
  #include &lt;errno.h&gt;
  #include &lt;sys/types.h&gt;
  #include &lt;sys/socket.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;netdb.h&gt;
  
  #include &lt;arpa/inet.h&gt;  /* helpers like inet_ntop */ 
  #include &lt;netinet/in.h&gt;
  
  void listenInput();
  
  void* handleConn(void* args) {
      printf("Handling connection!\n");
      listenInput();
      return NULL;
  }
  
  void acceptData(int socket) {
  
  
  }
  
  void listenInput() {
      struct addrinfo hints;
      struct addrinfo *sockadr;
      char ipstr[INET6_ADDRSTRLEN];
      int status;
      struct addrinfo *p = sockadr;
      int s;
      int yes = 1;
  
      memset(&amp;hints, 0, sizeof(hints));
      hints.ai_family = AF_INET;
      hints.ai_socktype = SOCK_STREAM;
      hints.ai_flags = AI_PASSIVE;
  
      printf("Getting addr info. Preparing to listen on port 8080\n");
      if((status = getaddrinfo(NULL, "8080", &amp;hints, &amp;sockadr)) != 0) {
          printf("getaddrinfo: %s\n", gai_strerror(status));
          return;
      }
  
      printf("Woo, got addr info!\n");
      printf("Calling socket(...)\n");
      if( -1 == (s = socket(p-&gt;ai_family, p-&gt;ai_socktype, p-&gt;ai_protocol))) {
          printf("Error creating socket (%d): %s\n", errno, gai_strerror(errno));
          return;
      }
  
          printf("Calling bind\n");
          bind(s, p-&gt;ai_addr, p-&gt;ai_addrlen);
  
          printf("Calling listen...\n");
          listen(s, 5);
          {
              struct sockaddr_storage their_addr;
              socklen_t addr_size = sizeof their_addr;
  
              printf("accept()...\n");
              int newsocket = accept(s, (struct sockaddr *)&amp;their_addr, &amp;addr_size);
  
              printf("Got a connection! New socket: %d\n", newsocket);
          }
  
          close(s);
  
  
      freeaddrinfo(sockadr);
  }
  
  int main(int argc, char** argv) {
      pthread_t   thread;
      void*       status;
  
      pthread_create(&amp;thread, NULL, handleConn, NULL);
      pthread_join(thread, &amp;status);
      printf("Joined thread!\n");
      return 0;
  }
  </code></pre>
  
  <p>When running this, <code>socket()</code> fails with an error code 97 - Address family not supported.
  I have failed to find any relevant information about this issue so far.</p>
  
  <p>Here is the output of <code>ifconfig</code> inside my virtual machine:</p>
  
  <pre><code>eth0      Link encap:Ethernet  HWaddr 08:00:27:11:84:ee  
            inet addr:192.168.56.101  Bcast:192.168.56.255  Mask:255.255.255.0
            inet6 addr: fe80::a00:27ff:fe11:84ee/64 Scope:Link
            UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
            RX packets:122 errors:0 dropped:0 overruns:0 frame:0
            TX packets:104 errors:0 dropped:0 overruns:0 carrier:0
            collisions:0 txqueuelen:1000 
            RX bytes:17778 (17.3 KiB)  TX bytes:14571 (14.2 KiB)
  
  lo        Link encap:Local Loopback  
            inet addr:127.0.0.1  Mask:255.0.0.0
            inet6 addr: ::1/128 Scope:Host
            UP LOOPBACK RUNNING  MTU:16436  Metric:1
            RX packets:64 errors:0 dropped:0 overruns:0 frame:0
            TX packets:64 errors:0 dropped:0 overruns:0 carrier:0
            collisions:0 txqueuelen:0 
            RX bytes:4652 (4.5 KiB)  TX bytes:4652 (4.5 KiB)
  </code></pre>
  
  <p>Moreover, <code>netstat --tcp</code> shows other stream sockets listening, so other apps seem to succeed creating them.</p>