hi, inthe. my solution's mayb more readable; of corze ur's is nicer ;-) - this is 2 b seen as a comment, ok?
function Get_HostIP: string;
var
HEnt: pHostEnt;
WSAData: TWSAData;
iCnt: Integer;
sHostName: string;
sIPAddr: string;
begin
if WSAStartup($0101, WSAData) <> 0 then begin
Result := 'WSAStartup error';
Exit;
end;
try
sIPAddr := '';
sHostName := '';
SetLength(sHostName, 100);
if GetHostName(PChar(sHostName), 100) = 0 then begin
SetLength(sHostName, StrLen(PChar(sHostName)));
HEnt := GetHostByName(PChar(sHostName));
if HEnt <> nil then begin
for iCnt := 0 to HEnt^.h_length - 1 do
sIPAddr := sIPAddr + IntToStr(Ord(HEnt^.h_addr_list^[iCnt])) + '.';
SetLength(sIPAddr, Length(sIPAddr) - 1);
Result := sIPaddr;
end
else
Result := 'Hostname not found';
end
else case WSAGetLastError of
WSAEFAULT : Result := 'WSAEFault';
WSANOTINITIALISED: Result := 'WSANotInitialised';
WSAENETDOWN : Result := 'WSAENetDown';
WSAEINPROGRESS : Result := 'WSAEInProgress';
end;
finally
WSACleanup;
end;
end;
function Get_HostIP: string;
var
HEnt: pHostEnt;
WSAData: TWSAData;
iCnt: Integer;
sHostName: string;
sIPAddr: string;
begin
if WSAStartup($0101, WSAData) <> 0 then begin
Result := 'WSAStartup error';
Exit;
end;
try
sIPAddr := '';
sHostName := '';
SetLength(sHostName, 100);
if GetHostName(PChar(sHostNam
SetLength(sHostName, StrLen(PChar(sHostName)));
HEnt := GetHostByName(PChar(sHostN
if HEnt <> nil then begin
for iCnt := 0 to HEnt^.h_length - 1 do
sIPAddr := sIPAddr + IntToStr(Ord(HEnt^.h_addr_
SetLength(sIPAddr, Length(sIPAddr) - 1);
Result := sIPaddr;
end
else
Result := 'Hostname not found';
end
else case WSAGetLastError of
WSAEFAULT : Result := 'WSAEFault';
WSANOTINITIALISED: Result := 'WSANotInitialised';
WSAENETDOWN : Result := 'WSAENetDown';
WSAEINPROGRESS : Result := 'WSAEInProgress';
end;
finally
WSACleanup;
end;
end;