CInternetServer::GetClientAddress Method  
 
INT GetClientAddress(
  SOCKET hSocket,  
  LPINTERNET_ADDRESS lpAddress,  
  UINT *lpnRemotePort  
);
INT GetClientAddress(
  SOCKET hSocket,  
  LPTSTR lpszAddress,  
  INT nMaxLength  
);
INT GetClientAddress(
  SOCKET hSocket,  
  CString& strAddress  
);

Return the IP address and port number for the specified client session.

Parameters

hSocket
An optional parameter that specifies the handle to a server or client socket. If this parameter is omitted, the socket handle for the active client session will be used. If this method is called outside of a server event handler, the socket handle must be specified.
lpAddress
A pointer to an INTERNET_ADDRESS structure that will contain the IP address of the client that is connected to the server. This parameter may be NULL, in which case the IP address will not be returned to the caller.
lpnRemotePort
A pointer to an unsigned integer that will contain the port number of the client that is connected to the server. This parameter may be NULL, in which case the port number will not be returned to the caller.
lpszAddress
A pointer to a string buffer that will contain the formatted IP address, terminated with a null character. To accommodate both IPv4 and IPv6 addresses, this buffer should be at least 46 characters in length.
nMaxLength
The maximum number of characters that can be copied into the address buffer.

Return Value

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

Remarks

If this method is called within an OnAccept event handler, passing the server handle as the hSocket parameter will return the IP address and port number for the client that is attempting to establish the connection. If the client address is unavailable, the ipFamily member of the INTERNET_ADDRESS structure will be zero.

The format and length of IPv4 and IPv6 address strings are very different. An IPv4 address string looks like "192.168.0.20", while an IPv6 address string can look something like "fd7c:2f6a:4f4f:ba34::a32". If your application checks for the format of these address strings, it needs to be aware of the differences. You also need to make sure that you're providing enough space to display or store an address to avoid buffer overruns.

Requirements

Minimum Desktop Platform: Windows 7 Service Pack 1
Minimum Server Platform: Windows Server 2008 R2 Service Pack 1
Header File: cswsock11.h
Import Library: cswskv11.lib

See Also

GetClientPort, OnAccept, OnConnect, INTERNET_ADDRESS