From owner-freebsd-bugs@FreeBSD.ORG Sun May 23 22:07:08 2010 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id DF8C51065672 for ; Sun, 23 May 2010 22:07:08 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (unknown [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id A3EF58FC13 for ; Sun, 23 May 2010 22:07:08 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.4/8.14.4) with ESMTP id o4NM78hr017275 for ; Sun, 23 May 2010 22:07:08 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.4/8.14.4/Submit) id o4NM78hR017274; Sun, 23 May 2010 22:07:08 GMT (envelope-from gnats) Resent-Date: Sun, 23 May 2010 22:07:08 GMT Resent-Message-Id: <201005232207.o4NM78hR017274@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Haven Hash Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 4FED21065674 for ; Sun, 23 May 2010 20:54:59 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21]) by mx1.freebsd.org (Postfix) with ESMTP id 3EA748FC08 for ; Sun, 23 May 2010 20:54:59 +0000 (UTC) Received: from www.freebsd.org (localhost [127.0.0.1]) by www.freebsd.org (8.14.3/8.14.3) with ESMTP id o4NKswBp026277 for ; Sun, 23 May 2010 20:54:58 GMT (envelope-from nobody@www.freebsd.org) Received: (from nobody@localhost) by www.freebsd.org (8.14.3/8.14.3/Submit) id o4NKswIp026275; Sun, 23 May 2010 20:54:58 GMT (envelope-from nobody) Message-Id: <201005232054.o4NKswIp026275@www.freebsd.org> Date: Sun, 23 May 2010 20:54:58 GMT From: Haven Hash To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Cc: Subject: misc/146889: Not having NET_RT_IFLIST #defined causes getifaddrs.c (libc) to fail to build X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 23 May 2010 22:07:09 -0000 >Number: 146889 >Category: misc >Synopsis: Not having NET_RT_IFLIST #defined causes getifaddrs.c (libc) to fail to build >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Sun May 23 22:07:08 UTC 2010 >Closed-Date: >Last-Modified: >Originator: Haven Hash >Release: 8.0 Release >Organization: >Environment: FreeBSD hashbsd 8.0-RELEASE FreeBSD 8.0-RELEASE #0: Sat Nov 21 15:48:17 UTC 2009 root@almeida.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC i386 >Description: Very minor issue that is most likely completely ignorable, but since I had a patch that seems to work I figured I'd put it here in case anyone else ever hit this. The getifaddrs() libc call does its magic by default by using the NET_RT_IFLIST sysctl call, however it also looks to attempt to support another method using the SIOCGIFCONF ioctl call. It prefers the sysctl method unless the NET_RT_IFLIST #define is not defined. I had reason to want to use the SIOCGIFCONF ioctl method so I undefined NET_RT_IFLIST in lib/libc/net/getifaddrs.c (right after the first #ifdef check) however this causes the getifaddrs.c file to fail to build. The build errors are slight issues concerning variables only being declared inside the NET_RT_IFLIST ifdef blocks and the need for one additional header file (unistd.h) in the #else code. This looks to have always been the case (non-NET_RT_IFLIST code fails to build) and maybe the right thing to do is to just remove all of the non-NET_RT_IFLIST code? (given that is does not build it is unlikely anyone uses it). >How-To-Repeat: Edit lib/libc/net/getifaddrs.c and add the following: #undef NET_RT_IFLIST in between current lines 40 and 41 (immediately after the first #ifdef NET_RT_IFLIST) to simulate building getifaddrs.c without this define. Try to rebuild libc and you will see build errors in getifaddrs.c because some variables are only declared inside #ifdef NET_RT_IFLIST specific code, but are used outside of #ifdef NET_RT_IFLIST code. >Fix: Attached patch works for me. It puts the declaration of the ifa and ift variables into non-#ifdef NET_RT_IFLIST code, removes the variable m since it is not used, moves the declaration of the len and alen variables into #ifdef NET_RT_IFLIST specific code since that is the only code they are used in and adds the unistd.h include because #else code makes use of a _close() call that prevented it from building without this header. To reiterate this is only helpful for the very rare case that someone would like getifaddrs() to not use the NET_RT_IFLIST sysctl method to obtain interface addresses from the kernel, since the getifaddrs() code looks to support two methods this seems like something it is attempting to support, however the second method currently fails to build. The NET_RT_IFLIST sysctl method is definitely preferred (i.e. for instance the ioctl alternative will not get you netmasks as the ifreq struct it gets back from the kernel does not contain a netmask field). Patch attached with submission follows: Index: lib/libc/net/getifaddrs.c =================================================================== --- lib/libc/net/getifaddrs.c (revision 208457) +++ lib/libc/net/getifaddrs.c (working copy) @@ -44,6 +44,7 @@ #include #endif +#include #include #include #include @@ -97,6 +98,7 @@ int ntry = 0; int mib[6]; size_t needed; + size_t len, alen; char *buf; char *next; struct ifaddrs *cif = 0; @@ -106,19 +108,18 @@ struct ifa_msghdr *ifam; struct sockaddr_dl *dl; struct sockaddr *sa; - struct ifaddrs *ifa, *ift; u_short idx = 0; #else /* NET_RT_IFLIST */ char buf[1024]; - int m, sock; + int sock; struct ifconf ifc; struct ifreq *ifr; struct ifreq *lifr; #endif /* NET_RT_IFLIST */ int i; - size_t len, alen; char *data; char *names; + struct ifaddrs *ifa, *ift; #ifdef NET_RT_IFLIST mib[0] = CTL_NET; >Release-Note: >Audit-Trail: >Unformatted: