title: Which header file to include for the use of gethostbyname_r() function
body: <p>I am using <code>gethostbyname_r()</code> function in my code, I am getting following error while compiling.</p>
  
  <p>gethostname.cpp:17: error: 'gethostbyname_r' was not declared in this scope</p>
  
  <p>My code:</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;
  #include&lt;netinet/in.h&gt;
  #include&lt;arpa/inet.h&gt;
  #include&lt;sys/file.h&gt;
  int main()
  {
    struct hostent hostbuf;
   struct hostent *hp = NULL;
   char* hostent_buff;
   int herr = 0;
   int hres = 0;
  
   hres = gethostbyname_r("domain name", &amp;hostbuf,
   hostent_buff, 1024, &amp;hp, &amp;herr);
  
   if (NULL == hp)
   {
   return -1;
   }
  
    return 0;
  }
  </code></pre>
  
  <p>Can anyone help me?
  And Can I use same same function gethostbyname_r() on Linux and Solaris?</p>