Article View: borland.public.cppbuilder.nativeapi
Article #14431Re: IP adrress of a network computer
From: Jan Piessens
Date: Wed, 13 Aug 2003 19:31
Date: Wed, 13 Aug 2003 19:31
26 lines
1654 bytes
1654 bytes
Remy Lebeau (TeamB) wrote:
>
> <Jan Piessens> wrote in message news:3f37ee88@newsgroups.borland.com...
>
> > I have fixed it with the next function:
>
> That is slightly dangerous, as hosthostbyname() will return NULL if it
> fails, and then you would be accessing an invalid pointer. You should
> always test return values before you use them, ie:
>
> void __fastcall TForm1::GetComputerIP(String sHost)
> {
> hostent *phost = gethostbyname(sHost.c_str());
> if( phost )
> Edit2->Text = inet_ntoa(*(in_addr*)phost->h_addr);
> else
> Edit2->Clear();
> }
>
>
> Gambit
Thanks Gambit for the good tip.
Jan
Technical Details
Message-ID:
<3f3a9212@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-01!sn-xit-08!supernews.com!priapus.visi.com!news-out.visi.com!petbe.visi.com!eusc.inter.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<3f336b2a$1@newsgroups.borland.com> <3f33c2fd@newsgroups.borland.com> <3f37ee88@newsgroups.borland.com> <3f38219f$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,68e5ffe7c328d7f6 X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2003-08-13 12:40:26 PST From: "Jan Piessens" <> Subject: Re: IP adrress of a network computer Newsgroups: borland.public.cppbuilder.nativeapi References: <3f336b2a$1@newsgroups.borland.com> <3f33c2fd@newsgroups.borland.com> <3f37ee88@newsgroups.borland.com> <3f38219f$1@newsgroups.borland.com> Organization: JLC Soft User-Agent: XanaNews/1.15.3.2 NNTP-Posting-Host: 213.119.196.140 Message-ID: <3f3a9212@newsgroups.borland.com> Date: 13 Aug 2003 12:31:30 -0700 X-Trace: newsgroups.borland.com 1060803090 213.119.196.140 (13 Aug 2003 12:31:30 -0700) Lines: 26 Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-01!sn-xit-08!supernews.com!priapus.visi.com!news-out.visi.com!petbe.visi.com!eusc.inter.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail