@@ -1705,142 +1705,10 @@ int mingw_putenv(const char *namevalue)
17051705 return result ? 0 : -1 ;
17061706}
17071707
1708- /*
1709- * Note, this isn't a complete replacement for getaddrinfo. It assumes
1710- * that service contains a numerical port, or that it is null. It
1711- * does a simple search using gethostbyname, and returns one IPv4 host
1712- * if one was found.
1713- */
1714- static int WSAAPI getaddrinfo_stub (const char * node , const char * service ,
1715- const struct addrinfo * hints ,
1716- struct addrinfo * * res )
1717- {
1718- struct hostent * h = NULL ;
1719- struct addrinfo * ai ;
1720- struct sockaddr_in * sin ;
1721-
1722- if (node ) {
1723- h = gethostbyname (node );
1724- if (!h )
1725- return WSAGetLastError ();
1726- }
1727-
1728- ai = xmalloc (sizeof (struct addrinfo ));
1729- * res = ai ;
1730- ai -> ai_flags = 0 ;
1731- ai -> ai_family = AF_INET ;
1732- ai -> ai_socktype = hints ? hints -> ai_socktype : 0 ;
1733- switch (ai -> ai_socktype ) {
1734- case SOCK_STREAM :
1735- ai -> ai_protocol = IPPROTO_TCP ;
1736- break ;
1737- case SOCK_DGRAM :
1738- ai -> ai_protocol = IPPROTO_UDP ;
1739- break ;
1740- default :
1741- ai -> ai_protocol = 0 ;
1742- break ;
1743- }
1744- ai -> ai_addrlen = sizeof (struct sockaddr_in );
1745- if (hints && (hints -> ai_flags & AI_CANONNAME ))
1746- ai -> ai_canonname = h ? xstrdup (h -> h_name ) : NULL ;
1747- else
1748- ai -> ai_canonname = NULL ;
1749-
1750- sin = xcalloc (1 , ai -> ai_addrlen );
1751- sin -> sin_family = AF_INET ;
1752- /* Note: getaddrinfo is supposed to allow service to be a string,
1753- * which should be looked up using getservbyname. This is
1754- * currently not implemented */
1755- if (service )
1756- sin -> sin_port = htons (atoi (service ));
1757- if (h )
1758- sin -> sin_addr = * (struct in_addr * )h -> h_addr ;
1759- else if (hints && (hints -> ai_flags & AI_PASSIVE ))
1760- sin -> sin_addr .s_addr = INADDR_ANY ;
1761- else
1762- sin -> sin_addr .s_addr = INADDR_LOOPBACK ;
1763- ai -> ai_addr = (struct sockaddr * )sin ;
1764- ai -> ai_next = NULL ;
1765- return 0 ;
1766- }
1767-
1768- static void WSAAPI freeaddrinfo_stub (struct addrinfo * res )
1769- {
1770- free (res -> ai_canonname );
1771- free (res -> ai_addr );
1772- free (res );
1773- }
1774-
1775- static int WSAAPI getnameinfo_stub (const struct sockaddr * sa , socklen_t salen ,
1776- char * host , DWORD hostlen ,
1777- char * serv , DWORD servlen , int flags )
1778- {
1779- const struct sockaddr_in * sin = (const struct sockaddr_in * )sa ;
1780- if (sa -> sa_family != AF_INET )
1781- return EAI_FAMILY ;
1782- if (!host && !serv )
1783- return EAI_NONAME ;
1784-
1785- if (host && hostlen > 0 ) {
1786- struct hostent * ent = NULL ;
1787- if (!(flags & NI_NUMERICHOST ))
1788- ent = gethostbyaddr ((const char * )& sin -> sin_addr ,
1789- sizeof (sin -> sin_addr ), AF_INET );
1790-
1791- if (ent )
1792- snprintf (host , hostlen , "%s" , ent -> h_name );
1793- else if (flags & NI_NAMEREQD )
1794- return EAI_NONAME ;
1795- else
1796- snprintf (host , hostlen , "%s" , inet_ntoa (sin -> sin_addr ));
1797- }
1798-
1799- if (serv && servlen > 0 ) {
1800- struct servent * ent = NULL ;
1801- if (!(flags & NI_NUMERICSERV ))
1802- ent = getservbyport (sin -> sin_port ,
1803- flags & NI_DGRAM ? "udp" : "tcp" );
1804-
1805- if (ent )
1806- snprintf (serv , servlen , "%s" , ent -> s_name );
1807- else
1808- snprintf (serv , servlen , "%d" , ntohs (sin -> sin_port ));
1809- }
1810-
1811- return 0 ;
1812- }
1813-
1814- static HMODULE ipv6_dll = NULL ;
1815- static void (WSAAPI * ipv6_freeaddrinfo )(struct addrinfo * res );
1816- static int (WSAAPI * ipv6_getaddrinfo )(const char * node , const char * service ,
1817- const struct addrinfo * hints ,
1818- struct addrinfo * * res );
1819- static int (WSAAPI * ipv6_getnameinfo )(const struct sockaddr * sa , socklen_t salen ,
1820- char * host , DWORD hostlen ,
1821- char * serv , DWORD servlen , int flags );
1822- /*
1823- * gai_strerror is an inline function in the ws2tcpip.h header, so we
1824- * don't need to try to load that one dynamically.
1825- */
1826-
1827- static void socket_cleanup (void )
1828- {
1829- WSACleanup ();
1830- if (ipv6_dll )
1831- FreeLibrary (ipv6_dll );
1832- ipv6_dll = NULL ;
1833- ipv6_freeaddrinfo = freeaddrinfo_stub ;
1834- ipv6_getaddrinfo = getaddrinfo_stub ;
1835- ipv6_getnameinfo = getnameinfo_stub ;
1836- }
1837-
18381708static void ensure_socket_initialization (void )
18391709{
18401710 WSADATA wsa ;
18411711 static int initialized = 0 ;
1842- const char * libraries [] = { "ws2_32.dll" , "wship6.dll" , NULL };
1843- const char * * name ;
18441712
18451713 if (initialized )
18461714 return ;
@@ -1849,35 +1717,7 @@ static void ensure_socket_initialization(void)
18491717 die ("unable to initialize winsock subsystem, error %d" ,
18501718 WSAGetLastError ());
18511719
1852- for (name = libraries ; * name ; name ++ ) {
1853- ipv6_dll = LoadLibraryExA (* name , NULL ,
1854- LOAD_LIBRARY_SEARCH_SYSTEM32 );
1855- if (!ipv6_dll )
1856- continue ;
1857-
1858- ipv6_freeaddrinfo = (void (WSAAPI * )(struct addrinfo * ))
1859- GetProcAddress (ipv6_dll , "freeaddrinfo" );
1860- ipv6_getaddrinfo = (int (WSAAPI * )(const char * , const char * ,
1861- const struct addrinfo * ,
1862- struct addrinfo * * ))
1863- GetProcAddress (ipv6_dll , "getaddrinfo" );
1864- ipv6_getnameinfo = (int (WSAAPI * )(const struct sockaddr * ,
1865- socklen_t , char * , DWORD ,
1866- char * , DWORD , int ))
1867- GetProcAddress (ipv6_dll , "getnameinfo" );
1868- if (!ipv6_freeaddrinfo || !ipv6_getaddrinfo || !ipv6_getnameinfo ) {
1869- FreeLibrary (ipv6_dll );
1870- ipv6_dll = NULL ;
1871- } else
1872- break ;
1873- }
1874- if (!ipv6_freeaddrinfo || !ipv6_getaddrinfo || !ipv6_getnameinfo ) {
1875- ipv6_freeaddrinfo = freeaddrinfo_stub ;
1876- ipv6_getaddrinfo = getaddrinfo_stub ;
1877- ipv6_getnameinfo = getnameinfo_stub ;
1878- }
1879-
1880- atexit (socket_cleanup );
1720+ atexit ((void (* )(void )) WSACleanup );
18811721 initialized = 1 ;
18821722}
18831723
@@ -1895,24 +1735,12 @@ struct hostent *mingw_gethostbyname(const char *host)
18951735 return gethostbyname (host );
18961736}
18971737
1898- void mingw_freeaddrinfo (struct addrinfo * res )
1899- {
1900- ipv6_freeaddrinfo (res );
1901- }
1902-
1738+ #undef getaddrinfo
19031739int mingw_getaddrinfo (const char * node , const char * service ,
19041740 const struct addrinfo * hints , struct addrinfo * * res )
19051741{
19061742 ensure_socket_initialization ();
1907- return ipv6_getaddrinfo (node , service , hints , res );
1908- }
1909-
1910- int mingw_getnameinfo (const struct sockaddr * sa , socklen_t salen ,
1911- char * host , DWORD hostlen , char * serv , DWORD servlen ,
1912- int flags )
1913- {
1914- ensure_socket_initialization ();
1915- return ipv6_getnameinfo (sa , salen , host , hostlen , serv , servlen , flags );
1743+ return getaddrinfo (node , service , hints , res );
19161744}
19171745
19181746int mingw_socket (int domain , int type , int protocol )
0 commit comments