Fixes so "make allnoconfig" works again.
[oweals/busybox.git] / libbb / interface.c
index 4632e2930b0473e9e83c2c697f4cfba194d395e4..65d7c4e7147fcd7830004f711b2d2ba0588d20c1 100644 (file)
@@ -15,7 +15,7 @@
  *              that either displays or sets the characteristics of
  *              one or more of the system's networking interfaces.
  *
- * Version:     $Id: interface.c,v 1.24 2004/08/12 16:52:00 andersen Exp $
+ * Version:     $Id: interface.c,v 1.25 2004/08/26 21:45:21 andersen Exp $
  *
  * Author:      Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
  *              and others.  Copyright 1993 MicroWalt Corporation
@@ -888,6 +888,20 @@ static int sockets_open(int family)
        return sfd;
 }
 
+#ifdef CONFIG_FEATURE_CLEAN_UP
+static void sockets_close(void)
+{
+       struct aftype **aft;
+       for (aft = aftypes; *aft != NULL; aft++) {
+               struct aftype *af = *aft;
+               if( af->fd != -1 ) {
+                       close(af->fd);
+                       af->fd = -1;
+               }
+       }
+}
+#endif
+
 /* like strcmp(), but knows about numbers */
 static int nstrcmp(const char *a, const char *b)
 {
@@ -986,7 +1000,7 @@ static int if_readconf(void)
        return err;
 }
 
-char *get_name(char *name, char *p)
+static char *get_name(char *name, char *p)
 {
        /* Extract <name>[:<alias>] from nul-terminated p where p matches
           <name>[:<alias>]: after leading whitespace.
@@ -1016,7 +1030,7 @@ char *get_name(char *name, char *p)
                /* first ':' not found - return empty */
                name[0]='\0';
        }
-       return p;
+       return p + 1;
 }
 
 /* If scanf supports size qualifiers for %n conversions, then we can
@@ -1223,17 +1237,13 @@ static int if_fetch(struct interface *ife)
        }
 #endif
 
+#ifdef SIOCGIFMAP
        strcpy(ifr.ifr_name, ifname);
-       if (ioctl(skfd, SIOCGIFMAP, &ifr) < 0)
-               memset(&ife->map, 0, sizeof(struct ifmap));
+       if (ioctl(skfd, SIOCGIFMAP, &ifr) == 0)
+               ife->map = ifr.ifr_map;
        else
-               memcpy(&ife->map, &ifr.ifr_map, sizeof(struct ifmap));
-
-       strcpy(ifr.ifr_name, ifname);
-       if (ioctl(skfd, SIOCGIFMAP, &ifr) < 0)
+#endif
                memset(&ife->map, 0, sizeof(struct ifmap));
-       else
-               ife->map = ifr.ifr_map;
 
 #ifdef HAVE_TXQUEUELEN
        strcpy(ifr.ifr_name, ifname);
@@ -1374,7 +1384,7 @@ static struct hwtype loop_hwtype = {
 #if HAVE_HWETHER
 #include <net/if_arp.h>
 
-#if __GLIBC__ >=2 && __GLIBC_MINOR >= 1
+#if (__GLIBC__ >=2 && __GLIBC_MINOR >= 1) || defined(_NEWLIB_VERSION)
 #include <net/ethernet.h>
 #else
 #include <linux/if_ether.h>
@@ -2078,6 +2088,8 @@ int display_interfaces(char *ifname)
 
        /* Do we have to show the current setup? */
        status = if_print(ifname);
-       close(skfd);
+#ifdef CONFIG_FEATURE_CLEAN_UP
+       sockets_close();
+#endif
        exit(status < 0);
 }