Why doesn't this code work right?
I'm using the code below, and added winsock to my uses list.
I'm using D4 C/S.
Now when i do inttostr(my_ip_address) it returns some weird
numer -7723189217 bla bla (i random typed this one of course :-)
Why?
Rik
function my_ip_address:longint;
const
bufsize=255;
var
buf: pointer;
RemoteHost : PHostEnt; (* No, don't free it! *)
begin
buf:=NIL;
try
getmem(buf,bufsize);
winsock.gethostname(buf,bufsize); (* this one maybe without domain *)
RemoteHost:=Winsock.GetHostByName(buf);
if RemoteHost=NIL then
my_ip_address:=winsock.htonl($07000001) (* 127.0.0.1 *)
else
my_ip_address:=longint(pointer(RemoteHost^.h_addr_list^)^);
finally
if buf<>NIL then freemem(buf,bufsize);
end;
result:=winsock.ntohl(result);
end;