diff options
author | ume <ume@FreeBSD.org> | 2006-07-21 18:57:44 +0000 |
---|---|---|
committer | ume <ume@FreeBSD.org> | 2006-07-21 18:57:44 +0000 |
commit | 9cc6e84d28d55e96dea517a0afa186cda673010f (patch) | |
tree | c0e88b1bb9599c748f95d790d022915d3c896346 /lib | |
parent | cd6fe3744084e02ffd7e31613b881b8b2afb62ba (diff) | |
download | FreeBSD-src-9cc6e84d28d55e96dea517a0afa186cda673010f.zip FreeBSD-src-9cc6e84d28d55e96dea517a0afa186cda673010f.tar.gz |
clean-up: rewrote explore_null and explore_numeric without using sentinel.
we do not need it since we make (at most) a single addrinfo entry in these
cases.
Obtained from: KAME
MFC after: 1 week
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libc/net/getaddrinfo.c | 55 |
1 files changed, 20 insertions, 35 deletions
diff --git a/lib/libc/net/getaddrinfo.c b/lib/libc/net/getaddrinfo.c index b422c4b..d93c14b 100644 --- a/lib/libc/net/getaddrinfo.c +++ b/lib/libc/net/getaddrinfo.c @@ -1062,13 +1062,11 @@ explore_null(const struct addrinfo *pai, const char *servname, { int s; const struct afd *afd; - struct addrinfo *cur; - struct addrinfo sentinel; + struct addrinfo *ai; int error; *res = NULL; - sentinel.ai_next = NULL; - cur = &sentinel; + ai = NULL; /* * filter out AFs that are not supported by the kernel @@ -1092,26 +1090,19 @@ explore_null(const struct addrinfo *pai, const char *servname, return 0; if (pai->ai_flags & AI_PASSIVE) { - GET_AI(cur->ai_next, afd, afd->a_addrany); - /* xxx meaningless? - * GET_CANONNAME(cur->ai_next, "anyaddr"); - */ - GET_PORT(cur->ai_next, servname); + GET_AI(ai, afd, afd->a_addrany); + GET_PORT(ai, servname); } else { - GET_AI(cur->ai_next, afd, afd->a_loopback); - /* xxx meaningless? - * GET_CANONNAME(cur->ai_next, "localhost"); - */ - GET_PORT(cur->ai_next, servname); + GET_AI(ai, afd, afd->a_loopback); + GET_PORT(ai, servname); } - cur = cur->ai_next; - *res = sentinel.ai_next; + *res = ai; return 0; free: - if (sentinel.ai_next) - freeaddrinfo(sentinel.ai_next); + if (ai != NULL) + freeaddrinfo(ai); return error; } @@ -1123,14 +1114,12 @@ explore_numeric(const struct addrinfo *pai, const char *hostname, const char *servname, struct addrinfo **res, const char *canonname) { const struct afd *afd; - struct addrinfo *cur; - struct addrinfo sentinel; + struct addrinfo *ai; int error; char pton[PTON_MAX]; *res = NULL; - sentinel.ai_next = NULL; - cur = &sentinel; + ai = NULL; /* * if the servname does not match socktype/protocol, ignore it. @@ -1148,18 +1137,16 @@ explore_numeric(const struct addrinfo *pai, const char *hostname, if (inet_aton(hostname, (struct in_addr *)pton) == 1) { if (pai->ai_family == afd->a_af || pai->ai_family == PF_UNSPEC /*?*/) { - GET_AI(cur->ai_next, afd, pton); - GET_PORT(cur->ai_next, servname); + GET_AI(ai, afd, pton); + GET_PORT(ai, servname); if ((pai->ai_flags & AI_CANONNAME)) { /* * Set the numeric address itself as * the canonical name, based on a * clarification in rfc3493. */ - GET_CANONNAME(cur->ai_next, canonname); + GET_CANONNAME(ai, canonname); } - while (cur && cur->ai_next) - cur = cur->ai_next; } else ERR(EAI_FAMILY); /*xxx*/ } @@ -1169,31 +1156,29 @@ explore_numeric(const struct addrinfo *pai, const char *hostname, if (inet_pton(afd->a_af, hostname, pton) == 1) { if (pai->ai_family == afd->a_af || pai->ai_family == PF_UNSPEC /*?*/) { - GET_AI(cur->ai_next, afd, pton); - GET_PORT(cur->ai_next, servname); + GET_AI(ai, afd, pton); + GET_PORT(ai, servname); if ((pai->ai_flags & AI_CANONNAME)) { /* * Set the numeric address itself as * the canonical name, based on a * clarification in rfc3493. */ - GET_CANONNAME(cur->ai_next, canonname); + GET_CANONNAME(ai, canonname); } - while (cur && cur->ai_next) - cur = cur->ai_next; } else ERR(EAI_FAMILY); /* XXX */ } break; } - *res = sentinel.ai_next; + *res = ai; return 0; free: bad: - if (sentinel.ai_next) - freeaddrinfo(sentinel.ai_next); + if (ai != NULL) + freeaddrinfo(ai); return error; } |