Re: gethostbyname problem



Why are you calling WSAStartup twice?! That's probably the source of all of
your problems.

Paul T.

"Rajat" <raj.rr7@xxxxxxxxx> wrote in message
news:1156170123.066175.270980@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hi,

I am trying to resolve the DNS to get the IP using IP helper API
gethostbyname. The code is as follows:

hostent *hp = NULL;
struct in_addr srv_addr;
DWORD dwErr = 0;
WORD wVersionRequested;
WSADATA wsaData;
int err;

wVersionRequested = 0x0101;
err = WSAStartup( wVersionRequested, &wsaData );
if ( err != 0 )
{
return;
}

wVersionRequested = MAKEWORD(1, 1);
int nResult = WSAStartup(wVersionRequested, &wsaData);
if (nResult != 0)
{
return;
}

/* chHost contains name of the DNS to resolve*/
hp = gethostbyname(chHost);
dwErr = WSAGetLastError();
if (hp != NULL)
{
strcpy(chHostIP,inet_ntoa( *( struct in_addr*)( hp ->
h_addr_list[0])));
/* Printing the IP address*/
}

WSACleanup();

In this case for the very first time DNS is resolved and IP is given.
But when try to use the same thing for the second time gethostbyname
returns error WSANOTINITIALISED (Though WSAStartUp function is executed
successfully)

Does anybody ever find same behavior. Can anybody guide me what is
going wrong here.

Thanks in advance
Rajat



.



Relevant Pages

  • gethostbyname problem
    ... I am trying to resolve the DNS to get the IP using IP helper API ... WSADATA wsaData; ... In this case for the very first time DNS is resolved and IP is given. ... But when try to use the same thing for the second time gethostbyname ...
    (microsoft.public.windowsce.embedded.vc)
  • gethostbyname problem
    ... I am trying to resolve the DNS to get the IP using IP helper API ... WSADATA wsaData; ... In this case for the very first time DNS is resolved and IP is given. ... But when try to use the same thing for the second time gethostbyname ...
    (microsoft.public.pocketpc.developer)
  • gethostbyname problem
    ... I am trying to resolve the DNS to get the IP using IP helper API ... WSADATA wsaData; ... In this case for the very first time DNS is resolved and IP is given. ... But when try to use the same thing for the second time gethostbyname ...
    (microsoft.public.windowsce.embedded)
  • gethostbyname problem
    ... I am trying to resolve the DNS to get the IP using IP helper API ... WSADATA wsaData; ... In this case for the very first time DNS is resolved and IP is given. ... But when try to use the same thing for the second time gethostbyname ...
    (microsoft.public.pocketpc)
  • Re: gethostbyname problem
    ... Try not to call WSAStartup twice from the same process. ... I am trying to resolve the DNS to get the IP using IP helper API ... WSADATA wsaData; ... In this case for the very first time DNS is resolved and IP is given. ...
    (microsoft.public.pocketpc.developer)

Loading