procedure GetHostNameIP(var HostName, IPaddr, WSAErr: string);
var
Buffer: array[0..127] of Char;
WSAData: TWSAData;
HostEnt: PHostEnt;
begin
HostName := EmptyStr;
IPaddr := EmptyStr;
WSAErr := EmptyStr;
FillChar(Buffer, SizeOf(Buffer), #0);
FillChar(WSAData, SizeOf(WSAData), #0);
if WSAStartup(MAKEWORD(2, 0), WSADATA) = 0 then
begin
if GetHostName(@Buffer, SizeOf(Buffer)) = 0 then
begin
HostName := StrPas(@Buffer);
HostEnt := GetHostByName(@Buffer);
if Assigned(HostEnt) then
IPaddr := inet_ntoa(PInAddr(HostEnt.h_addr_list^)^);
end
else
case WSAGetLastError of
WSAEFAULT : WSAErr := 'WSAEFault';
WSANOTINITIALISED : WSAErr := 'WSANotInitialised';
WSAENETDOWN : WSAErr := 'WSAENetDown';
WSAEINPROGRESS : WSAErr := 'WSAEInProgress';
end;
WSACleanup;
end
else
WSAErr := 'Winsock is not responding."';
end;