sockaddr.c (251886) | sockaddr.c (253734) |
---|---|
1/* Licensed to the Apache Software Foundation (ASF) under one or more 2 * contributor license agreements. See the NOTICE file distributed with 3 * this work for additional information regarding copyright ownership. 4 * The ASF licenses this file to You under the Apache License, Version 2.0 5 * (the "License"); you may not use this file except in compliance with 6 * the License. You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 --- 342 unchanged lines hidden (view full) --- 351 } 352 else 353#endif /* AIX_SERVNAME_HACK */ 354 servname = apr_itoa(p, port); 355#endif /* OSF1 */ 356 } 357 error = getaddrinfo(hostname, servname, &hints, &ai_list); 358#ifdef HAVE_GAI_ADDRCONFIG | 1/* Licensed to the Apache Software Foundation (ASF) under one or more 2 * contributor license agreements. See the NOTICE file distributed with 3 * this work for additional information regarding copyright ownership. 4 * The ASF licenses this file to You under the Apache License, Version 2.0 5 * (the "License"); you may not use this file except in compliance with 6 * the License. You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 --- 342 unchanged lines hidden (view full) --- 351 } 352 else 353#endif /* AIX_SERVNAME_HACK */ 354 servname = apr_itoa(p, port); 355#endif /* OSF1 */ 356 } 357 error = getaddrinfo(hostname, servname, &hints, &ai_list); 358#ifdef HAVE_GAI_ADDRCONFIG |
359 if (error == EAI_BADFLAGS && family == APR_UNSPEC) { 360 /* Retry with no flags if AI_ADDRCONFIG was rejected. */ 361 hints.ai_flags = 0; | 359 /* 360 * Using AI_ADDRCONFIG involves some unfortunate guesswork because it 361 * does not consider loopback addresses when trying to determine if 362 * IPv4 or IPv6 is configured on a system (see RFC 3493). 363 * This is a problem if one actually wants to listen on or connect to 364 * the loopback address of a protocol family that is not otherwise 365 * configured on the system. See PR 52709. 366 * To work around some of the problems, retry without AI_ADDRCONFIG 367 * in case of EAI_ADDRFAMILY. 368 * XXX: apr_sockaddr_info_get() should really accept a flag to determine 369 * XXX: if AI_ADDRCONFIG's guesswork is wanted and if the address is 370 * XXX: to be used for listen() or connect(). 371 * 372 * In case of EAI_BADFLAGS, AI_ADDRCONFIG is not supported. 373 */ 374 if ((family == APR_UNSPEC) && (error == EAI_BADFLAGS 375#ifdef EAI_ADDRFAMILY 376 || error == EAI_ADDRFAMILY 377#endif 378 )) { 379 hints.ai_flags &= ~AI_ADDRCONFIG; |
362 error = getaddrinfo(hostname, servname, &hints, &ai_list); 363 } 364#endif 365 if (error) { 366#if defined(WIN32) 367 return apr_get_netos_error(); 368#else 369 if (error == EAI_SYSTEM) { | 380 error = getaddrinfo(hostname, servname, &hints, &ai_list); 381 } 382#endif 383 if (error) { 384#if defined(WIN32) 385 return apr_get_netos_error(); 386#else 387 if (error == EAI_SYSTEM) { |
370 return errno; | 388 return errno ? errno : APR_EGENERAL; |
371 } 372 else 373 { 374 /* issues with representing this with APR's error scheme: 375 * glibc uses negative values for these numbers, perhaps so 376 * they don't conflict with h_errno values... Tru64 uses 377 * positive values which conflict with h_errno values 378 */ --- 38 unchanged lines hidden (view full) --- 417 new_sa->hostname = prev_sa->hostname; 418 prev_sa->next = new_sa; 419 } 420 421 prev_sa = new_sa; 422 ai = ai->ai_next; 423 } 424 freeaddrinfo(ai_list); | 389 } 390 else 391 { 392 /* issues with representing this with APR's error scheme: 393 * glibc uses negative values for these numbers, perhaps so 394 * they don't conflict with h_errno values... Tru64 uses 395 * positive values which conflict with h_errno values 396 */ --- 38 unchanged lines hidden (view full) --- 435 new_sa->hostname = prev_sa->hostname; 436 prev_sa->next = new_sa; 437 } 438 439 prev_sa = new_sa; 440 ai = ai->ai_next; 441 } 442 freeaddrinfo(ai_list); |
443 444 if (prev_sa == NULL) { 445 /* 446 * getaddrinfo returned only useless entries and *sa is still empty. 447 * This should be treated as an error. 448 */ 449 return APR_EGENERAL; 450 } 451 |
|
425 return APR_SUCCESS; 426} 427 428static apr_status_t find_addresses(apr_sockaddr_t **sa, 429 const char *hostname, apr_int32_t family, 430 apr_port_t port, apr_int32_t flags, 431 apr_pool_t *p) 432{ --- 117 unchanged lines hidden (view full) --- 550 new_sa->hostname = prev_sa->hostname; 551 prev_sa->next = new_sa; 552 } 553 554 prev_sa = new_sa; 555 ++curaddr; 556 } 557 | 452 return APR_SUCCESS; 453} 454 455static apr_status_t find_addresses(apr_sockaddr_t **sa, 456 const char *hostname, apr_int32_t family, 457 apr_port_t port, apr_int32_t flags, 458 apr_pool_t *p) 459{ --- 117 unchanged lines hidden (view full) --- 577 new_sa->hostname = prev_sa->hostname; 578 prev_sa->next = new_sa; 579 } 580 581 prev_sa = new_sa; 582 ++curaddr; 583 } 584 |
585 if (prev_sa == NULL) { 586 /* this should not happen but no result should be treated as error */ 587 return APR_EGENERAL; 588 } 589 |
|
558 return APR_SUCCESS; 559} 560 561#endif /* end of !HAVE_GETADDRINFO code */ 562 563APR_DECLARE(apr_status_t) apr_sockaddr_info_get(apr_sockaddr_t **sa, 564 const char *hostname, 565 apr_int32_t family, apr_port_t port, --- 439 unchanged lines hidden (view full) --- 1005} 1006 1007APR_DECLARE(int) apr_ipsubnet_test(apr_ipsubnet_t *ipsub, apr_sockaddr_t *sa) 1008{ 1009#if APR_HAVE_IPV6 1010 /* XXX This line will segv on Win32 build with APR_HAVE_IPV6, 1011 * but without the IPV6 drivers installed. 1012 */ | 590 return APR_SUCCESS; 591} 592 593#endif /* end of !HAVE_GETADDRINFO code */ 594 595APR_DECLARE(apr_status_t) apr_sockaddr_info_get(apr_sockaddr_t **sa, 596 const char *hostname, 597 apr_int32_t family, apr_port_t port, --- 439 unchanged lines hidden (view full) --- 1037} 1038 1039APR_DECLARE(int) apr_ipsubnet_test(apr_ipsubnet_t *ipsub, apr_sockaddr_t *sa) 1040{ 1041#if APR_HAVE_IPV6 1042 /* XXX This line will segv on Win32 build with APR_HAVE_IPV6, 1043 * but without the IPV6 drivers installed. 1044 */ |
1013 if (sa->sa.sin.sin_family == AF_INET) { | 1045 if (sa->family == AF_INET) { |
1014 if (ipsub->family == AF_INET && 1015 ((sa->sa.sin.sin_addr.s_addr & ipsub->mask[0]) == ipsub->sub[0])) { 1016 return 1; 1017 } 1018 } 1019 else if (IN6_IS_ADDR_V4MAPPED((struct in6_addr *)sa->ipaddr_ptr)) { 1020 if (ipsub->family == AF_INET && 1021 (((apr_uint32_t *)sa->ipaddr_ptr)[3] & ipsub->mask[0]) == ipsub->sub[0]) { 1022 return 1; 1023 } 1024 } | 1046 if (ipsub->family == AF_INET && 1047 ((sa->sa.sin.sin_addr.s_addr & ipsub->mask[0]) == ipsub->sub[0])) { 1048 return 1; 1049 } 1050 } 1051 else if (IN6_IS_ADDR_V4MAPPED((struct in6_addr *)sa->ipaddr_ptr)) { 1052 if (ipsub->family == AF_INET && 1053 (((apr_uint32_t *)sa->ipaddr_ptr)[3] & ipsub->mask[0]) == ipsub->sub[0]) { 1054 return 1; 1055 } 1056 } |
1025 else { | 1057 else if (sa->family == AF_INET6 && ipsub->family == AF_INET6) { |
1026 apr_uint32_t *addr = (apr_uint32_t *)sa->ipaddr_ptr; 1027 1028 if ((addr[0] & ipsub->mask[0]) == ipsub->sub[0] && 1029 (addr[1] & ipsub->mask[1]) == ipsub->sub[1] && 1030 (addr[2] & ipsub->mask[2]) == ipsub->sub[2] && 1031 (addr[3] & ipsub->mask[3]) == ipsub->sub[3]) { 1032 return 1; 1033 } 1034 } 1035#else 1036 if ((sa->sa.sin.sin_addr.s_addr & ipsub->mask[0]) == ipsub->sub[0]) { 1037 return 1; 1038 } 1039#endif /* APR_HAVE_IPV6 */ 1040 return 0; /* no match */ 1041} | 1058 apr_uint32_t *addr = (apr_uint32_t *)sa->ipaddr_ptr; 1059 1060 if ((addr[0] & ipsub->mask[0]) == ipsub->sub[0] && 1061 (addr[1] & ipsub->mask[1]) == ipsub->sub[1] && 1062 (addr[2] & ipsub->mask[2]) == ipsub->sub[2] && 1063 (addr[3] & ipsub->mask[3]) == ipsub->sub[3]) { 1064 return 1; 1065 } 1066 } 1067#else 1068 if ((sa->sa.sin.sin_addr.s_addr & ipsub->mask[0]) == ipsub->sub[0]) { 1069 return 1; 1070 } 1071#endif /* APR_HAVE_IPV6 */ 1072 return 0; /* no match */ 1073} |