🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #1961

Re: gethostbyaddr() does not return any info

#1961
From: Hans Galema
Date: Tue, 15 May 2007 09:35
36 lines
1907 bytes
Kris wrote:

> 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

> 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.
Technical Details
Message-ID: <46497ef8$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <46497388$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,d22c882963cf68b8
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
Date: Tue, 15 May 2007 11:35:44 +0200
From: Hans Galema <notused@notused.nl>
User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206)
X-Accept-Language: en-us, en
MIME-Version: 1.0
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Re: gethostbyaddr() does not return any info
References: <46497388$1@newsgroups.borland.com>
In-Reply-To: <46497388$1@newsgroups.borland.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 145.98.201.248
Message-ID: <46497ef8$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1179221752 145.98.201.248 (15 May 2007 02:35:52 -0700)
Lines: 36
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail