CInternetServer::GetLocalAddress Method  
 
INT GetLocalAddress(
  LPINTERNET_ADDRESS lpAddress,  
  UINT *lpnPort  
);
INT GetLocalAddress(
  LPTSTR lpszAddress,  
  INT nMaxLength  
);
INT GetLocalAddress(
  CString& strAddress  
  UINT *lpnPort  
);

Return the local IP address and port number for the server.

Parameters

lpAddress
A pointer to an INTERNET_ADDRESS structure that will contain the IP address of the local host. If the server is not active, this function will attempt to determine the IP address of the local host assigned by the system. If the address is not required, this parameter may be NULL.
lpszAddress
A pointer to a null terminated string that will contain the IP address of the local host. If this version of the method is used, the IP address is converted to a string format using the FormatAddress method. The string should be able to store at least 46 characters to ensure that both IPv4 and IPv6 formatted addresses can be returned without the possibility of a buffer overrun. An alternate form of the method accepts a CString argument which will contain the line of text returned by the server.
lpnPort
A pointer to an unsigned integer that will contain the local port number. If the server is active, this parameter will be set to the local port that the listening socket was bound to. If the server is not active, this parameter is ignored. If the port number is not required, this parameter may be NULL.

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

To ensure future compatibility with IPv6 networks, it is important that the application does not make any assumptions about the format of the address. If the function returns successfully, the ipFamily member of the INTERNET_ADDRESS structure should always be checked to determine the type of address.

If the system is connected to the Internet through a local network and/or uses a router that performs Network Address Translation (NAT), the GetLocalAddress method will return the local, non-routable IP address assigned to the local system. To determine the public IP address has been assigned to the system, you should use the GetExternalAddress method.

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
Unicode: Implemented as Unicode and ANSI versions

See Also

GetClientAddress, GetExternalAddress, GetHostAddress, GetHostName, GetLocalName, INTERNET_ADDRESS