Socket connect realization: gethostbyname or getnameinfo for now I'm using:

int connect(const String&amp; address, int port) {
    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 ERROR;
    //TODO: gethostbyname is obsolete.
    if((host = (struct hostent*) gethostbyname(address)) == 0)
        return ERROR;
    memset(&amp;servAddr, 0, sizeof(servAddr));
    servAddr.sin_family      = AF_INET;
    servAddr.sin_addr.s_addr = inet_addr(inet_ntoa(*(struct in_addr*)(host -&gt; h_addr_list[0])));
    servAddr.sin_port        = htons(port);
    if(::connect(handle, (struct sockaddr*) &amp;servAddr, sizeof(servAddr)) &lt; 0)
        return ERROR;
    return OK;
    }


this procedure but everytime I compile it I'm getting:

socket.cpp:(.text+0x374): warning: gethostbyname is obsolescent, use getnameinfo() instead.

getname info is still being confusing stuff for me. here is my try to implement it:

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 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 ERROR;

if (::connect(handle, (struct sockaddr *) &amp;servAddr, sizeof(servAddr)) &lt; 0)
    return ERROR;


-- yes this doesn't work :(

Maybe I should use getaddrinfo instead? 

getaddrinfo(hostname, NULL, &amp;hints, &amp;res) - can I use it alike gethostbyname? but where is host actually here? hints?

Working recode based on answer:

int Socket::connect(const String&amp; address, int port) {
    struct sockaddr_in servAddr;
    /* open socket */
    if((handle = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) &lt; 0)
        return ERROR;
    //gethostbyname by getaddrinfo replacement
    addrinfo hints = {sizeof(addrinfo)};
    hints.ai_flags = AI_ALL;
    hints.ai_family = PF_INET;
    hints.ai_protocol = 4; //IPPROTO_IPV4
    addrinfo* pResult = NULL;
    int errcode = getaddrinfo(address, NULL, &amp;hints, &amp;pResult);
    if(errcode != 0)
        return ERROR;
    memset(&amp;servAddr, 0, sizeof(servAddr));
    servAddr.sin_family      = AF_INET;
    servAddr.sin_addr.s_addr = *((uint32_t*) &amp; (((sockaddr_in*)pResult-&gt;ai_addr)-&gt;sin_addr));
    servAddr.sin_port        = htons(port);
    if(::connect(handle, (struct sockaddr*) &amp;servAddr, sizeof(servAddr)) &lt; 0)
        return ERROR;
    return OK;
    }
This works for me:

int connect2(const CStringA&amp; address, int port) {
  struct sockaddr_in servAddr;
  /* open socket */
  SOCKET handle;
  if((handle = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) &lt; 0)
    return ERROR;
  //gethostbyname by getaddrinfo replacement
  ADDRINFO hints;
  ZeroMemory(&amp;hints, sizeof(hints));
  hints.ai_flags = AI_ALL;
  hints.ai_family = PF_INET;
  hints.ai_protocol = IPPROTO_IPV4;
  ADDRINFO* pResult = NULL;
  int errcode = getaddrinfo((LPCSTR)address, NULL, &amp;hints, &amp;pResult);
  if(errcode != 0)
    return ERROR;
  memset(&amp;servAddr, 0, sizeof(servAddr));
  servAddr.sin_family      = AF_INET;
  servAddr.sin_addr.S_un.S_addr = *((ULONG*)&amp;(((sockaddr_in*)pResult-&gt;ai_addr)-&gt;sin_addr));
  servAddr.sin_port        = htons(port);
  if(::connect(handle, (struct sockaddr*) &amp;servAddr, sizeof(servAddr)) &lt; 0)
    return ERROR;
  return OK;
}