svn commit: trunk/uClibc: extra/Configs include libc/inet

Bernhard Fischer rep.dot.nop at gmail.com
Fri Jun 27 11:43:37 UTC 2008


On Fri, Jun 27, 2008 at 02:08:45AM -0700, ricardw at uclibc.org wrote:
>Author: ricardw
>Date: 2008-06-27 02:08:44 -0700 (Fri, 27 Jun 2008)
>New Revision: 22531
>
>Log:
>Added support for the AI_ADDRCONFIG flag in the hints->ai_flags parameter to getaddrinfo(3).

>Added: trunk/uClibc/include/ifaddrs.h
>===================================================================
>--- trunk/uClibc/include/ifaddrs.h	                        (rev 0)
>+++ trunk/uClibc/include/ifaddrs.h	2008-06-27 09:08:44 UTC (rev 22531)
>@@ -0,0 +1,19 @@
>+#ifndef _IFADDRS_H
>+#include <libc/inet/ifaddrs.h>

I'm not convinced that the above will work well.

>+#include <stdbool.h>
>+#include <stdint.h>
>+
>+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)

Perhaps just use unsigned*seen as param.

>+  attribute_hidden;
>+
>+#endif	/* ifaddrs.h */
>
>Modified: trunk/uClibc/libc/inet/Makefile.in
>===================================================================
>--- trunk/uClibc/libc/inet/Makefile.in	2008-06-27 04:30:48 UTC (rev 22530)
>+++ trunk/uClibc/libc/inet/Makefile.in	2008-06-27 09:08:44 UTC (rev 22531)
>@@ -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
>+	ether_addr.c ntohl.c ifaddrs.c ntop.c check_pf.c
> endif
> ifeq ($(UCLIBC_HAS_IPV6),y)
> CSRC += in6_addr.c
>
>Added: trunk/uClibc/libc/inet/check_pf.c
>===================================================================
>--- trunk/uClibc/libc/inet/check_pf.c	                        (rev 0)
>+++ trunk/uClibc/libc/inet/check_pf.c	2008-06-27 09:08:44 UTC (rev 22531)
>@@ -0,0 +1,65 @@
>+/* 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 __UCLIBC_SUPPORT_AI_ADDRCONFIG__

Turn it off and build with -Wundef, then fix it, please.

>+  {
>+    /* 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.  */
>+      *seen_ipv4 = true;

No. Doesn't take __UCLIBC_HAS_IPV4__ into account.

>+#if __UCLIBC_HAS_IPV6__

-Wundef

> static int addrconfig (sa_family_t af)
> {
>     int s;
>     int ret;
>     int saved_errno = errno;
>-    s = socket(af, SOCK_DGRAM, 0);
>-    if (s < 0)
>-	ret = (errno == EMFILE) ? 1 : 0;
>+    bool seen_ipv4;
>+    bool seen_ipv6;

yea, no. one variable and mask them. Or, even better
unsigned __check_pf(void)
>+
>+    __check_pf(&seen_ipv4, &seen_ipv6);
>+    if (af == AF_INET)
>+	ret = (int)seen_ipv4;
>+    else if (af == AF_INET6)
>+	ret = (int)seen_ipv6;
>     else
>     {
>-	close(s);
>-	ret = 1;
>+	s = socket(af, SOCK_DGRAM, 0);
>+	if (s < 0)
>+	    ret = (errno == EMFILE) ? 1 : 0;
>+	else
>+	{
>+	    close(s);
>+	    ret = 1;
>+	}

Why don't you just ret=1 and adjust ret later on accordingly?

Please look which one is smaller in this spot.

And please do not introduce warnings about using undefined preprocessor
tokens and also keep in mind that we ultimately want a libc that can be
configured as IPv6-only. Thanks.



More information about the uClibc mailing list