gt2StringToAddress
Converts a string address, which is either a hostname ("www.gamespy.net") or a dotted IP ("1.2.3.4") into an IP and a port.
- GT2Bool gt2StringToAddress(
- const char * string,
- unsigned int * ip,
- unsigned short * port );
Routine | Required Header | Distribution |
---|---|---|
gt2StringToAddress | <gt2.h> | SDKZIP |
Return Value
Returns GT2False if there was an error parsing the string, or if a supplied hostname can't be resolved.
Parameters
- string
- [in] String to convert.
- ip
- [out] IP in network byte order. Can be NULL.
- port
- [out] Port in host byte order. Can be NULL.
Remarks
The IP is stored in network byte order, and the port is stored in host byte order. Returns false if there was an error parsing the string, or if a supplied hostname can't be resolved.
Possible string forms:
NULL => all IPs, any port (localAddress only).
"" => all IPs, any port (localAddress only).
"1.2.3.4" => 1.2.3.4 IP, any port (localAddress only).
"host.com" => host.com's IP, any port (localAddress only).
":2786" => all IPs, 2786 port (localAddress only).
"1.2.3.4:0" => 1.2.3.4 IP, any port (localAddress only).
"host.com:0" => host.com's IP, any port (localAddress only).
"0.0.0.0:2786" => all IPs, 2786 port (localAddress only).
"1.2.3.4:2786" => 1.2.3.4 IP, 2786 port (localAddress or remoteAddress).
"host.com:2786" => host.com's IP, 2786 port (localAddress or remoteAddress).
If this function needs to resolve a hostname ("host.com") it may need to contact a DNS server, which can cause the function to block for an indefinite period of time. Usually it is less than 2 seconds, but on certain systems, and under certain circumstances, it can take 30 seconds or longer.
Section Reference: Gamespy Transport SDK
See Also: gt2Connect, gt2CreateSocket, gt2StringToHostInfo