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 

How can I get all the local IP addresses on a PC?

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> comp.lang.pascal.delphi.misc
View previous topic :: View next topic  
Author Message
Dodgy
Guest





PostPosted: Thu Sep 15, 2005 4:33 pm    Post subject: How can I get all the local IP addresses on a PC? Reply with quote



I used to use the bit of code below, which worked fine with Indy8's
idwinsock.

Unfortunately I had to update to Indy9, and it uses idwinsock2.

function GetLocalIPs: string;
type PPInAddr= ^PInAddr;
var
wsaData: TWSAData;
HostInfo: PHostEnt;
HostName: array[0..255] of char;
Addr: PPInAddr;
begin
Result:='';
if WSAStartup($0102, wsaData)<>0 then exit;
try
if gethostname(HostName, SizeOf(HostName)) <> 0 then exit;
HostInfo:=gethostbyname(HostName);
if HostInfo=nil then Exit;
Addr:=Pointer(HostInfo^.h_address_list);
if (Addr=nil) or (Addr^=nil) then exit;
Result:=StrPas(inet_ntoa(Addr^^));
inc(Addr);
while Addr^<>nil do begin
Result:=Result+','+StrPas(inet_ntoa(Addr^^));
inc(Addr);
end;
finally
WSACleanup;
end;
end;

Had to change h_addr_list to h_address_list, but that was it...
Compiled... Works! hurrah.

Well it works, but it manages to completely screw up the idhttp
component which until the above routine was called, was working
properly. The idhttp component errors with "cannot allocate socket".
Nice.

So I'm now in need of an alternative method (I need all the IPs a
machine has for multi-NIC configurations), or a correction for the
Indy 9 source code. I've checked their bug list, but nothing I could
see that related to this.

Can anyone help?

Dodgy.
--
MUSHROOMS ARE THE OPIATE OF THE MOOSES
Back to top
Dodgy
Guest





PostPosted: Thu Sep 15, 2005 4:54 pm    Post subject: Re: How can I get all the local IP addresses on a PC? Reply with quote



On Thu, 15 Sep 2005 17:33:12 +0100, Dodgy
<Dodgy (AT) earth (DOT) planet.universe> waffled on about something:

<snip>

Ooops,
Ignore me!

I just discovered that the only reason I was referencing idwinsock and
then idwinsock2 was for a couple of data type definitions... And it
then gives me gethostname and gethostbyname into the bargain... Looks
like they've managed to break them in Indy9, but luckily D5's started
winsock library contains everything I need.

Dodgy.
--
MUSHROOMS ARE THE OPIATE OF THE MOOSES
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> comp.lang.pascal.delphi.misc 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.