@@ -1729,142 +1729,10 @@ int mingw_putenv(const char *namevalue)
17291729 return result ? 0 : -1 ;
17301730}
17311731
1732- /*
1733- * Note, this isn't a complete replacement for getaddrinfo. It assumes
1734- * that service contains a numerical port, or that it is null. It
1735- * does a simple search using gethostbyname, and returns one IPv4 host
1736- * if one was found.
1737- */
1738- static int WSAAPI getaddrinfo_stub (const char * node , const char * service ,
1739- const struct addrinfo * hints ,
1740- struct addrinfo * * res )
1741- {
1742- struct hostent * h = NULL ;
1743- struct addrinfo * ai ;
1744- struct sockaddr_in * sin ;
1745-
1746- if (node ) {
1747- h = gethostbyname (node );
1748- if (!h )
1749- return WSAGetLastError ();
1750- }
1751-
1752- ai = xmalloc (sizeof (struct addrinfo ));
1753- * res = ai ;
1754- ai -> ai_flags = 0 ;
1755- ai -> ai_family = AF_INET ;
1756- ai -> ai_socktype = hints ? hints -> ai_socktype : 0 ;
1757- switch (ai -> ai_socktype ) {
1758- case SOCK_STREAM :
1759- ai -> ai_protocol = IPPROTO_TCP ;
1760- break ;
1761- case SOCK_DGRAM :
1762- ai -> ai_protocol = IPPROTO_UDP ;
1763- break ;
1764- default :
1765- ai -> ai_protocol = 0 ;
1766- break ;
1767- }
1768- ai -> ai_addrlen = sizeof (struct sockaddr_in );
1769- if (hints && (hints -> ai_flags & AI_CANONNAME ))
1770- ai -> ai_canonname = h ? xstrdup (h -> h_name ) : NULL ;
1771- else
1772- ai -> ai_canonname = NULL ;
1773-
1774- sin = xcalloc (1 , ai -> ai_addrlen );
1775- sin -> sin_family = AF_INET ;
1776- /* Note: getaddrinfo is supposed to allow service to be a string,
1777- * which should be looked up using getservbyname. This is
1778- * currently not implemented */
1779- if (service )
1780- sin -> sin_port = htons (atoi (service ));
1781- if (h )
1782- sin -> sin_addr = * (struct in_addr * )h -> h_addr ;
1783- else if (hints && (hints -> ai_flags & AI_PASSIVE ))
1784- sin -> sin_addr .s_addr = INADDR_ANY ;
1785- else
1786- sin -> sin_addr .s_addr = INADDR_LOOPBACK ;
1787- ai -> ai_addr = (struct sockaddr * )sin ;
1788- ai -> ai_next = NULL ;
1789- return 0 ;
1790- }
1791-
1792- static void WSAAPI freeaddrinfo_stub (struct addrinfo * res )
1793- {
1794- free (res -> ai_canonname );
1795- free (res -> ai_addr );
1796- free (res );
1797- }
1798-
1799- static int WSAAPI getnameinfo_stub (const struct sockaddr * sa , socklen_t salen ,
1800- char * host , DWORD hostlen ,
1801- char * serv , DWORD servlen , int flags )
1802- {
1803- const struct sockaddr_in * sin = (const struct sockaddr_in * )sa ;
1804- if (sa -> sa_family != AF_INET )
1805- return EAI_FAMILY ;
1806- if (!host && !serv )
1807- return EAI_NONAME ;
1808-
1809- if (host && hostlen > 0 ) {
1810- struct hostent * ent = NULL ;
1811- if (!(flags & NI_NUMERICHOST ))
1812- ent = gethostbyaddr ((const char * )& sin -> sin_addr ,
1813- sizeof (sin -> sin_addr ), AF_INET );
1814-
1815- if (ent )
1816- snprintf (host , hostlen , "%s" , ent -> h_name );
1817- else if (flags & NI_NAMEREQD )
1818- return EAI_NONAME ;
1819- else
1820- snprintf (host , hostlen , "%s" , inet_ntoa (sin -> sin_addr ));
1821- }
1822-
1823- if (serv && servlen > 0 ) {
1824- struct servent * ent = NULL ;
1825- if (!(flags & NI_NUMERICSERV ))
1826- ent = getservbyport (sin -> sin_port ,
1827- flags & NI_DGRAM ? "udp" : "tcp" );
1828-
1829- if (ent )
1830- snprintf (serv , servlen , "%s" , ent -> s_name );
1831- else
1832- snprintf (serv , servlen , "%d" , ntohs (sin -> sin_port ));
1833- }
1834-
1835- return 0 ;
1836- }
1837-
1838- static HMODULE ipv6_dll = NULL ;
1839- static void (WSAAPI * ipv6_freeaddrinfo )(struct addrinfo * res );
1840- static int (WSAAPI * ipv6_getaddrinfo )(const char * node , const char * service ,
1841- const struct addrinfo * hints ,
1842- struct addrinfo * * res );
1843- static int (WSAAPI * ipv6_getnameinfo )(const struct sockaddr * sa , socklen_t salen ,
1844- char * host , DWORD hostlen ,
1845- char * serv , DWORD servlen , int flags );
1846- /*
1847- * gai_strerror is an inline function in the ws2tcpip.h header, so we
1848- * don't need to try to load that one dynamically.
1849- */
1850-
1851- static void socket_cleanup (void )
1852- {
1853- WSACleanup ();
1854- if (ipv6_dll )
1855- FreeLibrary (ipv6_dll );
1856- ipv6_dll = NULL ;
1857- ipv6_freeaddrinfo = freeaddrinfo_stub ;
1858- ipv6_getaddrinfo = getaddrinfo_stub ;
1859- ipv6_getnameinfo = getnameinfo_stub ;
1860- }
1861-
18621732static void ensure_socket_initialization (void )
18631733{
18641734 WSADATA wsa ;
18651735 static int initialized = 0 ;
1866- const char * libraries [] = { "ws2_32.dll" , "wship6.dll" , NULL };
1867- const char * * name ;
18681736
18691737 if (initialized )
18701738 return ;
@@ -1873,35 +1741,7 @@ static void ensure_socket_initialization(void)
18731741 die ("unable to initialize winsock subsystem, error %d" ,
18741742 WSAGetLastError ());
18751743
1876- for (name = libraries ; * name ; name ++ ) {
1877- ipv6_dll = LoadLibraryExA (* name , NULL ,
1878- LOAD_LIBRARY_SEARCH_SYSTEM32 );
1879- if (!ipv6_dll )
1880- continue ;
1881-
1882- ipv6_freeaddrinfo = (void (WSAAPI * )(struct addrinfo * ))
1883- GetProcAddress (ipv6_dll , "freeaddrinfo" );
1884- ipv6_getaddrinfo = (int (WSAAPI * )(const char * , const char * ,
1885- const struct addrinfo * ,
1886- struct addrinfo * * ))
1887- GetProcAddress (ipv6_dll , "getaddrinfo" );
1888- ipv6_getnameinfo = (int (WSAAPI * )(const struct sockaddr * ,
1889- socklen_t , char * , DWORD ,
1890- char * , DWORD , int ))
1891- GetProcAddress (ipv6_dll , "getnameinfo" );
1892- if (!ipv6_freeaddrinfo || !ipv6_getaddrinfo || !ipv6_getnameinfo ) {
1893- FreeLibrary (ipv6_dll );
1894- ipv6_dll = NULL ;
1895- } else
1896- break ;
1897- }
1898- if (!ipv6_freeaddrinfo || !ipv6_getaddrinfo || !ipv6_getnameinfo ) {
1899- ipv6_freeaddrinfo = freeaddrinfo_stub ;
1900- ipv6_getaddrinfo = getaddrinfo_stub ;
1901- ipv6_getnameinfo = getnameinfo_stub ;
1902- }
1903-
1904- atexit (socket_cleanup );
1744+ atexit ((void (* )(void )) WSACleanup );
19051745 initialized = 1 ;
19061746}
19071747
@@ -1919,24 +1759,12 @@ struct hostent *mingw_gethostbyname(const char *host)
19191759 return gethostbyname (host );
19201760}
19211761
1922- void mingw_freeaddrinfo (struct addrinfo * res )
1923- {
1924- ipv6_freeaddrinfo (res );
1925- }
1926-
1762+ #undef getaddrinfo
19271763int mingw_getaddrinfo (const char * node , const char * service ,
19281764 const struct addrinfo * hints , struct addrinfo * * res )
19291765{
19301766 ensure_socket_initialization ();
1931- return ipv6_getaddrinfo (node , service , hints , res );
1932- }
1933-
1934- int mingw_getnameinfo (const struct sockaddr * sa , socklen_t salen ,
1935- char * host , DWORD hostlen , char * serv , DWORD servlen ,
1936- int flags )
1937- {
1938- ensure_socket_initialization ();
1939- return ipv6_getnameinfo (sa , salen , host , hostlen , serv , servlen , flags );
1767+ return getaddrinfo (node , service , hints , res );
19401768}
19411769
19421770int mingw_socket (int domain , int type , int protocol )
0 commit comments