Re: How to get client name

Giganews Newsgroups
Subject: Re: How to get client name
Posted by:  Mike B (nospam@faribonet.net)
Date: Fri, 1 Aug 2003

Carlos,

  Include WINSOCK in your uses and try this...

Mike

function GetHN(aIPAddress: String): String;
Var
  HostName: String;
  pszIPAddress: PChar;
  GInitData: TWSADATA;
  paHostEnt: PHostEnt;
  InetAddr: u_long;
begin
  HostName := '';
  { WSAStartup function initiates use of the Windows Sockets DLL by a
process }
  if (WSAStartup($101,GInitData)=0) then begin
    { Convert the IP address string into a network address }
    pszIPAddress:=StrAlloc(Length(aIPAddress)+1);
    StrPCopy(pszIPAddress,aIPAddress);
    InetAddr:=Inet_Addr(pszIPAddress);
    StrDispose(pszIPAddress );
    { Get Host Info }
    paHostEnt:=GetHostByAddr(pchar(@InetAddr),4,PF_INET);
    if (paHostEnt<>nil) then begin
      HostName:=paHostEnt.h_name;
    end else begin
      HostName:='IP Address NOT found!!!';
    end;
    { Close WinSock }
    WSACleanup;
  end;
  Result:=HostName;
end;

"Carlos Matos" <mat…@comograma.pt> wrote in message
news:5CE72E8B3679E240mat…@comograma.pt...
> Hi,
> I'm writing a TCP server app and I would like to know the client name that
> connects to the server, like we get client IP
> (AThread.Connection.Socket.Binding.PeerIP).
>
> Thanks,
>
> --
> Carlos Matos

Replies

In response to

How to get client name posted by Carlos Matos on Thu, 31 Jul 2003