summaryrefslogtreecommitdiff
path: root/libc/inet/getaddrinfo.c
diff options
context:
space:
mode:
authorCarmelo Amoroso <carmelo.amoroso@st.com>2011-05-04 08:31:16 +0200
committerCarmelo Amoroso <carmelo.amoroso@st.com>2011-05-04 08:31:16 +0200
commit3004ce0c9619f89bf8e64931edd696bf4df8d2e1 (patch)
treef03f898fa5c2506c4e30f5f89ce097acf01bc016 /libc/inet/getaddrinfo.c
parent3b3285b1b7c02d36c74a6ae265fdb02ca991c96b (diff)
parent4916fd889ec1c60710faa528a3ccdb50973198e2 (diff)
Merge remote-tracking branch 'origin/master' into prelink
* origin/master: (32 commits) libubacktrace: fix backtrace support on arm-eabi, which needs libgcc_eh linked too getaddrinfo.c: fix incorrect check for ERANGE from gethostbyaddr_r getaddrinfo.c: improve code readability. No functional changes string: remove unused variable x86_64: silence warning if !TLS buildsys: prettify ssp.c handling madvise is LINUX_SPECIFIC test_nptl: fix expected result for tst-cputimer[123] test_nptl: fix expected result for tst-clock2 test buildsys: make $(LOCAL_INSTALL_PATH) phony ether_aton: reject invalid input tests: disable ether tests if !HAS_SOCKET inet: add ether_aton testcase sysconf: clock_getres depends on HAS_REALTIME __rt_sigwaitinfo: depends on HAS_REALTIME buildsys: minor fixes in Makefile.arch for C6X buildsys: minor fixes in Makefile.arch for microblaze libubacktrace: enabled for all archs indeed. sparc: don't access fp registers when configured for no fpu libubacktrace: generic implementation based dwarf ... Conflicts: ldso/ldso/dl-elf.c ldso/ldso/mips/elfinterp.c ldso/ldso/x86_64/elfinterp.c Signed-off-by: Carmelo Amoroso <carmelo.amoroso@st.com>
Diffstat (limited to 'libc/inet/getaddrinfo.c')
-rw-r--r--libc/inet/getaddrinfo.c60
1 files changed, 32 insertions, 28 deletions
diff --git a/libc/inet/getaddrinfo.c b/libc/inet/getaddrinfo.c
index b3435a8b2..1a77c5199 100644
--- a/libc/inet/getaddrinfo.c
+++ b/libc/inet/getaddrinfo.c
@@ -395,9 +395,9 @@ gaih_inet(const char *name, const struct gaih_service *service,
{
struct gaih_servtuple nullserv;
- const struct gaih_typeproto *tp = gaih_inet_typeproto;
- struct gaih_servtuple *st = &nullserv;
- struct gaih_addrtuple *at = NULL;
+ const struct gaih_typeproto *tp;
+ struct gaih_servtuple *st;
+ struct gaih_addrtuple *at;
int rc;
int v4mapped = (req->ai_family == PF_UNSPEC || req->ai_family == PF_INET6)
&& (req->ai_flags & AI_V4MAPPED);
@@ -405,22 +405,24 @@ gaih_inet(const char *name, const struct gaih_service *service,
memset(&nullserv, 0, sizeof(nullserv));
+ tp = gaih_inet_typeproto;
if (req->ai_protocol || req->ai_socktype) {
++tp;
- while (tp->name[0]
- && ((req->ai_socktype != 0 && req->ai_socktype != tp->socktype)
- || (req->ai_protocol != 0 && !(tp->protoflag & GAI_PROTO_PROTOANY) && req->ai_protocol != tp->protocol)
- )
- ) {
+ while (tp->name[0]) {
+ if ((req->ai_socktype == 0 || req->ai_socktype == tp->socktype)
+ && (req->ai_protocol == 0 || req->ai_protocol == tp->protocol || (tp->protoflag & GAI_PROTO_PROTOANY))
+ ) {
+ goto found;
+ }
++tp;
}
- if (! tp->name[0]) {
- if (req->ai_socktype)
- return (GAIH_OKIFUNSPEC | -EAI_SOCKTYPE);
- return (GAIH_OKIFUNSPEC | -EAI_SERVICE);
- }
+ if (req->ai_socktype)
+ return (GAIH_OKIFUNSPEC | -EAI_SOCKTYPE);
+ return (GAIH_OKIFUNSPEC | -EAI_SERVICE);
+ found: ;
}
+ st = &nullserv;
if (service != NULL) {
if ((tp->protoflag & GAI_PROTO_NOSERVICE) != 0)
return (GAIH_OKIFUNSPEC | -EAI_SERVICE);
@@ -495,6 +497,7 @@ gaih_inet(const char *name, const struct gaih_service *service,
}
}
+ at = NULL;
if (name != NULL) {
at = alloca(sizeof(struct gaih_addrtuple));
at->family = AF_UNSPEC;
@@ -502,10 +505,9 @@ gaih_inet(const char *name, const struct gaih_service *service,
at->next = NULL;
if (inet_pton(AF_INET, name, at->addr) > 0) {
- if (req->ai_family == AF_UNSPEC || req->ai_family == AF_INET || v4mapped)
- at->family = AF_INET;
- else
+ if (req->ai_family != AF_UNSPEC && req->ai_family != AF_INET && !v4mapped)
return -EAI_FAMILY;
+ at->family = AF_INET;
}
#if defined __UCLIBC_HAS_IPV6__
@@ -518,11 +520,9 @@ gaih_inet(const char *name, const struct gaih_service *service,
*scope_delim = '\0';
if (inet_pton(AF_INET6, namebuf, at->addr) > 0) {
- if (req->ai_family == AF_UNSPEC || req->ai_family == AF_INET6)
- at->family = AF_INET6;
- else
+ if (req->ai_family != AF_UNSPEC && req->ai_family != AF_INET6)
return -EAI_FAMILY;
-
+ at->family = AF_INET6;
if (scope_delim != NULL) {
int try_numericscope = 0;
uint32_t *a32 = (uint32_t*)at->addr;
@@ -545,7 +545,7 @@ gaih_inet(const char *name, const struct gaih_service *service,
}
#endif
- if (at->family == AF_UNSPEC && (req->ai_flags & AI_NUMERICHOST) == 0) {
+ if (at->family == AF_UNSPEC && !(req->ai_flags & AI_NUMERICHOST)) {
struct hostent *h;
struct gaih_addrtuple **pat = &at;
int no_data = 0;
@@ -649,7 +649,7 @@ gaih_inet(const char *name, const struct gaih_service *service,
at2->family,
&th, tmpbuf, tmpbuflen,
&h, &herrno);
- } while (rc == errno && herrno == NETDB_INTERNAL);
+ } while (rc == ERANGE && herrno == NETDB_INTERNAL);
if (rc != 0 && herrno == NETDB_INTERNAL) {
__set_h_errno(herrno);
@@ -783,9 +783,9 @@ int
getaddrinfo(const char *name, const char *service,
const struct addrinfo *hints, struct addrinfo **pai)
{
- int i = 0, j, last_i = 0;
- struct addrinfo *p = NULL, **end;
- const struct gaih *g = gaih, *pg = NULL;
+ int i, j, last_i;
+ struct addrinfo *p, **end;
+ const struct gaih *g, *pg;
struct gaih_service gaih_service, *pservice;
struct addrinfo default_hints;
@@ -800,7 +800,7 @@ getaddrinfo(const char *name, const char *service,
if (hints == NULL) {
memset(&default_hints, 0, sizeof(default_hints));
- if (AF_UNSPEC)
+ if (AF_UNSPEC != 0)
default_hints.ai_family = AF_UNSPEC;
hints = &default_hints;
}
@@ -832,10 +832,14 @@ getaddrinfo(const char *name, const char *service,
} else
pservice = NULL;
+ g = gaih;
+ pg = NULL;
+ p = NULL;
end = NULL;
if (pai)
end = &p;
-
+ i = 0;
+ last_i = 0;
j = 0;
while (g->gaih) {
if (hints->ai_family == g->family || hints->ai_family == AF_UNSPEC) {
@@ -851,7 +855,7 @@ getaddrinfo(const char *name, const char *service,
last_i = i;
if (hints->ai_family == AF_UNSPEC && (i & GAIH_OKIFUNSPEC))
continue;
- if (p)
+ /*if (p) - freeaddrinfo works ok on NULL too */
freeaddrinfo(p);
return -(i & GAIH_EAI);
}