Re: gethostbyname problem
- From: "Rajat" <raj.rr7@xxxxxxxxx>
- Date: 25 Aug 2006 04:43:17 -0700
Hi,
I really apologize for the mistake. Thanks for your reply.
Regards,
Rajat
voidcoder wrote:
Just because of your evil improper cross posting
you don't see now answers in another NGs. Check
my advice in the microsoft.public.pocketpc.
For some reasons, gethostbyname() doesn't function
correctly in some situations on WM2003 and WM5, and
especially on WM emulators.
On Fri, 25 Aug 2006 09:35:45 +0200, Rajat <raj.rr7@xxxxxxxxx> wrote:
Hi,
Thanks for the reply
I get the problem in the following code also
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;
}
/* 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 code snippet the chHost is the host name not an IP address in
quated text.
This code execute well first time. When i try to execute the same code
second time it returns error WSANOTINITIALISED. Any suggessions are
appreciated
Ulrich Eckhardt wrote:
Rajat wrote:
I am trying to resolve the DNS to get the IP using IP helper API[...]
gethostbyname with EVC++ and WM 5.0. The code is as follows:
wVersionRequested = 0x0101;
err = WSAStartup( wVersionRequested, &wsaData );
if ( err != 0 )
{
return;
}
wVersionRequested = MAKEWORD(1, 1);
int nResult = WSAStartup(wVersionRequested, &wsaData);
if (nResult != 0)
{
return;
}
What, init twice just to be sure? That btw also means you have to cleanup
twice!
/* chHost contains name of the DNS to resolve*/
Errmm... in order to resolve names, you already need a DNS (Domain Name
Server). What exactly is in this chHost string and what does it contain?
hp = gethostbyname(chHost);
Just in case you missed it and your string is something like "192.168.0.1",
then you should reread the MSDN documentation (e.g. at msdn.microsoft.com).
gethostbyname() doesn't parse strings in dotted quad notation, it only
resolves hostnames.
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)
Hmmm, now this is strange. I definitely found this to work according to the
docs in CE4.2. I guess that it's related to the double init though.
Uli
.
- References:
- gethostbyname problem
- From: Rajat
- Re: gethostbyname problem
- From: Ulrich Eckhardt
- Re: gethostbyname problem
- From: Rajat
- Re: gethostbyname problem
- From: voidcoder
- gethostbyname problem
- Prev by Date: Re: DirectX SDK samples execution problems (ITA - ENG)
- Next by Date: Re: DirectX SDK samples execution problems (ITA - ENG)
- Previous by thread: Re: gethostbyname problem
- Next by thread: Re: gethostbyname problem
- Index(es):
Relevant Pages
|