Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[Delphi] How can I list IPv6 Adresses

422 views
Skip to first unread message

Je@nb

unread,
Jun 21, 2003, 7:36:55 AM6/21/03
to
Hi, I want to develop a IPv6 program and I like to get all IPv6 Adresses
presents on the System.
For IPv4 I use this code :


function Tfmprinc.GetIPList(): TStrings;
type
TaPInAddr = array [0..255] of PInAddr;
PaPInAddr = ^TaPInAddr;
var
pptr: PaPInAddr;
I: Integer;
HostEnt: PHostEnt;
Name: String;
WSAData: TWSAData;
ToList : TStringList;
begin
ToList := TStringList.Create;
WSAStartup(2, WSAData);
SetLength(Name, 255);
Gethostname(PChar(Name), 255);
SetLength(Name, StrLen(PChar(Name)));
HostEnt := gethostbyname(PChar(Name));
if HostEnt <> nil then
begin
pptr := PaPInAddr(HostEnt^.h_addr_list);
I := 0;
while pptr^[I] <> nil do begin
ToList.Add(StrPas(inet_ntoa(pptr^[I]^)));
Inc(I);
end;
end;
WSACleanup;
GetIPList := ToList;
end;

Is this code correct ? Isn't there better ?
How can I do to get Ipv6 adresses ?

Regards.
Je@nb


Mark Mosbrucker [MSFT]

unread,
Jun 30, 2003, 5:58:25 PM6/30/03
to
Take a look at:
getaddrinfo
The getaddrinfo function provides protocol-independent translation from host
name to address.

int getaddrinfo(
const char* nodename,
const char* servname,
const struct addrinfo* hints,
struct addrinfo** res
);
Parameters
nodename
[in] Pointer to a null-terminated string containing a host (node) name or
a numeric host address string. The numeric host address string is a
dotted-decimal IPv4 address or an IPv6 hex address.
servname
[in] Pointer to a null-terminated string containing either a service name
or port number.
hints
[in] Pointer to an addrinfo structure that provides hints about the type
of socket the caller supports. See Remarks.
res
[out] Pointer to a linked list of one or more addrinfo structures
containing response information about the host.

Thanks,
Mark

--
This posting is provided "AS IS" with no warranties, and confers no rights.
--


"Je@nb" <je...@jeanb-net.com> wrote in message
news:bd1g0m$1rs0$1...@biggoron.nerim.net...

0 new messages