🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: IP Address of Workstation

#5084
From: Michael Gillen
Date: Fri, 30 Sep 2005 21:11
38 lines
1596 bytes
Shane Stump wrote:

> Does anyone have a code sample to get the ip address(s) of a local workstation given the
> workstation's name as returned by gethostname()?
> 
> Best Regards,
> 
> Shane

void __fastcall LoadLocalIpList(TStringList* SL)
{
	SL->Clear();
	WSADATA wsa = {0};
	if(::WSAStartup(MAKEWORD(2, 0), &wsa) != 0)
	{
		ShowMessage("The requested WinSock (version 2) is not available");
		return;
	}

	char buffer[65] = {0};
	if(::gethostname(buffer, sizeof(buffer)) == 0)
	{
		struct hostent *host = ::gethostbyname(buffer);
		if(host)
		{
			for(int x = 0; host->h_addr_list[x] != NULL; ++x)
			{
				AnsiString IpAddress = ::inet_ntoa(*(in_addr*)host->h_addr_list[x]);
				SL->Add(IpAddress);
			}
		}
	}
	::WSACleanup();
}


-- 
-Michael Gillen
Technical Details
Message-ID: <433daa0c@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!newspeer.tds.net!38.119.100.82.MISMATCH!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail
References: <433d8a67$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,bd4babe6e8b894e9
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Michael Gillen" <michael@gillenconsultinggroup-nospam.com>
Subject: Re: IP Address of Workstation
Newsgroups: borland.public.cppbuilder.nativeapi
References:  <433d8a67$1@newsgroups.borland.com>
User-Agent: XanaNews/1.17.6.5
NNTP-Posting-Host: 67.122.199.249
Message-ID: <433daa0c@newsgroups.borland.com>
Date: 30 Sep 2005 14:11:40 -0700
X-Trace: newsgroups.borland.com 1128114700 67.122.199.249 (30 Sep 2005 14:11:40 -0700)
Lines: 38
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!newspeer.tds.net!38.119.100.82.MISMATCH!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail