diff options
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/libc/net/getaddrinfo.c | 34 |
1 files changed, 26 insertions, 8 deletions
diff --git a/src/lib/libc/net/getaddrinfo.c b/src/lib/libc/net/getaddrinfo.c index 490b9861ae..0d14de7499 100644 --- a/src/lib/libc/net/getaddrinfo.c +++ b/src/lib/libc/net/getaddrinfo.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: getaddrinfo.c,v 1.46 2003/03/17 23:16:36 jason Exp $ */ | 1 | /* $OpenBSD: getaddrinfo.c,v 1.47 2003/05/14 05:38:34 itojun Exp $ */ |
2 | /* $KAME: getaddrinfo.c,v 1.31 2000/08/31 17:36:43 itojun Exp $ */ | 2 | /* $KAME: getaddrinfo.c,v 1.31 2000/08/31 17:36:43 itojun Exp $ */ |
3 | 3 | ||
4 | /* | 4 | /* |
@@ -203,7 +203,7 @@ static int explore_fqdn(const struct addrinfo *, const char *, | |||
203 | static int explore_null(const struct addrinfo *, | 203 | static int explore_null(const struct addrinfo *, |
204 | const char *, struct addrinfo **); | 204 | const char *, struct addrinfo **); |
205 | static int explore_numeric(const struct addrinfo *, const char *, | 205 | static int explore_numeric(const struct addrinfo *, const char *, |
206 | const char *, struct addrinfo **); | 206 | const char *, struct addrinfo **, const char *); |
207 | static int explore_numeric_scope(const struct addrinfo *, const char *, | 207 | static int explore_numeric_scope(const struct addrinfo *, const char *, |
208 | const char *, struct addrinfo **); | 208 | const char *, struct addrinfo **); |
209 | static int get_canonname(const struct addrinfo *, | 209 | static int get_canonname(const struct addrinfo *, |
@@ -418,7 +418,8 @@ getaddrinfo(hostname, servname, hints, res) | |||
418 | if (hostname == NULL) | 418 | if (hostname == NULL) |
419 | error = explore_null(pai, servname, &cur->ai_next); | 419 | error = explore_null(pai, servname, &cur->ai_next); |
420 | else | 420 | else |
421 | error = explore_numeric_scope(pai, hostname, servname, &cur->ai_next); | 421 | error = explore_numeric_scope(pai, hostname, servname, |
422 | &cur->ai_next); | ||
422 | 423 | ||
423 | if (error) | 424 | if (error) |
424 | goto free; | 425 | goto free; |
@@ -673,11 +674,12 @@ free: | |||
673 | * numeric hostname | 674 | * numeric hostname |
674 | */ | 675 | */ |
675 | static int | 676 | static int |
676 | explore_numeric(pai, hostname, servname, res) | 677 | explore_numeric(pai, hostname, servname, res, canonname) |
677 | const struct addrinfo *pai; | 678 | const struct addrinfo *pai; |
678 | const char *hostname; | 679 | const char *hostname; |
679 | const char *servname; | 680 | const char *servname; |
680 | struct addrinfo **res; | 681 | struct addrinfo **res; |
682 | const char *canonname; | ||
681 | { | 683 | { |
682 | const struct afd *afd; | 684 | const struct afd *afd; |
683 | struct addrinfo *cur; | 685 | struct addrinfo *cur; |
@@ -707,6 +709,14 @@ explore_numeric(pai, hostname, servname, res) | |||
707 | pai->ai_family == PF_UNSPEC /*?*/) { | 709 | pai->ai_family == PF_UNSPEC /*?*/) { |
708 | GET_AI(cur->ai_next, afd, pton); | 710 | GET_AI(cur->ai_next, afd, pton); |
709 | GET_PORT(cur->ai_next, servname); | 711 | GET_PORT(cur->ai_next, servname); |
712 | if ((pai->ai_flags & AI_CANONNAME)) { | ||
713 | /* | ||
714 | * Set the numeric address itself as | ||
715 | * the canonical name, based on a | ||
716 | * clarification in rfc2553bis-03. | ||
717 | */ | ||
718 | GET_CANONNAME(cur->ai_next, canonname); | ||
719 | } | ||
710 | while (cur && cur->ai_next) | 720 | while (cur && cur->ai_next) |
711 | cur = cur->ai_next; | 721 | cur = cur->ai_next; |
712 | } else | 722 | } else |
@@ -720,6 +730,14 @@ explore_numeric(pai, hostname, servname, res) | |||
720 | pai->ai_family == PF_UNSPEC /*?*/) { | 730 | pai->ai_family == PF_UNSPEC /*?*/) { |
721 | GET_AI(cur->ai_next, afd, pton); | 731 | GET_AI(cur->ai_next, afd, pton); |
722 | GET_PORT(cur->ai_next, servname); | 732 | GET_PORT(cur->ai_next, servname); |
733 | if ((pai->ai_flags & AI_CANONNAME)) { | ||
734 | /* | ||
735 | * Set the numeric address itself as | ||
736 | * the canonical name, based on a | ||
737 | * clarification in rfc2553bis-03. | ||
738 | */ | ||
739 | GET_CANONNAME(cur->ai_next, canonname); | ||
740 | } | ||
723 | while (cur && cur->ai_next) | 741 | while (cur && cur->ai_next) |
724 | cur = cur->ai_next; | 742 | cur = cur->ai_next; |
725 | } else | 743 | } else |
@@ -749,7 +767,7 @@ explore_numeric_scope(pai, hostname, servname, res) | |||
749 | struct addrinfo **res; | 767 | struct addrinfo **res; |
750 | { | 768 | { |
751 | #if !defined(SCOPE_DELIMITER) || !defined(INET6) | 769 | #if !defined(SCOPE_DELIMITER) || !defined(INET6) |
752 | return explore_numeric(pai, hostname, servname, res); | 770 | return explore_numeric(pai, hostname, servname, res, hostname); |
753 | #else | 771 | #else |
754 | const struct afd *afd; | 772 | const struct afd *afd; |
755 | struct addrinfo *cur; | 773 | struct addrinfo *cur; |
@@ -768,11 +786,11 @@ explore_numeric_scope(pai, hostname, servname, res) | |||
768 | return 0; | 786 | return 0; |
769 | 787 | ||
770 | if (!afd->a_scoped) | 788 | if (!afd->a_scoped) |
771 | return explore_numeric(pai, hostname, servname, res); | 789 | return explore_numeric(pai, hostname, servname, res, hostname); |
772 | 790 | ||
773 | cp = strchr(hostname, SCOPE_DELIMITER); | 791 | cp = strchr(hostname, SCOPE_DELIMITER); |
774 | if (cp == NULL) | 792 | if (cp == NULL) |
775 | return explore_numeric(pai, hostname, servname, res); | 793 | return explore_numeric(pai, hostname, servname, res, hostname); |
776 | 794 | ||
777 | /* | 795 | /* |
778 | * Handle special case of <scoped_address><delimiter><scope id> | 796 | * Handle special case of <scoped_address><delimiter><scope id> |
@@ -785,7 +803,7 @@ explore_numeric_scope(pai, hostname, servname, res) | |||
785 | addr = hostname2; | 803 | addr = hostname2; |
786 | scope = cp + 1; | 804 | scope = cp + 1; |
787 | 805 | ||
788 | error = explore_numeric(pai, addr, servname, res); | 806 | error = explore_numeric(pai, addr, servname, res, hostname); |
789 | if (error == 0) { | 807 | if (error == 0) { |
790 | u_int32_t scopeid; | 808 | u_int32_t scopeid; |
791 | 809 | ||