@@ -2270,179 +2270,21 @@ int mingw_putenv(const char *namevalue)
2270
2270
2271
2271
#endif
2272
2272
2273
- /*
2274
- * Note, this isn't a complete replacement for getaddrinfo. It assumes
2275
- * that service contains a numerical port, or that it is null. It
2276
- * does a simple search using gethostbyname, and returns one IPv4 host
2277
- * if one was found.
2278
- */
2279
- static int WSAAPI getaddrinfo_stub (const char * node , const char * service ,
2280
- const struct addrinfo * hints ,
2281
- struct addrinfo * * res )
2282
- {
2283
- struct hostent * h = NULL ;
2284
- struct addrinfo * ai ;
2285
- struct sockaddr_in * sin ;
2286
-
2287
- if (node ) {
2288
- h = gethostbyname (node );
2289
- if (!h )
2290
- return WSAGetLastError ();
2291
- }
2292
-
2293
- ai = xmalloc (sizeof (struct addrinfo ));
2294
- * res = ai ;
2295
- ai -> ai_flags = 0 ;
2296
- ai -> ai_family = AF_INET ;
2297
- ai -> ai_socktype = hints ? hints -> ai_socktype : 0 ;
2298
- switch (ai -> ai_socktype ) {
2299
- case SOCK_STREAM :
2300
- ai -> ai_protocol = IPPROTO_TCP ;
2301
- break ;
2302
- case SOCK_DGRAM :
2303
- ai -> ai_protocol = IPPROTO_UDP ;
2304
- break ;
2305
- default :
2306
- ai -> ai_protocol = 0 ;
2307
- break ;
2308
- }
2309
- ai -> ai_addrlen = sizeof (struct sockaddr_in );
2310
- if (hints && (hints -> ai_flags & AI_CANONNAME ))
2311
- ai -> ai_canonname = h ? xstrdup (h -> h_name ) : NULL ;
2312
- else
2313
- ai -> ai_canonname = NULL ;
2314
-
2315
- sin = xcalloc (1 , ai -> ai_addrlen );
2316
- sin -> sin_family = AF_INET ;
2317
- /* Note: getaddrinfo is supposed to allow service to be a string,
2318
- * which should be looked up using getservbyname. This is
2319
- * currently not implemented */
2320
- if (service )
2321
- sin -> sin_port = htons (atoi (service ));
2322
- if (h )
2323
- sin -> sin_addr = * (struct in_addr * )h -> h_addr ;
2324
- else if (hints && (hints -> ai_flags & AI_PASSIVE ))
2325
- sin -> sin_addr .s_addr = INADDR_ANY ;
2326
- else
2327
- sin -> sin_addr .s_addr = INADDR_LOOPBACK ;
2328
- ai -> ai_addr = (struct sockaddr * )sin ;
2329
- ai -> ai_next = NULL ;
2330
- return 0 ;
2331
- }
2332
-
2333
- static void WSAAPI freeaddrinfo_stub (struct addrinfo * res )
2334
- {
2335
- free (res -> ai_canonname );
2336
- free (res -> ai_addr );
2337
- free (res );
2338
- }
2339
-
2340
- static int WSAAPI getnameinfo_stub (const struct sockaddr * sa , socklen_t salen ,
2341
- char * host , DWORD hostlen ,
2342
- char * serv , DWORD servlen , int flags )
2343
- {
2344
- const struct sockaddr_in * sin = (const struct sockaddr_in * )sa ;
2345
- if (sa -> sa_family != AF_INET )
2346
- return EAI_FAMILY ;
2347
- if (!host && !serv )
2348
- return EAI_NONAME ;
2349
-
2350
- if (host && hostlen > 0 ) {
2351
- struct hostent * ent = NULL ;
2352
- if (!(flags & NI_NUMERICHOST ))
2353
- ent = gethostbyaddr ((const char * )& sin -> sin_addr ,
2354
- sizeof (sin -> sin_addr ), AF_INET );
2355
-
2356
- if (ent )
2357
- snprintf (host , hostlen , "%s" , ent -> h_name );
2358
- else if (flags & NI_NAMEREQD )
2359
- return EAI_NONAME ;
2360
- else
2361
- snprintf (host , hostlen , "%s" , inet_ntoa (sin -> sin_addr ));
2362
- }
2363
-
2364
- if (serv && servlen > 0 ) {
2365
- struct servent * ent = NULL ;
2366
- if (!(flags & NI_NUMERICSERV ))
2367
- ent = getservbyport (sin -> sin_port ,
2368
- flags & NI_DGRAM ? "udp" : "tcp" );
2369
-
2370
- if (ent )
2371
- snprintf (serv , servlen , "%s" , ent -> s_name );
2372
- else
2373
- snprintf (serv , servlen , "%d" , ntohs (sin -> sin_port ));
2374
- }
2375
-
2376
- return 0 ;
2377
- }
2378
-
2379
- static HMODULE ipv6_dll = NULL ;
2380
- static void (WSAAPI * ipv6_freeaddrinfo )(struct addrinfo * res );
2381
- static int (WSAAPI * ipv6_getaddrinfo )(const char * node , const char * service ,
2382
- const struct addrinfo * hints ,
2383
- struct addrinfo * * res );
2384
- static int (WSAAPI * ipv6_getnameinfo )(const struct sockaddr * sa , socklen_t salen ,
2385
- char * host , DWORD hostlen ,
2386
- char * serv , DWORD servlen , int flags );
2387
- /*
2388
- * gai_strerror is an inline function in the ws2tcpip.h header, so we
2389
- * don't need to try to load that one dynamically.
2390
- */
2391
-
2392
- static void socket_cleanup (void )
2393
- {
2394
- WSACleanup ();
2395
- if (ipv6_dll )
2396
- FreeLibrary (ipv6_dll );
2397
- ipv6_dll = NULL ;
2398
- ipv6_freeaddrinfo = freeaddrinfo_stub ;
2399
- ipv6_getaddrinfo = getaddrinfo_stub ;
2400
- ipv6_getnameinfo = getnameinfo_stub ;
2401
- }
2402
2273
2403
2274
static void ensure_socket_initialization (void )
2404
2275
{
2405
2276
WSADATA wsa ;
2406
2277
static int initialized = 0 ;
2407
- const char * libraries [] = { "ws2_32.dll" , "wship6.dll" , NULL };
2408
- const char * * name ;
2278
+
2409
2279
2410
2280
if (initialized )
2411
2281
return ;
2412
2282
2413
2283
if (WSAStartup (MAKEWORD (2 ,2 ), & wsa ))
2414
2284
die ("unable to initialize winsock subsystem, error %d" ,
2415
2285
WSAGetLastError ());
2416
-
2417
- for (name = libraries ; * name ; name ++ ) {
2418
- ipv6_dll = LoadLibraryExA (* name , NULL ,
2419
- LOAD_LIBRARY_SEARCH_SYSTEM32 );
2420
- if (!ipv6_dll )
2421
- continue ;
2422
-
2423
- ipv6_freeaddrinfo = (void (WSAAPI * )(struct addrinfo * ))
2424
- GetProcAddress (ipv6_dll , "freeaddrinfo" );
2425
- ipv6_getaddrinfo = (int (WSAAPI * )(const char * , const char * ,
2426
- const struct addrinfo * ,
2427
- struct addrinfo * * ))
2428
- GetProcAddress (ipv6_dll , "getaddrinfo" );
2429
- ipv6_getnameinfo = (int (WSAAPI * )(const struct sockaddr * ,
2430
- socklen_t , char * , DWORD ,
2431
- char * , DWORD , int ))
2432
- GetProcAddress (ipv6_dll , "getnameinfo" );
2433
- if (!ipv6_freeaddrinfo || !ipv6_getaddrinfo || !ipv6_getnameinfo ) {
2434
- FreeLibrary (ipv6_dll );
2435
- ipv6_dll = NULL ;
2436
- } else
2437
- break ;
2438
- }
2439
- if (!ipv6_freeaddrinfo || !ipv6_getaddrinfo || !ipv6_getnameinfo ) {
2440
- ipv6_freeaddrinfo = freeaddrinfo_stub ;
2441
- ipv6_getaddrinfo = getaddrinfo_stub ;
2442
- ipv6_getnameinfo = getnameinfo_stub ;
2443
- }
2444
-
2445
- atexit (socket_cleanup );
2286
+
2287
+ atexit ((void (* )(void )) WSACleanup );
2446
2288
initialized = 1 ;
2447
2289
}
2448
2290
@@ -2460,26 +2302,6 @@ struct hostent *mingw_gethostbyname(const char *host)
2460
2302
return gethostbyname (host );
2461
2303
}
2462
2304
2463
- void mingw_freeaddrinfo (struct addrinfo * res )
2464
- {
2465
- ipv6_freeaddrinfo (res );
2466
- }
2467
-
2468
- int mingw_getaddrinfo (const char * node , const char * service ,
2469
- const struct addrinfo * hints , struct addrinfo * * res )
2470
- {
2471
- ensure_socket_initialization ();
2472
- return ipv6_getaddrinfo (node , service , hints , res );
2473
- }
2474
-
2475
- int mingw_getnameinfo (const struct sockaddr * sa , socklen_t salen ,
2476
- char * host , DWORD hostlen , char * serv , DWORD servlen ,
2477
- int flags )
2478
- {
2479
- ensure_socket_initialization ();
2480
- return ipv6_getnameinfo (sa , salen , host , hostlen , serv , servlen , flags );
2481
- }
2482
-
2483
2305
int mingw_socket (int domain , int type , int protocol )
2484
2306
{
2485
2307
int sockfd ;
0 commit comments