Fix kbuild bugs noticed by Bernhard Fischer <rep.nop@aon.at>
[oweals/busybox.git] / networking / interface.c
index 4f8e46de4f6133a2a5880a485dc78e8573827b7c..6c8e93879833cf236d74660cc17158a0a2dfddd9 100644 (file)
@@ -1,3 +1,4 @@
+/* vi: set sw=4 ts=4: */
 /*
  * stolen from net-tools-1.59 and stripped down for busybox by
  *                     Erik Andersen <andersen@codepoet.org>
  *                     (default AF was wrong)
  */
 
-/*
- *
- * Protocol Families.
- *
- */
-#define HAVE_AFINET 1
-
-/*
- *
- * Device Hardware types.
- *
- */
-#define HAVE_HWETHER   1
-#define HAVE_HWPPP     1
-
-
 #include "inet_common.h"
 #include <stdio.h>
 #include <errno.h>
@@ -126,37 +111,6 @@ struct aftype {
        char *flag_file;
 };
 
-#if HAVE_AFUNIX
-
-/* Display a UNIX domain address. */
-static char *UNIX_print(unsigned char *ptr)
-{
-       return (ptr);
-}
-
-
-/* Display a UNIX domain address. */
-static char *UNIX_sprint(struct sockaddr *sap, int numeric)
-{
-       static char buf[64];
-
-       if (sap->sa_family == 0xFFFF || sap->sa_family == 0)
-               return safe_strncpy(buf, "[NONE SET]", sizeof(buf));
-       return (UNIX_print(sap->sa_data));
-}
-
-
-static struct aftype unix_aftype = {
-       "unix", "UNIX Domain", AF_UNIX, 0,
-       UNIX_print, UNIX_sprint, NULL, NULL,
-       NULL, NULL, NULL,
-       -1,
-       "/proc/net/unix"
-};
-#endif                                                 /* HAVE_AFUNIX */
-
-#if HAVE_AFINET
-
 /* Display an Internet socket address. */
 static char *INET_sprint(struct sockaddr *sap, int numeric)
 {
@@ -173,17 +127,14 @@ static char *INET_sprint(struct sockaddr *sap, int numeric)
 }
 
 static struct aftype inet_aftype = {
-       "inet", "DARPA Internet", AF_INET, sizeof(unsigned long),
-       NULL /* UNUSED INET_print */ , INET_sprint,
-       NULL /* UNUSED INET_input */ , NULL /* UNUSED INET_reserror */ ,
-       NULL /*INET_rprint */ , NULL /*INET_rinput */ ,
-       NULL /* UNUSED INET_getnetmask */ ,
-       -1,
-       NULL
+       .name =         "inet",
+       .title =        "DARPA Internet",
+       .af =           AF_INET,
+       .alen =         4,
+       .sprint =       INET_sprint,
+       .fd =           -1
 };
 
-#endif                                                 /* HAVE_AFINET */
-
 #if HAVE_AFINET6
 
 /* Display an Internet socket address. */
@@ -201,13 +152,12 @@ static char *INET6_sprint(struct sockaddr *sap, int numeric)
 }
 
 static struct aftype inet6_aftype = {
-       "inet6", "IPv6", AF_INET6, sizeof(struct in6_addr),
-       NULL /* UNUSED INET6_print */ , INET6_sprint,
-       NULL /* UNUSED INET6_input */ , NULL /* UNUSED INET6_reserror */ ,
-       NULL /*INET6_rprint */ , NULL /*INET6_rinput */ ,
-       NULL /* UNUSED INET6_getnetmask */ ,
-       -1,
-       NULL
+       .name =         "inet6",
+       .title =        "IPv6",
+       .af =           AF_INET6,
+       .alen =         sizeof(struct in6_addr),
+       .sprint =       INET6_sprint,
+       .fd =           -1
 };
 
 #endif                                                 /* HAVE_AFINET6 */
@@ -247,12 +197,7 @@ static struct aftype unspec_aftype = {
 };
 
 static struct aftype * const aftypes[] = {
-#if HAVE_AFUNIX
-       &unix_aftype,
-#endif
-#if HAVE_AFINET
        &inet_aftype,
-#endif
 #if HAVE_AFINET6
        &inet6_aftype,
 #endif
@@ -380,7 +325,7 @@ static int sockets_open(int family)
                        sfd = af->fd;
        }
        if (sfd < 0) {
-               bb_error_msg("No usable address families found.");
+               bb_error_msg("no usable address families found");
        }
        return sfd;
 }
@@ -418,7 +363,7 @@ static int nstrcmp(const char *a, const char *b)
        }
 
        if (isdigit(*a) && isdigit(*b)) {
-               return atoi(a_ptr) > atoi(b_ptr) ? 1 : -1;
+               return xatoul(a_ptr) > xatoul(b_ptr) ? 1 : -1;
        }
        return *a - *b;
 }
@@ -500,22 +445,16 @@ static int if_readconf(void)
 
 static char *get_name(char *name, char *p)
 {
-       /* Extract <name>[:<alias>] from nul-terminated p where p matches
-          <name>[:<alias>]: after leading whitespace.
+       /* Extract <name> from nul-terminated p where p matches
+          <name>: after leading whitespace.
           If match is not made, set name empty and return unchanged p */
-       int namestart=0, nameend=0, aliasend;
+       int namestart=0, nameend=0;
        while (isspace(p[namestart]))
                namestart++;
        nameend=namestart;
        while (p[nameend] && p[nameend]!=':' && !isspace(p[nameend]))
                nameend++;
        if (p[nameend]==':') {
-               aliasend=nameend+1;
-               while (p[aliasend] && isdigit(p[aliasend]))
-                       aliasend++;
-               if (p[aliasend]==':') {
-                       nameend=aliasend;
-               }
                if ((nameend-namestart)<IFNAMSIZ) {
                        memcpy(name,&p[namestart],nameend-namestart);
                        name[nameend-namestart]='\0';
@@ -525,7 +464,7 @@ static char *get_name(char *name, char *p)
                        name[0]='\0';
                }
        } else {
-               /* first ':' not found - return empty */
+               /* trailing ':' not found - return empty */
                name[0]='\0';
        }
        return p + 1;
@@ -618,7 +557,7 @@ static int if_readlist_proc(char *target)
 
        fh = fopen(_PATH_PROCNET_DEV, "r");
        if (!fh) {
-               bb_perror_msg("Warning: cannot open %s. Limited output.", _PATH_PROCNET_DEV);
+               bb_perror_msg("warning: cannot open %s, limiting output", _PATH_PROCNET_DEV);
                return if_readconf();
        }
        fgets(buf, sizeof buf, fh);     /* eat line */
@@ -721,7 +660,6 @@ static int if_fetch(struct interface *ife)
        ife->tx_queue_len = -1; /* unknown value */
 #endif
 
-#if HAVE_AFINET
        /* IPv4 address? */
        fd = get_socket_for_af(AF_INET);
        if (fd >= 0) {
@@ -750,7 +688,6 @@ static int if_fetch(struct interface *ife)
                } else
                        memset(&ife->addr, 0, sizeof(struct sockaddr));
        }
-#endif
 
        return 0;
 }
@@ -787,16 +724,18 @@ struct hwtype {
 };
 
 static const struct hwtype unspec_hwtype = {
-       "unspec", "UNSPEC", -1, 0,
-       UNSPEC_print, NULL, NULL
+       .name =         "unspec",
+       .title =        "UNSPEC",
+       .type =         -1,
+       .print =        UNSPEC_print
 };
 
 static const struct hwtype loop_hwtype = {
-       "loop", "Local Loopback", ARPHRD_LOOPBACK, 0,
-       NULL, NULL, NULL
+       .name =         "loop",
+       .title =        "Local Loopback",
+       .type =         ARPHRD_LOOPBACK
 };
 
-#if HAVE_HWETHER
 #include <net/if_arp.h>
 
 #if (__GLIBC__ >=2 && __GLIBC_MINOR >= 1) || defined(_NEWLIB_VERSION)
@@ -818,43 +757,39 @@ static char *pr_ether(unsigned char *ptr)
 }
 
 static const struct hwtype ether_hwtype = {
-       "ether", "Ethernet", ARPHRD_ETHER, ETH_ALEN,
-       pr_ether, NULL /* UNUSED in_ether */ , NULL
+       .name =         "ether",
+       .title =        "Ethernet",
+       .type =         ARPHRD_ETHER,
+       .alen =         ETH_ALEN,
+       .print =        pr_ether
 };
 
-
-#endif                                                 /* HAVE_HWETHER */
-
-
-#if HAVE_HWPPP
-
 #include <net/if_arp.h>
 
 static const struct hwtype ppp_hwtype = {
-       "ppp", "Point-Point Protocol", ARPHRD_PPP, 0,
-       NULL, NULL, NULL /* UNUSED do_ppp */ , 0
+       .name =         "ppp",
+       .title =        "Point-to-Point Protocol",
+       .type =         ARPHRD_PPP
 };
 
-
-#endif                                                 /* HAVE_PPP */
+#ifdef CONFIG_FEATURE_IPV6
+static const struct hwtype sit_hwtype = {
+       .name =                 "sit",
+       .title =                "IPv6-in-IPv4",
+       .type =                 ARPHRD_SIT,
+       .print =                UNSPEC_print,
+       .suppress_null_addr =   1
+} ;
+#endif
 
 static const struct hwtype * const hwtypes[] = {
-
        &loop_hwtype,
-
-#if HAVE_HWSTRIP
-       &strip_hwtype,
-#endif
-#if HAVE_HWETHER
        &ether_hwtype,
-#endif
-#if HAVE_HWTUNNEL
-       &tunnel_hwtype,
-#endif
-#if HAVE_HWPPP
        &ppp_hwtype,
-#endif
        &unspec_hwtype,
+#ifdef CONFIG_FEATURE_IPV6
+       &sit_hwtype,
+#endif
        NULL
 };
 
@@ -1003,9 +938,8 @@ static void ife_print(struct interface *ptr)
                        printf("(auto)");
        }
 #endif
-       printf("\n");
+       puts("");
 
-#if HAVE_AFINET
        if (ptr->has_ip) {
                printf("          %s addr:%s ", ap->name,
                           ap->sprint(&ptr->addr, 1));
@@ -1017,7 +951,6 @@ static void ife_print(struct interface *ptr)
                }
                printf(" Mask:%s\n", ap->sprint(&ptr->netmask, 1));
        }
-#endif
 
 #if HAVE_AFINET6
 
@@ -1074,7 +1007,7 @@ static void ife_print(struct interface *ptr)
                                default:
                                        printf("Unknown");
                                }
-                               printf("\n");
+                               puts("");
                        }
                }
                fclose(f);
@@ -1101,7 +1034,7 @@ static void ife_print(struct interface *ptr)
        if (ptr->outfill || ptr->keepalive)
                printf("  Outfill:%d  Keepalive:%d", ptr->outfill, ptr->keepalive);
 #endif
-       printf("\n");
+       puts("");
 
        /* If needed, display the interface statistics. */
 
@@ -1150,9 +1083,9 @@ static void ife_print(struct interface *ptr)
                }
                if (ptr->map.dma)
                        printf("DMA chan:%x ", ptr->map.dma);
-               printf("\n");
+               puts("");
        }
-       printf("\n");
+       puts("");
 }