Article View: borland.public.cppbuilder.nativeapi
Article #5085Re: IP Address of Workstation
From: Shane Stump
Date: Fri, 30 Sep 2005 21:34
Date: Fri, 30 Sep 2005 21:34
47 lines
2039 bytes
2039 bytes
Thanks - I believe this is what I was looking for!
Best Regards,
Shane
"Michael Gillen" <michael@gillenconsultinggroup-nospam.com> wrote in message
news:433daa0c@newsgroups.borland.com...
> 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:
<433daeef$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!news.moat.net!news-out.newsfeeds.com!propagator3-LAX.newsfeeds.com!news-in.newsfeeds.com!news-in.superfeed.net!caladan.landsraad.net!newsgroups.borland.com!not-for-mailReferences:
<433d8a67$1@newsgroups.borland.com> <433daa0c@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: "Shane Stump" <ShaneStumpNOSPAM@StumpWare.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <433d8a67$1@newsgroups.borland.com> <433daa0c@newsgroups.borland.com> Subject: Re: IP Address of Workstation Date: Fri, 30 Sep 2005 16:34:32 -0500 Lines: 49 Organization: StumpWare X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2180 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 X-RFC2646: Format=Flowed; Original NNTP-Posting-Host: 66.63.248.134 Message-ID: <433daeef$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1128115951 66.63.248.134 (30 Sep 2005 14:32:31 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!news.moat.net!news-out.newsfeeds.com!propagator3-LAX.newsfeeds.com!news-in.newsfeeds.com!news-in.superfeed.net!caladan.landsraad.net!newsgroups.borland.com!not-for-mail