@@ -1630,142 +1630,10 @@ int mingw_putenv(const char *namevalue)
1630
1630
return result ? 0 : -1 ;
1631
1631
}
1632
1632
1633
- /*
1634
- * Note, this isn't a complete replacement for getaddrinfo. It assumes
1635
- * that service contains a numerical port, or that it is null. It
1636
- * does a simple search using gethostbyname, and returns one IPv4 host
1637
- * if one was found.
1638
- */
1639
- static int WSAAPI getaddrinfo_stub (const char * node , const char * service ,
1640
- const struct addrinfo * hints ,
1641
- struct addrinfo * * res )
1642
- {
1643
- struct hostent * h = NULL ;
1644
- struct addrinfo * ai ;
1645
- struct sockaddr_in * sin ;
1646
-
1647
- if (node ) {
1648
- h = gethostbyname (node );
1649
- if (!h )
1650
- return WSAGetLastError ();
1651
- }
1652
-
1653
- ai = xmalloc (sizeof (struct addrinfo ));
1654
- * res = ai ;
1655
- ai -> ai_flags = 0 ;
1656
- ai -> ai_family = AF_INET ;
1657
- ai -> ai_socktype = hints ? hints -> ai_socktype : 0 ;
1658
- switch (ai -> ai_socktype ) {
1659
- case SOCK_STREAM :
1660
- ai -> ai_protocol = IPPROTO_TCP ;
1661
- break ;
1662
- case SOCK_DGRAM :
1663
- ai -> ai_protocol = IPPROTO_UDP ;
1664
- break ;
1665
- default :
1666
- ai -> ai_protocol = 0 ;
1667
- break ;
1668
- }
1669
- ai -> ai_addrlen = sizeof (struct sockaddr_in );
1670
- if (hints && (hints -> ai_flags & AI_CANONNAME ))
1671
- ai -> ai_canonname = h ? xstrdup (h -> h_name ) : NULL ;
1672
- else
1673
- ai -> ai_canonname = NULL ;
1674
-
1675
- sin = xcalloc (1 , ai -> ai_addrlen );
1676
- sin -> sin_family = AF_INET ;
1677
- /* Note: getaddrinfo is supposed to allow service to be a string,
1678
- * which should be looked up using getservbyname. This is
1679
- * currently not implemented */
1680
- if (service )
1681
- sin -> sin_port = htons (atoi (service ));
1682
- if (h )
1683
- sin -> sin_addr = * (struct in_addr * )h -> h_addr ;
1684
- else if (hints && (hints -> ai_flags & AI_PASSIVE ))
1685
- sin -> sin_addr .s_addr = INADDR_ANY ;
1686
- else
1687
- sin -> sin_addr .s_addr = INADDR_LOOPBACK ;
1688
- ai -> ai_addr = (struct sockaddr * )sin ;
1689
- ai -> ai_next = NULL ;
1690
- return 0 ;
1691
- }
1692
-
1693
- static void WSAAPI freeaddrinfo_stub (struct addrinfo * res )
1694
- {
1695
- free (res -> ai_canonname );
1696
- free (res -> ai_addr );
1697
- free (res );
1698
- }
1699
-
1700
- static int WSAAPI getnameinfo_stub (const struct sockaddr * sa , socklen_t salen ,
1701
- char * host , DWORD hostlen ,
1702
- char * serv , DWORD servlen , int flags )
1703
- {
1704
- const struct sockaddr_in * sin = (const struct sockaddr_in * )sa ;
1705
- if (sa -> sa_family != AF_INET )
1706
- return EAI_FAMILY ;
1707
- if (!host && !serv )
1708
- return EAI_NONAME ;
1709
-
1710
- if (host && hostlen > 0 ) {
1711
- struct hostent * ent = NULL ;
1712
- if (!(flags & NI_NUMERICHOST ))
1713
- ent = gethostbyaddr ((const char * )& sin -> sin_addr ,
1714
- sizeof (sin -> sin_addr ), AF_INET );
1715
-
1716
- if (ent )
1717
- snprintf (host , hostlen , "%s" , ent -> h_name );
1718
- else if (flags & NI_NAMEREQD )
1719
- return EAI_NONAME ;
1720
- else
1721
- snprintf (host , hostlen , "%s" , inet_ntoa (sin -> sin_addr ));
1722
- }
1723
-
1724
- if (serv && servlen > 0 ) {
1725
- struct servent * ent = NULL ;
1726
- if (!(flags & NI_NUMERICSERV ))
1727
- ent = getservbyport (sin -> sin_port ,
1728
- flags & NI_DGRAM ? "udp" : "tcp" );
1729
-
1730
- if (ent )
1731
- snprintf (serv , servlen , "%s" , ent -> s_name );
1732
- else
1733
- snprintf (serv , servlen , "%d" , ntohs (sin -> sin_port ));
1734
- }
1735
-
1736
- return 0 ;
1737
- }
1738
-
1739
- static HMODULE ipv6_dll = NULL ;
1740
- static void (WSAAPI * ipv6_freeaddrinfo )(struct addrinfo * res );
1741
- static int (WSAAPI * ipv6_getaddrinfo )(const char * node , const char * service ,
1742
- const struct addrinfo * hints ,
1743
- struct addrinfo * * res );
1744
- static int (WSAAPI * ipv6_getnameinfo )(const struct sockaddr * sa , socklen_t salen ,
1745
- char * host , DWORD hostlen ,
1746
- char * serv , DWORD servlen , int flags );
1747
- /*
1748
- * gai_strerror is an inline function in the ws2tcpip.h header, so we
1749
- * don't need to try to load that one dynamically.
1750
- */
1751
-
1752
- static void socket_cleanup (void )
1753
- {
1754
- WSACleanup ();
1755
- if (ipv6_dll )
1756
- FreeLibrary (ipv6_dll );
1757
- ipv6_dll = NULL ;
1758
- ipv6_freeaddrinfo = freeaddrinfo_stub ;
1759
- ipv6_getaddrinfo = getaddrinfo_stub ;
1760
- ipv6_getnameinfo = getnameinfo_stub ;
1761
- }
1762
-
1763
1633
static void ensure_socket_initialization (void )
1764
1634
{
1765
1635
WSADATA wsa ;
1766
1636
static int initialized = 0 ;
1767
- const char * libraries [] = { "ws2_32.dll" , "wship6.dll" , NULL };
1768
- const char * * name ;
1769
1637
1770
1638
if (initialized )
1771
1639
return ;
@@ -1774,35 +1642,7 @@ static void ensure_socket_initialization(void)
1774
1642
die ("unable to initialize winsock subsystem, error %d" ,
1775
1643
WSAGetLastError ());
1776
1644
1777
- for (name = libraries ; * name ; name ++ ) {
1778
- ipv6_dll = LoadLibraryExA (* name , NULL ,
1779
- LOAD_LIBRARY_SEARCH_SYSTEM32 );
1780
- if (!ipv6_dll )
1781
- continue ;
1782
-
1783
- ipv6_freeaddrinfo = (void (WSAAPI * )(struct addrinfo * ))
1784
- GetProcAddress (ipv6_dll , "freeaddrinfo" );
1785
- ipv6_getaddrinfo = (int (WSAAPI * )(const char * , const char * ,
1786
- const struct addrinfo * ,
1787
- struct addrinfo * * ))
1788
- GetProcAddress (ipv6_dll , "getaddrinfo" );
1789
- ipv6_getnameinfo = (int (WSAAPI * )(const struct sockaddr * ,
1790
- socklen_t , char * , DWORD ,
1791
- char * , DWORD , int ))
1792
- GetProcAddress (ipv6_dll , "getnameinfo" );
1793
- if (!ipv6_freeaddrinfo || !ipv6_getaddrinfo || !ipv6_getnameinfo ) {
1794
- FreeLibrary (ipv6_dll );
1795
- ipv6_dll = NULL ;
1796
- } else
1797
- break ;
1798
- }
1799
- if (!ipv6_freeaddrinfo || !ipv6_getaddrinfo || !ipv6_getnameinfo ) {
1800
- ipv6_freeaddrinfo = freeaddrinfo_stub ;
1801
- ipv6_getaddrinfo = getaddrinfo_stub ;
1802
- ipv6_getnameinfo = getnameinfo_stub ;
1803
- }
1804
-
1805
- atexit (socket_cleanup );
1645
+ atexit ((void (* )(void )) WSACleanup );
1806
1646
initialized = 1 ;
1807
1647
}
1808
1648
@@ -1820,24 +1660,12 @@ struct hostent *mingw_gethostbyname(const char *host)
1820
1660
return gethostbyname (host );
1821
1661
}
1822
1662
1823
- void mingw_freeaddrinfo (struct addrinfo * res )
1824
- {
1825
- ipv6_freeaddrinfo (res );
1826
- }
1827
-
1663
+ #undef getaddrinfo
1828
1664
int mingw_getaddrinfo (const char * node , const char * service ,
1829
1665
const struct addrinfo * hints , struct addrinfo * * res )
1830
1666
{
1831
1667
ensure_socket_initialization ();
1832
- return ipv6_getaddrinfo (node , service , hints , res );
1833
- }
1834
-
1835
- int mingw_getnameinfo (const struct sockaddr * sa , socklen_t salen ,
1836
- char * host , DWORD hostlen , char * serv , DWORD servlen ,
1837
- int flags )
1838
- {
1839
- ensure_socket_initialization ();
1840
- return ipv6_getnameinfo (sa , salen , host , hostlen , serv , servlen , flags );
1668
+ return getaddrinfo (node , service , hints , res );
1841
1669
}
1842
1670
1843
1671
int mingw_socket (int domain , int type , int protocol )
0 commit comments