Re: gethostbyname problem

Tech-Archive recommends: Speed Up your PC by fixing your registry



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



.



Relevant Pages

  • Re: gethostbyname problem
    ... For some reasons, gethostbyname() doesn't function ... WSADATA wsaData; ... What exactly is in this chHost string and what does it contain? ... But when try to use the same thing for the second time gethostbyname ...
    (microsoft.public.windowsce.embedded.vc)
  • Re: gethostbyname problem
    ... I tried with only one WSAStartup, But still facing the same issue. ... Paul G. Tobey wrote: ... WSADATA wsaData; ... But when try to use the same thing for the second time gethostbyname ...
    (microsoft.public.windowsce.embedded)
  • Re: [OT, redirect] Re: gethostbyname(string here)
    ... Artie Gold wrote: ... > of standard C) please ask in a forum specific to your platform. ... While the example is using gethostbyname(), ... string to the function. ...
    (comp.lang.c)
  • Re: [OT, redirect] Re: gethostbyname(string here)
    ... Kenneth Brody wrote: ... While the example is using gethostbyname(), the real question being ... and he had to remove it before passing the string to the function. ...
    (comp.lang.c)
  • Re: Struct Aligment set to 1 byte caused gethostbyname() access violat
    ... This seems to be some bug in your application, not the problem of gethostbyname. ... the compiler option "Struct Member Aligment" set to "1 Byte ... WSADATA wsaData; ...
    (microsoft.public.win32.programmer.networks)