@@ -1714,142 +1714,10 @@ int mingw_putenv(const char *namevalue)
17141714 return result ? 0 : -1 ;
17151715}
17161716
1717- /*
1718- * Note, this isn't a complete replacement for getaddrinfo. It assumes
1719- * that service contains a numerical port, or that it is null. It
1720- * does a simple search using gethostbyname, and returns one IPv4 host
1721- * if one was found.
1722- */
1723- static int WSAAPI getaddrinfo_stub (const char * node , const char * service ,
1724- const struct addrinfo * hints ,
1725- struct addrinfo * * res )
1726- {
1727- struct hostent * h = NULL ;
1728- struct addrinfo * ai ;
1729- struct sockaddr_in * sin ;
1730-
1731- if (node ) {
1732- h = gethostbyname (node );
1733- if (!h )
1734- return WSAGetLastError ();
1735- }
1736-
1737- ai = xmalloc (sizeof (struct addrinfo ));
1738- * res = ai ;
1739- ai -> ai_flags = 0 ;
1740- ai -> ai_family = AF_INET ;
1741- ai -> ai_socktype = hints ? hints -> ai_socktype : 0 ;
1742- switch (ai -> ai_socktype ) {
1743- case SOCK_STREAM :
1744- ai -> ai_protocol = IPPROTO_TCP ;
1745- break ;
1746- case SOCK_DGRAM :
1747- ai -> ai_protocol = IPPROTO_UDP ;
1748- break ;
1749- default :
1750- ai -> ai_protocol = 0 ;
1751- break ;
1752- }
1753- ai -> ai_addrlen = sizeof (struct sockaddr_in );
1754- if (hints && (hints -> ai_flags & AI_CANONNAME ))
1755- ai -> ai_canonname = h ? xstrdup (h -> h_name ) : NULL ;
1756- else
1757- ai -> ai_canonname = NULL ;
1758-
1759- sin = xcalloc (1 , ai -> ai_addrlen );
1760- sin -> sin_family = AF_INET ;
1761- /* Note: getaddrinfo is supposed to allow service to be a string,
1762- * which should be looked up using getservbyname. This is
1763- * currently not implemented */
1764- if (service )
1765- sin -> sin_port = htons (atoi (service ));
1766- if (h )
1767- sin -> sin_addr = * (struct in_addr * )h -> h_addr ;
1768- else if (hints && (hints -> ai_flags & AI_PASSIVE ))
1769- sin -> sin_addr .s_addr = INADDR_ANY ;
1770- else
1771- sin -> sin_addr .s_addr = INADDR_LOOPBACK ;
1772- ai -> ai_addr = (struct sockaddr * )sin ;
1773- ai -> ai_next = NULL ;
1774- return 0 ;
1775- }
1776-
1777- static void WSAAPI freeaddrinfo_stub (struct addrinfo * res )
1778- {
1779- free (res -> ai_canonname );
1780- free (res -> ai_addr );
1781- free (res );
1782- }
1783-
1784- static int WSAAPI getnameinfo_stub (const struct sockaddr * sa , socklen_t salen ,
1785- char * host , DWORD hostlen ,
1786- char * serv , DWORD servlen , int flags )
1787- {
1788- const struct sockaddr_in * sin = (const struct sockaddr_in * )sa ;
1789- if (sa -> sa_family != AF_INET )
1790- return EAI_FAMILY ;
1791- if (!host && !serv )
1792- return EAI_NONAME ;
1793-
1794- if (host && hostlen > 0 ) {
1795- struct hostent * ent = NULL ;
1796- if (!(flags & NI_NUMERICHOST ))
1797- ent = gethostbyaddr ((const char * )& sin -> sin_addr ,
1798- sizeof (sin -> sin_addr ), AF_INET );
1799-
1800- if (ent )
1801- snprintf (host , hostlen , "%s" , ent -> h_name );
1802- else if (flags & NI_NAMEREQD )
1803- return EAI_NONAME ;
1804- else
1805- snprintf (host , hostlen , "%s" , inet_ntoa (sin -> sin_addr ));
1806- }
1807-
1808- if (serv && servlen > 0 ) {
1809- struct servent * ent = NULL ;
1810- if (!(flags & NI_NUMERICSERV ))
1811- ent = getservbyport (sin -> sin_port ,
1812- flags & NI_DGRAM ? "udp" : "tcp" );
1813-
1814- if (ent )
1815- snprintf (serv , servlen , "%s" , ent -> s_name );
1816- else
1817- snprintf (serv , servlen , "%d" , ntohs (sin -> sin_port ));
1818- }
1819-
1820- return 0 ;
1821- }
1822-
1823- static HMODULE ipv6_dll = NULL ;
1824- static void (WSAAPI * ipv6_freeaddrinfo )(struct addrinfo * res );
1825- static int (WSAAPI * ipv6_getaddrinfo )(const char * node , const char * service ,
1826- const struct addrinfo * hints ,
1827- struct addrinfo * * res );
1828- static int (WSAAPI * ipv6_getnameinfo )(const struct sockaddr * sa , socklen_t salen ,
1829- char * host , DWORD hostlen ,
1830- char * serv , DWORD servlen , int flags );
1831- /*
1832- * gai_strerror is an inline function in the ws2tcpip.h header, so we
1833- * don't need to try to load that one dynamically.
1834- */
1835-
1836- static void socket_cleanup (void )
1837- {
1838- WSACleanup ();
1839- if (ipv6_dll )
1840- FreeLibrary (ipv6_dll );
1841- ipv6_dll = NULL ;
1842- ipv6_freeaddrinfo = freeaddrinfo_stub ;
1843- ipv6_getaddrinfo = getaddrinfo_stub ;
1844- ipv6_getnameinfo = getnameinfo_stub ;
1845- }
1846-
18471717static void ensure_socket_initialization (void )
18481718{
18491719 WSADATA wsa ;
18501720 static int initialized = 0 ;
1851- const char * libraries [] = { "ws2_32.dll" , "wship6.dll" , NULL };
1852- const char * * name ;
18531721
18541722 if (initialized )
18551723 return ;
@@ -1858,35 +1726,7 @@ static void ensure_socket_initialization(void)
18581726 die ("unable to initialize winsock subsystem, error %d" ,
18591727 WSAGetLastError ());
18601728
1861- for (name = libraries ; * name ; name ++ ) {
1862- ipv6_dll = LoadLibraryExA (* name , NULL ,
1863- LOAD_LIBRARY_SEARCH_SYSTEM32 );
1864- if (!ipv6_dll )
1865- continue ;
1866-
1867- ipv6_freeaddrinfo = (void (WSAAPI * )(struct addrinfo * ))
1868- GetProcAddress (ipv6_dll , "freeaddrinfo" );
1869- ipv6_getaddrinfo = (int (WSAAPI * )(const char * , const char * ,
1870- const struct addrinfo * ,
1871- struct addrinfo * * ))
1872- GetProcAddress (ipv6_dll , "getaddrinfo" );
1873- ipv6_getnameinfo = (int (WSAAPI * )(const struct sockaddr * ,
1874- socklen_t , char * , DWORD ,
1875- char * , DWORD , int ))
1876- GetProcAddress (ipv6_dll , "getnameinfo" );
1877- if (!ipv6_freeaddrinfo || !ipv6_getaddrinfo || !ipv6_getnameinfo ) {
1878- FreeLibrary (ipv6_dll );
1879- ipv6_dll = NULL ;
1880- } else
1881- break ;
1882- }
1883- if (!ipv6_freeaddrinfo || !ipv6_getaddrinfo || !ipv6_getnameinfo ) {
1884- ipv6_freeaddrinfo = freeaddrinfo_stub ;
1885- ipv6_getaddrinfo = getaddrinfo_stub ;
1886- ipv6_getnameinfo = getnameinfo_stub ;
1887- }
1888-
1889- atexit (socket_cleanup );
1729+ atexit ((void (* )(void )) WSACleanup );
18901730 initialized = 1 ;
18911731}
18921732
@@ -1904,24 +1744,12 @@ struct hostent *mingw_gethostbyname(const char *host)
19041744 return gethostbyname (host );
19051745}
19061746
1907- void mingw_freeaddrinfo (struct addrinfo * res )
1908- {
1909- ipv6_freeaddrinfo (res );
1910- }
1911-
1747+ #undef getaddrinfo
19121748int mingw_getaddrinfo (const char * node , const char * service ,
19131749 const struct addrinfo * hints , struct addrinfo * * res )
19141750{
19151751 ensure_socket_initialization ();
1916- return ipv6_getaddrinfo (node , service , hints , res );
1917- }
1918-
1919- int mingw_getnameinfo (const struct sockaddr * sa , socklen_t salen ,
1920- char * host , DWORD hostlen , char * serv , DWORD servlen ,
1921- int flags )
1922- {
1923- ensure_socket_initialization ();
1924- return ipv6_getnameinfo (sa , salen , host , hostlen , serv , servlen , flags );
1752+ return getaddrinfo (node , service , hints , res );
19251753}
19261754
19271755int mingw_socket (int domain , int type , int protocol )
0 commit comments