BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

gethostbyaddr() does not return any info

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Native API)
View previous topic :: View next topic  
Author Message
Kris
Guest





PostPosted: Tue May 15, 2007 1:46 pm    Post subject: gethostbyaddr() does not return any info Reply with quote



Hi,

I'm attempting to obtain the NetBIOS name of given IP address (which is
a NAS device in my LAN).

However, the gethostbyaddr() call always returns NULL and the
WSAGetLastError() returns 6 (=WSA_INVALID_HANDLE).

Does anybody know what I'm doing wrong ? The code below shows following
output:

Address=1711280300
RemoteHost=00000000
Error=6

struct hostent* RemoteHost;
unsigned int Address;
char host_name[]="172.16.0.102";

Address=inet_addr(host_name);
DEBUG("Address=%d",Address);

RemoteHost=gethostbyaddr((char*)&Address,4,AF_INET);
DEBUG("RemoteHost=%08X",RemoteHost);

int Error=WSAGetLastError();
DEBUG("Error=%d",Error);


Thanks,

Kris
Back to top
Hans Galema
Guest





PostPosted: Tue May 15, 2007 2:35 pm    Post subject: Re: gethostbyaddr() does not return any info Reply with quote



Kris wrote:

Quote:
Does anybody know what I'm doing wrong ?

You forgot to initialise.

The Windows Sockets WSAStartup function initiates use of the Windows Sockets DLL by a process

Quote:
char host_name[]="172.16.0.102";

How terrible to call an ip-address a hostname!

Add some code before and afther what you already have:

WORD wVersionRequested =MAKEWORD( 1,1);
WSADATA wsaData;
long res=WSAStartup( wVersionRequested, &wsaData );
if(res)
{
ShowMessage ( "res so return;" );
return;
}

char ipaddr [] = "172.16.0.102";

unsigned long inaddr = inet_addr ( ipaddr );

hostent *myhostent = gethostbyaddr( (const char FAR *)&inaddr, sizeof ( in_addr ), 0 );

if ( myhostent ) ShowMessage ( ipaddr + AnsiString ( "\n\n" ) + myhostent->h_name );
else
ShowMessage ( ipaddr + AnsiString ( "\n\n" ) + "no myhostent" );

WSACleanup();

Hans.
Back to top
Kris
Guest





PostPosted: Tue May 15, 2007 3:44 pm    Post subject: Re: gethostbyaddr() does not return any info Reply with quote



Hans Galema wrote:
Quote:
Add some code before and afther what you already have:

Cool. After I changed one little thing in your example code I got it
working perfectly now. I changed the
gethostbyaddr(..., 0 );
into
gethostbyaddr(..., AF_INET );

Thank you very much for your help.

Regards,

Kris
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Native API) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.