title: netdb.h not linking properly
body: <p>I'm trying to compile this program, as referenced in <em>Beej's Guide to Network Programming</em> on page 19.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;netdb.h&gt;
  #include &lt;sys/types.h&gt;
  #include &lt;sys/socket.h&gt;
  
  int main() {
      int status;
      struct addrinfo hints;
      struct addrinfo *servinfo;          /* Will point to the results */
      memset(&amp;hints, 0, sizeof hints);    /* Make sure the struct is empty */
      hints.ai_family = AF_UNSPEC;        /* Don't care IPv4 or IPv6 */
      hints.ai_socktype = SOCK_STREAM;
      hints.ai_flags = AI_PASSIVE;
  
      if ((status = getaddrinfo(NULL, "3490", &amp;hints, &amp;servinfo)) != 0) {
          fprintf(stderr, "getaddrinfo error: %s\n", gai_strerror(status));
          exit(1);
      }
  
      /* Servinfo now points to a linked list of 1 or more struct addrinfos
          ... do everything until you don't need servinfo anymore .... */
  
      freeaddrinfo(servinfo); /* Free the linked-list */
  
      return 0;
  }    
  </code></pre>
  
  <p>Among other errors, I see</p>
  
  <pre><code>../main.c:8:18: error: storage size of ‘hints’ isn’t known
  ../main.c:13:19: error: ‘AI_PASSIVE’ undeclared (first use in this function)
  ../main.c:16:3: warning: implicit declaration of function ‘gai_strerror’
  </code></pre>
  
  <p>It appears that gcc isn't linking with <code>netdb.h</code>. Eclipse, the IDE that I'm using to build this, has no trouble finding the file. Here's the compiler command:</p>
  
  <pre><code>gcc -O0 -g3 -pedantic -Wall -c -fmessage-length=0 -ansi -MMD -MP -MF"main.d" -MT"main.d" -o"main.o" "../main.c"
  </code></pre>
  
  <p>Adding <code>-lnetdb</code> doesn't resolve the issue. Also...</p>
  
  <pre><code>~&gt; find /usr/include/ -name netdb.h
  /usr/include/bits/netdb.h
  /usr/include/gssrpc/netdb.h
  /usr/include/netdb.h
  /usr/include/rpc/netdb.h
  </code></pre>
  
  <p>I think these files came preinstalled on my openSUSE host. Why doesn't gcc detect <code>netdb.h</code>? Or am I drawing the wrong conclusion?</p>