diff options
-rw-r--r-- | lib/libc/asr/asr_resolver.c | 28 | ||||
-rw-r--r-- | lib/libc/asr/getaddrinfo_async.c | 53 | ||||
-rw-r--r-- | lib/libc/asr/getnameinfo_async.c | 22 |
3 files changed, 46 insertions, 57 deletions
diff --git a/lib/libc/asr/asr_resolver.c b/lib/libc/asr/asr_resolver.c index 6afd10a8d80..7de2e3acb5c 100644 --- a/lib/libc/asr/asr_resolver.c +++ b/lib/libc/asr/asr_resolver.c @@ -1,4 +1,4 @@ -/* $OpenBSD: asr_resolver.c,v 1.5 2012/07/29 20:33:21 eric Exp $ */ +/* $OpenBSD: asr_resolver.c,v 1.6 2012/08/18 11:19:51 eric Exp $ */ /* * Copyright (c) 2012 Eric Faurot <eric@openbsd.org> * @@ -473,16 +473,21 @@ getaddrinfo(const char *hostname, const char *servname, { struct async *as; struct async_res ar; + int saved_errno = errno; as = getaddrinfo_async(hostname, servname, hints, NULL); - if (as == NULL) - return ((errno == ENOMEM) ? EAI_MEMORY : EAI_SYSTEM); + if (as == NULL) { + if (errno == ENOMEM) { + errno = saved_errno; + return (EAI_MEMORY); + } + return (EAI_SYSTEM); + } async_run_sync(as, &ar); - errno = ar.ar_errno; - h_errno = ar.ar_h_errno; *res = ar.ar_addrinfo; + errno = (ar.ar_gai_errno == EAI_SYSTEM) ? ar.ar_errno : saved_errno; return (ar.ar_gai_errno); } @@ -493,16 +498,21 @@ getnameinfo(const struct sockaddr *sa, socklen_t salen, char *host, { struct async *as; struct async_res ar; + int saved_errno = errno; as = getnameinfo_async(sa, salen, host, hostlen, serv, servlen, flags, NULL); - if (as == NULL) - return ((errno == ENOMEM) ? EAI_MEMORY : EAI_SYSTEM); + if (as == NULL) { + if (errno == ENOMEM) { + errno = saved_errno; + return (EAI_MEMORY); + } + return (EAI_SYSTEM); + } async_run_sync(as, &ar); - errno = ar.ar_errno; - h_errno = ar.ar_h_errno; + errno = (ar.ar_gai_errno == EAI_SYSTEM) ? ar.ar_errno : saved_errno; return (ar.ar_gai_errno); } diff --git a/lib/libc/asr/getaddrinfo_async.c b/lib/libc/asr/getaddrinfo_async.c index 2919c970743..7eb502256b8 100644 --- a/lib/libc/asr/getaddrinfo_async.c +++ b/lib/libc/asr/getaddrinfo_async.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getaddrinfo_async.c,v 1.4 2012/07/13 14:05:12 eric Exp $ */ +/* $OpenBSD: getaddrinfo_async.c,v 1.5 2012/08/18 11:19:51 eric Exp $ */ /* * Copyright (c) 2012 Eric Faurot <eric@openbsd.org> * @@ -110,15 +110,11 @@ getaddrinfo_async_run(struct async *as, struct async_res *ar) */ as->as_count = 0; - async_set_state(as, ASR_STATE_HALT); - ar->ar_errno = 0; - ar->ar_h_errno = NETDB_SUCCESS; - ar->ar_gai_errno = 0; if (as->as.ai.hostname == NULL && as->as.ai.servname == NULL) { - ar->ar_h_errno = NO_RECOVERY; ar->ar_gai_errno = EAI_NONAME; + async_set_state(as, ASR_STATE_HALT); break; } @@ -128,23 +124,23 @@ getaddrinfo_async_run(struct async *as, struct async_res *ar) ai->ai_canonname || ai->ai_addr || ai->ai_next) { - ar->ar_h_errno = NO_RECOVERY; ar->ar_gai_errno = EAI_BADHINTS; + async_set_state(as, ASR_STATE_HALT); break; } if (ai->ai_flags & ~AI_MASK || (ai->ai_flags & AI_CANONNAME && ai->ai_flags & AI_FQDN)) { - ar->ar_h_errno = NO_RECOVERY; ar->ar_gai_errno = EAI_BADFLAGS; + async_set_state(as, ASR_STATE_HALT); break; } if (ai->ai_family != PF_UNSPEC && ai->ai_family != PF_INET && ai->ai_family != PF_INET6) { - ar->ar_h_errno = NO_RECOVERY; ar->ar_gai_errno = EAI_FAMILY; + async_set_state(as, ASR_STATE_HALT); break; } @@ -152,23 +148,23 @@ getaddrinfo_async_run(struct async *as, struct async_res *ar) ai->ai_socktype != SOCK_DGRAM && ai->ai_socktype != SOCK_STREAM && ai->ai_socktype != SOCK_RAW) { - ar->ar_h_errno = NO_RECOVERY; ar->ar_gai_errno = EAI_SOCKTYPE; + async_set_state(as, ASR_STATE_HALT); break; } if (ai->ai_protocol && ai->ai_protocol != IPPROTO_UDP && ai->ai_protocol != IPPROTO_TCP) { - ar->ar_h_errno = NO_RECOVERY; ar->ar_gai_errno = EAI_PROTOCOL; + async_set_state(as, ASR_STATE_HALT); break; } if (ai->ai_socktype == SOCK_RAW && as->as.ai.servname != NULL) { - ar->ar_h_errno = NO_RECOVERY; ar->ar_gai_errno = EAI_SERVICE; + async_set_state(as, ASR_STATE_HALT); break; } @@ -179,8 +175,8 @@ getaddrinfo_async_run(struct async *as, struct async_res *ar) MATCH_PROTO(ai->ai_protocol, i)) break; if (matches[i].family == -1) { - ar->ar_h_errno = NO_RECOVERY; ar->ar_gai_errno = EAI_BADHINTS; + async_set_state(as, ASR_STATE_HALT); break; } @@ -194,11 +190,13 @@ getaddrinfo_async_run(struct async *as, struct async_res *ar) (as->as.ai.port_tcp == -1 && as->as.ai.port_udp == -1) || (ai->ai_protocol && (as->as.ai.port_udp == -1 || as->as.ai.port_tcp == -1))) { - ar->ar_h_errno = NO_RECOVERY; ar->ar_gai_errno = EAI_SERVICE; + async_set_state(as, ASR_STATE_HALT); break; } + ar->ar_gai_errno = 0; + /* If hostname is NULL, use local address */ if (as->as.ai.hostname == NULL) { for(family = iter_family(as, 1); @@ -217,17 +215,14 @@ getaddrinfo_async_run(struct async *as, struct async_res *ar) /* This can't fail */ sockaddr_from_str(&sa.sa, family, str); if ((r = add_sockaddr(as, &sa.sa, NULL))) { - ar->ar_errno = errno; - ar->ar_h_errno = NETDB_INTERNAL; ar->ar_gai_errno = r; - async_set_state(as, ASR_STATE_HALT); break; } } if (ar->ar_gai_errno == 0 && as->as_count == 0) { - ar->ar_h_errno = NO_DATA; ar->ar_gai_errno = EAI_NODATA; } + async_set_state(as, ASR_STATE_HALT); break; } @@ -241,21 +236,16 @@ getaddrinfo_async_run(struct async *as, struct async_res *ar) continue; if ((r = add_sockaddr(as, &sa.sa, NULL))) { - ar->ar_errno = errno; - ar->ar_h_errno = NETDB_INTERNAL; ar->ar_gai_errno = r; - async_set_state(as, ASR_STATE_HALT); - break; } - - async_set_state(as, ASR_STATE_HALT); break; } - if (ar->ar_gai_errno || as->as_count) + if (ar->ar_gai_errno || as->as_count) { + async_set_state(as, ASR_STATE_HALT); break; + } if (ai->ai_flags & AI_NUMERICHOST) { - ar->ar_h_errno = NO_RECOVERY; ar->ar_gai_errno = EAI_FAIL; async_set_state(as, ASR_STATE_HALT); break; @@ -273,8 +263,6 @@ getaddrinfo_async_run(struct async *as, struct async_res *ar) break; } if (r > (int)sizeof(fqdn)) { - ar->ar_errno = EINVAL; - ar->ar_h_errno = NO_RECOVERY; ar->ar_gai_errno = EAI_OVERFLOW; async_set_state(as, ASR_STATE_HALT); break; @@ -293,12 +281,9 @@ getaddrinfo_async_run(struct async *as, struct async_res *ar) as->as.ai.hints.ai_family, as->as.ai.hints.ai_flags, as->as_ctx); if (as->as.ai.subq == NULL) { - ar->ar_errno = errno; if (errno == EINVAL) { - ar->ar_h_errno = NO_RECOVERY; ar->ar_gai_errno = EAI_FAIL; } else { - ar->ar_h_errno = NETDB_INTERNAL; ar->ar_gai_errno = EAI_MEMORY; } async_set_state(as, ASR_STATE_HALT); @@ -317,8 +302,6 @@ getaddrinfo_async_run(struct async *as, struct async_res *ar) if (r == ASYNC_YIELD) { if ((r = add_sockaddr(as, &ar->ar_sa.sa, ar->ar_cname))) { - ar->ar_errno = errno; - ar->ar_h_errno = NETDB_INTERNAL; ar->ar_gai_errno = r; async_set_state(as, ASR_STATE_HALT); } @@ -352,12 +335,9 @@ getaddrinfo_async_run(struct async *as, struct async_res *ar) /* * No result found. Maybe we can try again. */ - ar->ar_errno = 0; if (as->as.ai.flags & ASYNC_AGAIN) { - ar->ar_h_errno = TRY_AGAIN; ar->ar_gai_errno = EAI_AGAIN; } else { - ar->ar_h_errno = NO_DATA; ar->ar_gai_errno = EAI_NODATA; } async_set_state(as, ASR_STATE_HALT); @@ -379,7 +359,6 @@ getaddrinfo_async_run(struct async *as, struct async_res *ar) default: ar->ar_errno = EOPNOTSUPP; - ar->ar_h_errno = NETDB_INTERNAL; ar->ar_gai_errno = EAI_SYSTEM; async_set_state(as, ASR_STATE_HALT); break; diff --git a/lib/libc/asr/getnameinfo_async.c b/lib/libc/asr/getnameinfo_async.c index 8ae109c6fa2..e32501f8337 100644 --- a/lib/libc/asr/getnameinfo_async.c +++ b/lib/libc/asr/getnameinfo_async.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getnameinfo_async.c,v 1.2 2012/04/25 20:28:25 eric Exp $ */ +/* $OpenBSD: getnameinfo_async.c,v 1.3 2012/08/18 11:19:51 eric Exp $ */ /* * Copyright (c) 2012 Eric Faurot <eric@openbsd.org> * @@ -112,13 +112,14 @@ getnameinfo_async_run(struct async *as, struct async_res *ar) if (as->as.ni.flags & NI_NUMERICHOST) { if (_numerichost(as) == -1) { - ar->ar_errno = errno; - if (ar->ar_errno == ENOMEM) + if (errno == ENOMEM) ar->ar_gai_errno = EAI_MEMORY; - else if (ar->ar_errno == ENOSPC) + else if (errno == ENOSPC) ar->ar_gai_errno = EAI_OVERFLOW; - else + else { + ar->ar_errno = errno; ar->ar_gai_errno = EAI_SYSTEM; + } } else ar->ar_gai_errno = 0; async_set_state(as, ASR_STATE_HALT); @@ -140,7 +141,6 @@ getnameinfo_async_run(struct async *as, struct async_res *ar) as->as.ni.sa.sa.sa_family, as->as_ctx); if (as->as.ni.subq == NULL) { - ar->ar_errno = errno; ar->ar_gai_errno = EAI_MEMORY; async_set_state(as, ASR_STATE_HALT); break; @@ -163,13 +163,14 @@ getnameinfo_async_run(struct async *as, struct async_res *ar) if (as->as.ni.flags & NI_NAMEREQD) { ar->ar_gai_errno = EAI_NONAME; } else if (_numerichost(as) == -1) { - ar->ar_errno = errno; - if (ar->ar_errno == ENOMEM) + if (errno == ENOMEM) ar->ar_gai_errno = EAI_MEMORY; - else if (ar->ar_errno == ENOSPC) + else if (errno == ENOSPC) ar->ar_gai_errno = EAI_OVERFLOW; - else + else { + ar->ar_errno = errno; ar->ar_gai_errno = EAI_SYSTEM; + } } else ar->ar_gai_errno = 0; } else { @@ -190,7 +191,6 @@ getnameinfo_async_run(struct async *as, struct async_res *ar) default: ar->ar_errno = EOPNOTSUPP; - ar->ar_h_errno = NETDB_INTERNAL; ar->ar_gai_errno = EAI_SYSTEM; async_set_state(as, ASR_STATE_HALT); break; |