|
@@ -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;
|
|
@@ -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) {
|