svn commit: trunk/uClibc/libc/inet

ricardw at uclibc.org ricardw at uclibc.org
Tue Jul 1 12:54:50 UTC 2008


Author: ricardw
Date: 2008-07-01 05:54:49 -0700 (Tue, 01 Jul 2008)
New Revision: 22589

Log:
Simplified check_pf() so it returns a bit vector in an unsigned int,
instead of modifying the contents of two bools.

Removed:
   trunk/uClibc/libc/inet/check_pf.c

Modified:
   trunk/uClibc/libc/inet/Makefile.in
   trunk/uClibc/libc/inet/getaddrinfo.c
   trunk/uClibc/libc/inet/ifaddrs.h


Changeset:
Modified: trunk/uClibc/libc/inet/Makefile.in
===================================================================
--- trunk/uClibc/libc/inet/Makefile.in	2008-07-01 12:20:20 UTC (rev 22588)
+++ trunk/uClibc/libc/inet/Makefile.in	2008-07-01 12:54:49 UTC (rev 22589)
@@ -14,7 +14,7 @@
 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

Deleted: trunk/uClibc/libc/inet/check_pf.c
===================================================================
--- trunk/uClibc/libc/inet/check_pf.c	2008-07-01 12:20:20 UTC (rev 22588)
+++ trunk/uClibc/libc/inet/check_pf.c	2008-07-01 12:54:49 UTC (rev 22589)
@@ -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__ */
-}

Modified: trunk/uClibc/libc/inet/getaddrinfo.c
===================================================================
--- trunk/uClibc/libc/inet/getaddrinfo.c	2008-07-01 12:20:20 UTC (rev 22588)
+++ trunk/uClibc/libc/inet/getaddrinfo.c	2008-07-01 12:54:49 UTC (rev 22589)
@@ -1,6 +1,8 @@
 /*
  * Copyright 1996 by Craig Metz 
  * Copyright (C) 2000-2006 Erik Andersen <andersen at 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 @@
 { 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 @@
     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 @@
 
 #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 @@
 	    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 @@
 	    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
 		}

Modified: trunk/uClibc/libc/inet/ifaddrs.h
===================================================================
--- trunk/uClibc/libc/inet/ifaddrs.h	2008-07-01 12:20:20 UTC (rev 22588)
+++ trunk/uClibc/libc/inet/ifaddrs.h	2008-07-01 12:54:49 UTC (rev 22589)
@@ -73,17 +73,4 @@
 
 __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 */




More information about the uClibc-cvs mailing list