@@ -2083,142 +2083,10 @@ int mingw_putenv(const char *namevalue)
2083
2083
return result ? 0 : -1 ;
2084
2084
}
2085
2085
2086
- /*
2087
- * Note, this isn't a complete replacement for getaddrinfo. It assumes
2088
- * that service contains a numerical port, or that it is null. It
2089
- * does a simple search using gethostbyname, and returns one IPv4 host
2090
- * if one was found.
2091
- */
2092
- static int WSAAPI getaddrinfo_stub (const char * node , const char * service ,
2093
- const struct addrinfo * hints ,
2094
- struct addrinfo * * res )
2095
- {
2096
- struct hostent * h = NULL ;
2097
- struct addrinfo * ai ;
2098
- struct sockaddr_in * sin ;
2099
-
2100
- if (node ) {
2101
- h = gethostbyname (node );
2102
- if (!h )
2103
- return WSAGetLastError ();
2104
- }
2105
-
2106
- ai = xmalloc (sizeof (struct addrinfo ));
2107
- * res = ai ;
2108
- ai -> ai_flags = 0 ;
2109
- ai -> ai_family = AF_INET ;
2110
- ai -> ai_socktype = hints ? hints -> ai_socktype : 0 ;
2111
- switch (ai -> ai_socktype ) {
2112
- case SOCK_STREAM :
2113
- ai -> ai_protocol = IPPROTO_TCP ;
2114
- break ;
2115
- case SOCK_DGRAM :
2116
- ai -> ai_protocol = IPPROTO_UDP ;
2117
- break ;
2118
- default :
2119
- ai -> ai_protocol = 0 ;
2120
- break ;
2121
- }
2122
- ai -> ai_addrlen = sizeof (struct sockaddr_in );
2123
- if (hints && (hints -> ai_flags & AI_CANONNAME ))
2124
- ai -> ai_canonname = h ? xstrdup (h -> h_name ) : NULL ;
2125
- else
2126
- ai -> ai_canonname = NULL ;
2127
-
2128
- sin = xcalloc (1 , ai -> ai_addrlen );
2129
- sin -> sin_family = AF_INET ;
2130
- /* Note: getaddrinfo is supposed to allow service to be a string,
2131
- * which should be looked up using getservbyname. This is
2132
- * currently not implemented */
2133
- if (service )
2134
- sin -> sin_port = htons (atoi (service ));
2135
- if (h )
2136
- sin -> sin_addr = * (struct in_addr * )h -> h_addr ;
2137
- else if (hints && (hints -> ai_flags & AI_PASSIVE ))
2138
- sin -> sin_addr .s_addr = INADDR_ANY ;
2139
- else
2140
- sin -> sin_addr .s_addr = INADDR_LOOPBACK ;
2141
- ai -> ai_addr = (struct sockaddr * )sin ;
2142
- ai -> ai_next = NULL ;
2143
- return 0 ;
2144
- }
2145
-
2146
- static void WSAAPI freeaddrinfo_stub (struct addrinfo * res )
2147
- {
2148
- free (res -> ai_canonname );
2149
- free (res -> ai_addr );
2150
- free (res );
2151
- }
2152
-
2153
- static int WSAAPI getnameinfo_stub (const struct sockaddr * sa , socklen_t salen ,
2154
- char * host , DWORD hostlen ,
2155
- char * serv , DWORD servlen , int flags )
2156
- {
2157
- const struct sockaddr_in * sin = (const struct sockaddr_in * )sa ;
2158
- if (sa -> sa_family != AF_INET )
2159
- return EAI_FAMILY ;
2160
- if (!host && !serv )
2161
- return EAI_NONAME ;
2162
-
2163
- if (host && hostlen > 0 ) {
2164
- struct hostent * ent = NULL ;
2165
- if (!(flags & NI_NUMERICHOST ))
2166
- ent = gethostbyaddr ((const char * )& sin -> sin_addr ,
2167
- sizeof (sin -> sin_addr ), AF_INET );
2168
-
2169
- if (ent )
2170
- snprintf (host , hostlen , "%s" , ent -> h_name );
2171
- else if (flags & NI_NAMEREQD )
2172
- return EAI_NONAME ;
2173
- else
2174
- snprintf (host , hostlen , "%s" , inet_ntoa (sin -> sin_addr ));
2175
- }
2176
-
2177
- if (serv && servlen > 0 ) {
2178
- struct servent * ent = NULL ;
2179
- if (!(flags & NI_NUMERICSERV ))
2180
- ent = getservbyport (sin -> sin_port ,
2181
- flags & NI_DGRAM ? "udp" : "tcp" );
2182
-
2183
- if (ent )
2184
- snprintf (serv , servlen , "%s" , ent -> s_name );
2185
- else
2186
- snprintf (serv , servlen , "%d" , ntohs (sin -> sin_port ));
2187
- }
2188
-
2189
- return 0 ;
2190
- }
2191
-
2192
- static HMODULE ipv6_dll = NULL ;
2193
- static void (WSAAPI * ipv6_freeaddrinfo )(struct addrinfo * res );
2194
- static int (WSAAPI * ipv6_getaddrinfo )(const char * node , const char * service ,
2195
- const struct addrinfo * hints ,
2196
- struct addrinfo * * res );
2197
- static int (WSAAPI * ipv6_getnameinfo )(const struct sockaddr * sa , socklen_t salen ,
2198
- char * host , DWORD hostlen ,
2199
- char * serv , DWORD servlen , int flags );
2200
- /*
2201
- * gai_strerror is an inline function in the ws2tcpip.h header, so we
2202
- * don't need to try to load that one dynamically.
2203
- */
2204
-
2205
- static void socket_cleanup (void )
2206
- {
2207
- WSACleanup ();
2208
- if (ipv6_dll )
2209
- FreeLibrary (ipv6_dll );
2210
- ipv6_dll = NULL ;
2211
- ipv6_freeaddrinfo = freeaddrinfo_stub ;
2212
- ipv6_getaddrinfo = getaddrinfo_stub ;
2213
- ipv6_getnameinfo = getnameinfo_stub ;
2214
- }
2215
-
2216
2086
static void ensure_socket_initialization (void )
2217
2087
{
2218
2088
WSADATA wsa ;
2219
2089
static int initialized = 0 ;
2220
- const char * libraries [] = { "ws2_32.dll" , "wship6.dll" , NULL };
2221
- const char * * name ;
2222
2090
2223
2091
if (initialized )
2224
2092
return ;
@@ -2227,35 +2095,7 @@ static void ensure_socket_initialization(void)
2227
2095
die ("unable to initialize winsock subsystem, error %d" ,
2228
2096
WSAGetLastError ());
2229
2097
2230
- for (name = libraries ; * name ; name ++ ) {
2231
- ipv6_dll = LoadLibraryExA (* name , NULL ,
2232
- LOAD_LIBRARY_SEARCH_SYSTEM32 );
2233
- if (!ipv6_dll )
2234
- continue ;
2235
-
2236
- ipv6_freeaddrinfo = (void (WSAAPI * )(struct addrinfo * ))
2237
- GetProcAddress (ipv6_dll , "freeaddrinfo" );
2238
- ipv6_getaddrinfo = (int (WSAAPI * )(const char * , const char * ,
2239
- const struct addrinfo * ,
2240
- struct addrinfo * * ))
2241
- GetProcAddress (ipv6_dll , "getaddrinfo" );
2242
- ipv6_getnameinfo = (int (WSAAPI * )(const struct sockaddr * ,
2243
- socklen_t , char * , DWORD ,
2244
- char * , DWORD , int ))
2245
- GetProcAddress (ipv6_dll , "getnameinfo" );
2246
- if (!ipv6_freeaddrinfo || !ipv6_getaddrinfo || !ipv6_getnameinfo ) {
2247
- FreeLibrary (ipv6_dll );
2248
- ipv6_dll = NULL ;
2249
- } else
2250
- break ;
2251
- }
2252
- if (!ipv6_freeaddrinfo || !ipv6_getaddrinfo || !ipv6_getnameinfo ) {
2253
- ipv6_freeaddrinfo = freeaddrinfo_stub ;
2254
- ipv6_getaddrinfo = getaddrinfo_stub ;
2255
- ipv6_getnameinfo = getnameinfo_stub ;
2256
- }
2257
-
2258
- atexit (socket_cleanup );
2098
+ atexit ((void (* )(void )) WSACleanup );
2259
2099
initialized = 1 ;
2260
2100
}
2261
2101
@@ -2273,26 +2113,6 @@ struct hostent *mingw_gethostbyname(const char *host)
2273
2113
return gethostbyname (host );
2274
2114
}
2275
2115
2276
- void mingw_freeaddrinfo (struct addrinfo * res )
2277
- {
2278
- ipv6_freeaddrinfo (res );
2279
- }
2280
-
2281
- int mingw_getaddrinfo (const char * node , const char * service ,
2282
- const struct addrinfo * hints , struct addrinfo * * res )
2283
- {
2284
- ensure_socket_initialization ();
2285
- return ipv6_getaddrinfo (node , service , hints , res );
2286
- }
2287
-
2288
- int mingw_getnameinfo (const struct sockaddr * sa , socklen_t salen ,
2289
- char * host , DWORD hostlen , char * serv , DWORD servlen ,
2290
- int flags )
2291
- {
2292
- ensure_socket_initialization ();
2293
- return ipv6_getnameinfo (sa , salen , host , hostlen , serv , servlen , flags );
2294
- }
2295
-
2296
2116
int mingw_socket (int domain , int type , int protocol )
2297
2117
{
2298
2118
int sockfd ;
0 commit comments