In the first form of the method, if it succeeds, the return value
is the IP address of the local system in numeric form. If the method
fails, the return value is INET_ADDRESS_NONE. In the second form, the
return value is the length of the IP address string and an error is
indicated by the return value INET_ERROR. To get extended error
information, call GetLastError.
The GetExternalAddress method returns the IP address
assigned to the router that connects the local host to the Internet.
This is typically used by an application executing on a system in a
local network that uses a router which performs Network Address
Translation (NAT). In that network configuration, the
GetLocalAddress method will only return the IP address for the
local system on the LAN side of the network unless a connection has
already been established to a remote host. The
GetExternalAddress function can be used to determine the IP
address assigned to the router on the Internet side of the connection
and can be particularly useful for servers running on a system behind
a NAT router.
This method requires that you have an active connection to the
Internet and calling this function on a system that uses dial-up
networking may cause the operating system to automatically connect to
the Internet service provider. An application should always check the
return value in case there is an error; never assume that the return
value is always a valid address. The function may be unable to
determine the external IP address for the local host for a number of
reasons, particularly if the system is behind a firewall or uses a
proxy server that restricts access to external sites on the Internet.
If the function is able to obtain a valid external address for the
local host, that address will be cached by the library for sixty
minutes. Because dial-up connections typically have different IP
addresses assigned to them each time the system is connected to the
Internet, it is recommended that this function only be used with
broadband connections where a NAT router is being used.
Calling this function may cause the current thread to block until
the external IP address can be resolved and should never be used in
conjunction with asynchronous socket connections. If
you need to call this function in an application which uses
asynchronous sockets, it is recommended that you create a new thread
and call this function from within that thread.