| |
| INT WINAPI InetGetLocalAddress(
|
| |
SOCKET hSocket, |
|
| |
INT nAddressFamily, |
|
| |
LPINTERNET_ADDRESS lpAddress, |
|
| |
UINT* lpnPort |
|
| );
|
The InetGetLocalAddress function returns the local IP
address and port number for the specified socket.
Parameters
- hSocket
- The socket handle.
- nAddressFamily
- An integer which identifies the type of IP address to return.
It may be one of the following values:
| Constant |
Description |
| INET_ADDRESS_UNKNOWN |
Return the IP address for the specified host in either IPv4 or
IPv6 format, depending on the type of connection that was
established. If the hSocket parameter is INVALID_SOCKET, a
preference will be given for returning an IPv4 address. However, if
the local host only has an IPv6 address, that value will be
returned. |
| INET_ADDRESS_DEFAULT |
Return the IP address for the specified host in the default
format. This is currently the same as specifying INET_ADDRESS_IPV4,
however an application should not depend on this behavior and for
future compatibility should be designed to handle either IPv4 or
IPv6 addresses. |
| INET_ADDRESS_IPV4 |
Specifies that the address should be returned in IPv4 format.
The first four bytes of the ipNumber array are significant
and contains the IP address. The remaining bytes are not
significant and an application should not depend on them having any
particular value, including zero. |
| INET_ADDRESS_IPV6 |
Specifies that the address should be returned in IPv6 format.
All bytes in the ipNumber array are significant. Note that
it is possible for an IPv6 address to actually represent an IPv4
address. This is indicated by the first 10 bytes of the address
being zero. |
- lpAddress
- A pointer to an INTERNET_ADDRESS structure that will
contain the IP address of the local host. If the hSocket
parameter is specified as INVALID_SOCKET, 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.
- lpnPort
- A pointer to an unsigned integer that will contain the local
port number. If the hSocket parameter specifies a valid
socket, this parameter will be set to the local port that the
socket was bound to. If the hSocket parameter is specified
as INVALID_SOCKET, this parameter is ignored. If the port number is
not required, this parameter may be NULL.
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
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 nAddressFamily parameter is specified as
INET_ADDRESS_UNKNOWN, the application must be prepared to handle
IPv6 addresses because it is possible for the local host to have an
IPv6 address assigned to it and no IPv4 address. For legacy
applications that only recognize IPv4 addresses, the
nAddressFamily member should always be specified as
INET_ADDRESS_IPV4 to ensure that only IPv4 addresses are
returned.
Requirements
Client: Requires Windows 7, Windows Vista or Windows
XP.
Server: Requires Windows Server 2008 or Windows Server
2003.
Header: Include cswsock7.h.
Library: Use cswskav7.lib.
Unicode: Implemented as Unicode and ANSI versions.
See Also
InetGetExternalAddress, InetGetHostAddress, InetGetHostName, InetGetLocalName, InetGetPeerAddress, INTERNET_ADDRESS
|
|