1515// along with this program; if not, write to the Free Software
1616// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
1717
18+ #ifdef WIN32
19+ #include " ws2tcpip.h"
20+ #else
21+ #include < arpa/inet.h>
22+ #include < err.h>
23+ #include < netdb.h>
24+ #include < sys/socket.h>
25+ #include < sys/sysctl.h>
26+ #include < stdlib.h>
27+ #endif
28+
29+ // ----------------------------------------------------------------------------
30+ /* * Workaround of a bug in iOS 9 where port number is not written. */
31+ extern " C" int getaddrinfo_compat (const char * hostname,
32+ const char * servname,
33+ const struct addrinfo * hints,
34+ struct addrinfo ** res)
35+ {
36+ #ifdef IOS_STK
37+ int err;
38+ int numericPort;
39+
40+ // If we're given a service name and it's a numeric string,
41+ // set `numericPort` to that, otherwise it ends up as 0.
42+ numericPort = servname != NULL ? atoi (servname) : 0 ;
43+
44+ // Call `getaddrinfo` with our input parameters.
45+ err = getaddrinfo (hostname, servname, hints, res);
46+
47+ // Post-process the results of `getaddrinfo` to work around
48+ if ((err == 0 ) && (numericPort != 0 ))
49+ {
50+ for (const struct addrinfo * addr = *res; addr != NULL ;
51+ addr = addr->ai_next )
52+ {
53+ in_port_t * portPtr;
54+ switch (addr->ai_family )
55+ {
56+ case AF_INET:
57+ {
58+ portPtr = &((struct sockaddr_in *)addr->ai_addr )->sin_port ;
59+ }
60+ break ;
61+ case AF_INET6:
62+ {
63+ portPtr = &((struct sockaddr_in6 *)addr->ai_addr )->sin6_port ;
64+ }
65+ break ;
66+ default :
67+ {
68+ portPtr = NULL ;
69+ }
70+ break ;
71+ }
72+ if ((portPtr != NULL ) && (*portPtr == 0 ))
73+ {
74+ *portPtr = htons (numericPort);
75+ }
76+ }
77+ }
78+ return err;
79+ #else
80+ return getaddrinfo (hostname, servname, hints, res);
81+ #endif
82+ }
83+
1884#ifndef ENABLE_IPV6
1985#include " network/unix_ipv6.hpp"
2086// ----------------------------------------------------------------------------
@@ -37,13 +103,6 @@ std::string getIPV6ReadableFromMappedAddress(const ENetAddress* ea)
37103#include " utils/log.hpp"
38104#include " utils/types.hpp"
39105
40- #include < arpa/inet.h>
41- #include < err.h>
42- #include < netdb.h>
43- #include < stdlib.h>
44- #include < sys/socket.h>
45- #include < sys/sysctl.h>
46-
47106#include < algorithm>
48107#include < utility>
49108#include < vector>
0 commit comments