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
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...