The GetUrlHostName method will extract the host name and port
number from a URL and return the canonical form of the host name.
If the lpnHostPort, lpnProtocol and lpdwOptions parameters
have been specified, they will contain the port number, protocol and additional
connection options associated with the URL scheme.
The general format of the URL should look like this:
[scheme]:// [[username : password] @] hostname [:port] / [path;parameters ...]
This method recognizes most standard URI schemes which use this
format. The host name and port number specified in the URL will be
used to establish a connection and the remaining information will be
discarded. If the URL does not explicitly specify a port number,
the default port number associated with the scheme will be used as
the default value. For example, consider the following:
https://www.example.com/
In this example, there is no port number specified; instead, the default
port for the https:// scheme would be used, which is port 443.
This method will also recognize a simpler format which only includes the
host name and port number without a URI scheme, such as:
www.example.com:443
If the lpszUrl parameter only specifies a host name without a
URI scheme or port number, this method will ignore the lpnHostPort,
lpnProtocol and lpdwOptions parameters and return the
canonical form of the host name in the lpszHostName string argument.
The host name portion of the URL can be specified as either a domain name
or an IP address. Because an IPv6 address can contain colon characters,
you must enclose the entire address in bracket [] characters. If this is
not done, the method will return an error indicating the port number is
invalid. For example, the URL https://[2001:db8:0:0:1::128]/
uses an IPv6 host address and this would be considered valid. Without the
brackets, this URL would not be accepted.
If the URL uses an IP address instead of a host name, this method will
return a copy of that IP address in the lpszHostName string provided
by the caller. The method will not attempt to resolve the IP address
into a host name, however you can use the GetHostName method
to perform a reverse DNS lookup if required.
The only URI schemes currently supported by this method use TCP
stream connections. In practical terms, this means the lpnProtocol
parameter will always return with the value INET_PROTOCOL_TCP when the
method is successful. If the method fails, this value will be
INET_PROTOCOL_NONE.
Although this method performs checks to ensure that the lpszUrl
parameter is in the correct format and does not contain any illegal
characters or malformed encoding, it does not validate the host name.
To check if the host name exists and has a valid IP address, use the
ValidateHostName method.