/* Experimentally off - libc_hidden_proto(strchr) */
/* Experimentally off - libc_hidden_proto(strcpy) */
/* Experimentally off - libc_hidden_proto(strlen) */
-libc_hidden_proto(socket)
-libc_hidden_proto(close)
-libc_hidden_proto(getservbyname_r)
-libc_hidden_proto(gethostbyname2_r)
-libc_hidden_proto(gethostbyaddr_r)
-libc_hidden_proto(inet_pton)
-libc_hidden_proto(inet_ntop)
-libc_hidden_proto(strtoul)
-libc_hidden_proto(if_nametoindex)
-libc_hidden_proto(__h_errno_location)
+/* libc_hidden_proto(socket) */
+/* libc_hidden_proto(close) */
+/* libc_hidden_proto(getservbyname_r) */
+/* libc_hidden_proto(gethostbyname2_r) */
+/* libc_hidden_proto(gethostbyaddr_r) */
+/* libc_hidden_proto(inet_pton) */
+/* libc_hidden_proto(inet_ntop) */
+/* libc_hidden_proto(strtoul) */
+/* libc_hidden_proto(if_nametoindex) */
+/* libc_hidden_proto(__h_errno_location) */
/* libc_hidden_proto(uname) */
#ifdef __UCLIBC_HAS_IPV6__
-libc_hidden_proto(in6addr_loopback)
+/* libc_hidden_proto(in6addr_loopback) */
#endif
#define GAIH_OKIFUNSPEC 0x0100
static unsigned __check_pf(void)
{
unsigned seen = 0;
+
#if defined __UCLIBC_SUPPORT_AI_ADDRCONFIG__
- {
- /* Get the interface list via getifaddrs. */
- struct ifaddrs *ifa = NULL;
- struct ifaddrs *runp;
- if (getifaddrs(&ifa) != 0) {
- /* We cannot determine what interfaces are available.
- * Be optimistic. */
+
+ struct ifaddrs *ifa;
+ struct ifaddrs *runp;
+
+ /* Get the interface list via getifaddrs. */
+ if (getifaddrs(&ifa) != 0) {
+ /* We cannot determine what interfaces are available.
+ * Be optimistic. */
#if defined __UCLIBC_HAS_IPV4__
- seen |= SEEN_IPV4;
-#endif /* __UCLIBC_HAS_IPV4__ */
+ seen |= SEEN_IPV4;
+#endif
#if defined __UCLIBC_HAS_IPV6__
- seen |= SEEN_IPV6;
-#endif /* __UCLIBC_HAS_IPV6__ */
- return seen;
- }
+ seen |= SEEN_IPV6;
+#endif
+ return seen;
+ }
- for (runp = ifa; runp != NULL; runp = runp->ifa_next)
+ for (runp = ifa; runp != NULL; runp = runp->ifa_next) {
#if defined __UCLIBC_HAS_IPV4__
- if (runp->ifa_addr->sa_family == PF_INET)
- seen |= SEEN_IPV4;
-#endif /* __UCLIBC_HAS_IPV4__ */
-#if defined __UCLIBC_HAS_IPV4__ && defined __UCLIBC_HAS_IPV6__
- else /* can't be both at once */
-#endif /* __UCLIBC_HAS_IPV4__ && defined __UCLIBC_HAS_IPV6__ */
+ if (runp->ifa_addr->sa_family == PF_INET)
+ seen |= SEEN_IPV4;
+#endif
#if defined __UCLIBC_HAS_IPV6__
- if (runp->ifa_addr->sa_family == PF_INET6)
- seen |= SEEN_IPV6;
-#endif /* __UCLIBC_HAS_IPV6__ */
-
- freeifaddrs(ifa);
+ if (runp->ifa_addr->sa_family == PF_INET6)
+ seen |= SEEN_IPV6;
+#endif
}
+ freeifaddrs(ifa);
+
#else
+
/* AI_ADDRCONFIG is disabled, assume both ipv4 and ipv6 available. */
#if defined __UCLIBC_HAS_IPV4__
seen |= SEEN_IPV4;
-#endif /* __UCLIBC_HAS_IPV4__ */
+#endif
#if defined __UCLIBC_HAS_IPV6__
seen |= SEEN_IPV6;
-#endif /* __UCLIBC_HAS_IPV6__ */
+#endif
#endif /* __UCLIBC_SUPPORT_AI_ADDRCONFIG__ */
+
return seen;
}
/* Using Unix sockets this way is a security risk. */
static int
gaih_local(const char *name, const struct gaih_service *service,
- const struct addrinfo *req, struct addrinfo **pai)
+ const struct addrinfo *req, struct addrinfo **pai)
{
struct utsname utsname;
+ struct addrinfo *ai = *pai;
if ((name != NULL) && (req->ai_flags & AI_NUMERICHOST))
- return GAIH_OKIFUNSPEC | -EAI_NONAME;
+ return (GAIH_OKIFUNSPEC | -EAI_NONAME);
if ((name != NULL) || (req->ai_flags & AI_CANONNAME))
if (uname(&utsname) < 0)
strcmp(name, "unix") &&
strcmp(name, utsname.nodename))
return (GAIH_OKIFUNSPEC | -EAI_NONAME);
- }
+ }
- if (req->ai_protocol || req->ai_socktype) {
- const struct gaih_typeproto *tp = gaih_inet_typeproto + 1;
+ if (req->ai_protocol || req->ai_socktype) {
+ const struct gaih_typeproto *tp = gaih_inet_typeproto + 1;
- while (tp->name[0]
- && ((tp->protoflag & GAI_PROTO_NOSERVICE) != 0
- || (req->ai_socktype != 0 && req->ai_socktype != tp->socktype)
- || (req->ai_protocol != 0 && !(tp->protoflag & GAI_PROTO_PROTOANY) && req->ai_protocol != tp->protocol))
- ) {
- ++tp;
- }
- if (! tp->name[0]) {
- if (req->ai_socktype)
- return (GAIH_OKIFUNSPEC | -EAI_SOCKTYPE);
- return (GAIH_OKIFUNSPEC | -EAI_SERVICE);
- }
+ while (tp->name[0]
+ && ((tp->protoflag & GAI_PROTO_NOSERVICE) != 0
+ || (req->ai_socktype != 0 && req->ai_socktype != tp->socktype)
+ || (req->ai_protocol != 0 && !(tp->protoflag & GAI_PROTO_PROTOANY) && req->ai_protocol != tp->protocol))
+ ) {
+ ++tp;
}
+ if (! tp->name[0]) {
+ if (req->ai_socktype)
+ return (GAIH_OKIFUNSPEC | -EAI_SOCKTYPE);
+ return (GAIH_OKIFUNSPEC | -EAI_SERVICE);
+ }
+ }
- *pai = malloc(sizeof(struct addrinfo) + sizeof(struct sockaddr_un)
+ *pai = ai = malloc(sizeof(struct addrinfo) + sizeof(struct sockaddr_un)
+ ((req->ai_flags & AI_CANONNAME)
- ? (strlen(utsname.nodename) + 1): 0));
- if (*pai == NULL)
- return -EAI_MEMORY;
-
- (*pai)->ai_next = NULL;
- (*pai)->ai_flags = req->ai_flags;
- (*pai)->ai_family = AF_LOCAL;
- (*pai)->ai_socktype = req->ai_socktype ? req->ai_socktype : SOCK_STREAM;
- (*pai)->ai_protocol = req->ai_protocol;
- (*pai)->ai_addrlen = sizeof(struct sockaddr_un);
- (*pai)->ai_addr = (void *)(*pai) + sizeof(struct addrinfo);
-
+ ? (strlen(utsname.nodename) + 1) : 0));
+ if (ai == NULL)
+ return -EAI_MEMORY;
+
+ ai->ai_next = NULL;
+ ai->ai_flags = req->ai_flags;
+ ai->ai_family = AF_LOCAL;
+ ai->ai_socktype = req->ai_socktype ? req->ai_socktype : SOCK_STREAM;
+ ai->ai_protocol = req->ai_protocol;
+ ai->ai_addrlen = sizeof(struct sockaddr_un);
+ ai->ai_addr = (void *)ai + sizeof(struct addrinfo);
#if SALEN
- ((struct sockaddr_un *)(*pai)->ai_addr)->sun_len = sizeof(struct sockaddr_un);
+ ((struct sockaddr_un *)ai->ai_addr)->sun_len = sizeof(struct sockaddr_un);
#endif /* SALEN */
- ((struct sockaddr_un *)(*pai)->ai_addr)->sun_family = AF_LOCAL;
- memset(((struct sockaddr_un *)(*pai)->ai_addr)->sun_path, 0, UNIX_PATH_MAX);
-
- if (service) {
- struct sockaddr_un *sunp = (struct sockaddr_un *)(*pai)->ai_addr;
+ ((struct sockaddr_un *)ai->ai_addr)->sun_family = AF_LOCAL;
+ memset(((struct sockaddr_un *)ai->ai_addr)->sun_path, 0, UNIX_PATH_MAX);
- if (strchr(service->name, '/') != NULL) {
- if (strlen(service->name) >= sizeof(sunp->sun_path))
- return GAIH_OKIFUNSPEC | -EAI_SERVICE;
+ if (service) {
+ struct sockaddr_un *sunp = (struct sockaddr_un *)ai->ai_addr;
+ if (strchr(service->name, '/') != NULL) {
+ if (strlen(service->name) >= sizeof(sunp->sun_path))
+ return GAIH_OKIFUNSPEC | -EAI_SERVICE;
strcpy(sunp->sun_path, service->name);
} else {
if (strlen(P_tmpdir "/") + 1 + strlen(service->name) >= sizeof(sunp->sun_path))
window between the test for the file and the actual creation
(done by the caller) in which a file with the same name could
be created. */
- char *buf = ((struct sockaddr_un *)(*pai)->ai_addr)->sun_path;
+ char *buf = ((struct sockaddr_un *)ai->ai_addr)->sun_path;
if (__path_search(buf, L_tmpnam, NULL, NULL, 0) != 0
|| __gen_tempname(buf, __GT_NOCREATE) != 0
}
}
+ ai->ai_canonname = NULL;
if (req->ai_flags & AI_CANONNAME)
- (*pai)->ai_canonname = strcpy((char *) *pai + sizeof(struct addrinfo) + sizeof(struct sockaddr_un),
+ ai->ai_canonname = strcpy((char *)(ai + 1) + sizeof(struct sockaddr_un),
utsname.nodename);
- else
- (*pai)->ai_canonname = NULL;
return 0;
}
#endif /* 0 */
{ PF_UNSPEC, NULL }
};
-libc_hidden_proto(freeaddrinfo)
+/* libc_hidden_proto(freeaddrinfo) */
void
freeaddrinfo(struct addrinfo *ai)
{
}
libc_hidden_def(freeaddrinfo)
-libc_hidden_proto(getaddrinfo)
+/* libc_hidden_proto(getaddrinfo) */
int
getaddrinfo(const char *name, const char *service,
const struct addrinfo *hints, struct addrinfo **pai)
{
- int i = 0, j = 0, last_i = 0;
+ int i = 0, j, last_i = 0;
struct addrinfo *p = NULL, **end;
const struct gaih *g = gaih, *pg = NULL;
struct gaih_service gaih_service, *pservice;
} else
pservice = NULL;
+ end = NULL;
if (pai)
end = &p;
- else
- end = NULL;
+ j = 0;
while (g->gaih) {
if (hints->ai_family == g->family || hints->ai_family == AF_UNSPEC) {
if ((hints->ai_flags & AI_ADDRCONFIG) && !addrconfig(g->family)) {
if (pai == NULL && last_i == 0)
return 0;
- if (p)
- freeaddrinfo(p);
+ /* if (p) - never happens, see above */
+ /* freeaddrinfo(p); */
return last_i ? -(last_i & GAIH_EAI) : EAI_NONAME;
}