InetGetPeerAddress Function  
 
INT WINAPI InetGetPeerAddress(
  SOCKET hSocket,  
  LPINTERNET_ADDRESS lpAddress,  
  UINT* lpnPort  
);

The InetGetPeerAddress function returns the peer IP address and remote port number for the specified socket.

Parameters

hSocket
The socket handle.
lpAddress
A pointer to an INTERNET_ADDRESS structure that will contain the IP address of the remote host that the socket is connected to.
lpnPort
A pointer to an unsigned integer that will contain the remote port that the socket is connected to.

Return Value

If the function succeeds, the return value is zero. If the function fails, the return value is INET_ERROR. To get extended error information, call InetGetLastError.

Remarks

If this function is called by a server application in response to a INET_EVENT_ACCEPT event, it will return the IP address and port number for the client that is attempting to establish the connection. If the peer address is unavailable, the ipFamily member of the INTERNET_ADDRESS structure will be zero. To convert the IP address to a printable string, use the InetFormatAddress function.

It is not recommended that you use the port number for anything other than informational and logging purposes. Server applications should not make any assumptions about the specific port number or range of port numbers that a client is using when establishing a connection to the server. The ephemeral port number that a client is bound to can vary based on the client operating system.

Requirements

Minimum Desktop Platform: Windows 7 (Service Pack 1)
Minimum Server Platform: Windows Server 2008 R2 (Service Pack 1)
Header: Include cswsock10.h
Import Library: cswskv10.lib

See Also

InetFormatAddress, InetGetHostAddress, InetGetHostName, InetGetLocalAddress, InetGetLocalName, INTERNET_ADDRESS