title: How to use getnameinfo instead of gethostbyname?
body: <p>in code :</p>
  
  <pre><code>if ((host = (struct hostent*) gethostbyname(address) ) == 0) // address is a string
  </code></pre>
  
  <p>I've got warning when cross compiling (generic arm architecture) on 4.5.x gcc :</p>
  
  <pre><code>(.text+0x1558): warning: gethostbyname is obsolescent, use getnameinfo() instead.
  </code></pre>
  
  <p><a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms738532%28v=vs.85%29.aspx" rel="noreferrer">getnameinfo</a> is:</p>
  
  <pre><code>int WSAAPI getnameinfo(
    __in   const struct sockaddr FAR *sa,
    __in   socklen_t salen,
    __out  char FAR *host,
    __in   DWORD hostlen,
    __out  char FAR *serv,
    __in   DWORD servlen,
    __in   int flags
  );
  </code></pre>
  
  <p>And it got more parameters... And I'm confused with it, I just need it work as gethostbyname were working. What parameter to pass to keep it simple stupid as it was with gethostbyname?</p>
  
  <p>Finally here is my try: </p>
  
  <pre><code>struct sockaddr_in servAddr;
  struct hostent *host;        /* Structure containing host information */
  
  /* open socket */
  if ((handle = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) &lt; 0)
      return LILI_ERROR;
  
  memset(&amp;servAddr, 0, sizeof(servAddr));
  servAddr.sin_family      = AF_INET;
  servAddr.sin_addr.s_addr = inet_addr(address.ptr());
  servAddr.sin_port        = htons(port);
  
  char servInfo[NI_MAXSERV];
  if ( ( host = (hostent*) getnameinfo(
                   (struct sockaddr *) &amp;servAddr
                   ,sizeof (struct sockaddr)
                   ,address.ptr(), address.size()
                   ,servInfo, NI_MAXSERV
                   ,NI_NUMERICHOST | NI_NUMERICSERV )  ) == 0)
      return LILI_ERROR;
  
  if (::connect(handle, (struct sockaddr *) &amp;servAddr, sizeof(servAddr)) &lt; 0)
      return LILI_ERROR;
  </code></pre>
  
  <p>It compiles well and no segmentation fault on start up but I can't connect my server with it :(</p>