diff options
Diffstat (limited to 'libc')
| -rw-r--r-- | libc/inet/Makefile.in | 2 | ||||
| -rw-r--r-- | libc/inet/check_pf.c | 74 | ||||
| -rw-r--r-- | libc/inet/getaddrinfo.c | 92 | ||||
| -rw-r--r-- | libc/inet/ifaddrs.h | 13 | 
4 files changed, 75 insertions, 106 deletions
| diff --git a/libc/inet/Makefile.in b/libc/inet/Makefile.in index e87287a4a..493041ff6 100644 --- a/libc/inet/Makefile.in +++ b/libc/inet/Makefile.in @@ -14,7 +14,7 @@ CSRC :=  ifneq ($(UCLIBC_HAS_IPV4)$(UCLIBC_HAS_IPV6),)  CSRC +=	getservice.c getproto.c hostid.c getnetent.c getnetbynm.c getnetbyad.c \  	inet_net.c herror.c if_index.c gai_strerror.c getaddrinfo.c \ -	ether_addr.c ntohl.c ifaddrs.c ntop.c check_pf.c +	ether_addr.c ntohl.c ifaddrs.c ntop.c  endif  ifeq ($(UCLIBC_HAS_IPV6),y)  CSRC += in6_addr.c diff --git a/libc/inet/check_pf.c b/libc/inet/check_pf.c deleted file mode 100644 index 9eed516b7..000000000 --- a/libc/inet/check_pf.c +++ /dev/null @@ -1,74 +0,0 @@ -/* Determine protocol families for which interfaces exist.  Generic version. -   Copyright (C) 2003, 2006 Free Software Foundation, Inc. -   This file is part of the GNU C Library. - -   The GNU C Library is free software; you can redistribute it and/or -   modify it under the terms of the GNU Lesser General Public -   License as published by the Free Software Foundation; either -   version 2.1 of the License, or (at your option) any later version. - -   The GNU C Library is distributed in the hope that it will be useful, -   but WITHOUT ANY WARRANTY; without even the implied warranty of -   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU -   Lesser General Public License for more details. - -   You should have received a copy of the GNU Lesser General Public -   License along with the GNU C Library; if not, write to the Free -   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -   02111-1307 USA.  */ - -#include <features.h> -#include "ifaddrs.h" -#include <netdb.h> - - -void -attribute_hidden -__check_pf (bool *seen_ipv4, bool *seen_ipv6) -{ -  *seen_ipv4 = false; -  *seen_ipv6 = false; -#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.  */ -#if defined __UCLIBC_HAS_IPV4__ -      *seen_ipv4 = true; -#endif /* __UCLIBC_HAS_IPV4__ */ -#if defined __UCLIBC_HAS_IPV6__ -      *seen_ipv6 = true; -#endif /* __UCLIBC_HAS_IPV6__ */ -      return; -    } - -    for (runp = ifa; runp != NULL; runp = runp->ifa_next) -#if defined __UCLIBC_HAS_IPV4__ -      if (runp->ifa_addr->sa_family == PF_INET) -        *seen_ipv4 = true; -#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 defined __UCLIBC_HAS_IPV6__ -      if (runp->ifa_addr->sa_family == PF_INET6) -        *seen_ipv6 = true; -#endif /* __UCLIBC_HAS_IPV6__ */ - -    (void) freeifaddrs (ifa); -  } -#else -  /* AI_ADDRCONFIG is disabled, assume both ipv4 and ipv6 available. */ -#if defined __UCLIBC_HAS_IPV4__ -  *seen_ipv4 = true; -#endif /* __UCLIBC_HAS_IPV4__ */ -#if defined __UCLIBC_HAS_IPV6__ -  *seen_ipv6 = true; -#endif /* __UCLIBC_HAS_IPV6__ */ - -#endif /* __UCLIBC_SUPPORT_AI_ADDRCONFIG__ */ -} diff --git a/libc/inet/getaddrinfo.c b/libc/inet/getaddrinfo.c index 8b735f29b..8baa6815e 100644 --- a/libc/inet/getaddrinfo.c +++ b/libc/inet/getaddrinfo.c @@ -1,6 +1,8 @@  /*   * Copyright 1996 by Craig Metz    * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org> + * Portions from the GNU C library, + * Copyright (C) 2003, 2006 Free Software Foundation, Inc.   *   * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.   */ @@ -157,29 +159,85 @@ static const struct addrinfo default_hints =  { 0, PF_UNSPEC, 0, 0, 0, NULL, NULL, NULL };  #endif +#define SEEN_IPV4 1 +#define SEEN_IPV6 2 + +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.  */ +#if defined __UCLIBC_HAS_IPV4__ +      seen |= SEEN_IPV4; +#endif /* __UCLIBC_HAS_IPV4__ */ +#if defined __UCLIBC_HAS_IPV6__ +      seen |= SEEN_IPV6; +#endif /* __UCLIBC_HAS_IPV6__ */ +      return seen; +    } + +    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 defined __UCLIBC_HAS_IPV6__ +      if (runp->ifa_addr->sa_family == PF_INET6) +        seen |= SEEN_IPV6; +#endif /* __UCLIBC_HAS_IPV6__ */ + +    (void) 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__ */ +#if defined __UCLIBC_HAS_IPV6__ +  seen |= SEEN_IPV6; +#endif /* __UCLIBC_HAS_IPV6__ */ + +#endif /* __UCLIBC_SUPPORT_AI_ADDRCONFIG__ */ +  return seen; +} +  static int addrconfig (sa_family_t af)  {      int s;      int ret;      int saved_errno = errno; -    bool seen_ipv4; -    bool seen_ipv6; +    unsigned seen; -    __check_pf(&seen_ipv4, &seen_ipv6); +    seen = __check_pf(); +#if defined __UCLIBC_HAS_IPV4__      if (af == AF_INET) -	ret = (int)seen_ipv4; -    else if (af == AF_INET6) -	ret = (int)seen_ipv6; +	ret = seen & SEEN_IPV4; +    else +#endif +#if defined __UCLIBC_HAS_IPV6__ +    if (af == AF_INET6) +	ret = seen & SEEN_IPV6;      else +#endif      {  	s = socket(af, SOCK_DGRAM, 0); -	if (s < 0) -	    ret = (errno == EMFILE) ? 1 : 0; +	ret = 1; /* Assume PF_UNIX. */ +	if (s < 0) { +	    if (errno != EMFILE) +	        ret = 0; +	}  	else -	{  	    close(s); -	    ret = 1; -	}      }      __set_errno (saved_errno);      return ret; @@ -384,9 +442,7 @@ gaih_inet (const char *name, const struct gaih_service *service,      int rc;      int v4mapped = (req->ai_family == PF_UNSPEC || req->ai_family == PF_INET6) &&  	(req->ai_flags & AI_V4MAPPED); -    bool seen_ipv4; -    bool seen_ipv6; -    __check_pf(&seen_ipv4, &seen_ipv6); +    unsigned seen = __check_pf();      if (req->ai_protocol || req->ai_socktype)      { @@ -574,7 +630,7 @@ gaih_inet (const char *name, const struct gaih_service *service,  #if defined __UCLIBC_HAS_IPV6__  	    if (req->ai_family == AF_UNSPEC || req->ai_family == AF_INET6) -		if (!(req->ai_flags & AI_ADDRCONFIG) || seen_ipv6) +		if (!(req->ai_flags & AI_ADDRCONFIG) || (seen & SEEN_IPV6))  		    gethosts (AF_INET6, struct in6_addr);  #endif  	    no_inet6_data = no_data; @@ -582,7 +638,7 @@ gaih_inet (const char *name, const struct gaih_service *service,  	    if (req->ai_family == AF_INET ||  		(!v4mapped && req->ai_family == AF_UNSPEC) ||  		(v4mapped && (no_inet6_data != 0 || (req->ai_flags & AI_ALL)))) -		if (!(req->ai_flags & AI_ADDRCONFIG) || seen_ipv4) +		if (!(req->ai_flags & AI_ADDRCONFIG) || (seen & SEEN_IPV4))  		    gethosts (AF_INET, struct in_addr);  	    if (no_data != 0 && no_inet6_data != 0) @@ -715,10 +771,10 @@ gaih_inet (const char *name, const struct gaih_service *service,  	    for (st2 = st; st2 != NULL; st2 = st2->next)  	    {  		if (req->ai_flags & AI_ADDRCONFIG) { -		    if (family == AF_INET && !seen_ipv4) +		    if (family == AF_INET && !(seen & SEEN_IPV4))  			break;  #if defined __UCLIBC_HAS_IPV6__ -		    else if (family == AF_INET6 && !seen_ipv6) +		    else if (family == AF_INET6 && !(seen & SEEN_IPV6))  			break;  #endif  		} diff --git a/libc/inet/ifaddrs.h b/libc/inet/ifaddrs.h index 2cc06ec86..f65bcaba3 100644 --- a/libc/inet/ifaddrs.h +++ b/libc/inet/ifaddrs.h @@ -73,17 +73,4 @@ extern void freeifaddrs (struct ifaddrs *__ifa)  __THROW;  __END_DECLS -struct in6addrinfo -{ -  enum { -    in6ai_deprecated = 1, -    in6ai_temporary = 2, -    in6ai_homeaddress = 4 -  } flags; -  uint32_t addr[4]; -}; - -extern void __check_pf (bool *seen_ipv4, bool *seen_ipv6) -  attribute_hidden; -  #endif /* ifaddrs.h */ | 
