Fix kbuild bugs noticed by Bernhard Fischer <rep.nop@aon.at>
[oweals/busybox.git] / networking / interface.c
index dc097fa593576b72b54a40607ab9a59682d2e858..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>
@@ -126,13 +127,12 @@ 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
 };
 
 #if HAVE_AFINET6
@@ -152,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 */
@@ -326,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;
 }
@@ -364,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;
 }
@@ -446,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';
@@ -471,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;
@@ -564,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 */
@@ -731,13 +724,16 @@ 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
 };
 
 #include <net/if_arp.h>
@@ -761,22 +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
 };
 
 #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
 };
 
+#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,
        &ether_hwtype,
        &ppp_hwtype,
        &unspec_hwtype,
+#ifdef CONFIG_FEATURE_IPV6
+       &sit_hwtype,
+#endif
        NULL
 };
 
@@ -925,7 +938,7 @@ static void ife_print(struct interface *ptr)
                        printf("(auto)");
        }
 #endif
-       printf("\n");
+       puts("");
 
        if (ptr->has_ip) {
                printf("          %s addr:%s ", ap->name,
@@ -994,7 +1007,7 @@ static void ife_print(struct interface *ptr)
                                default:
                                        printf("Unknown");
                                }
-                               printf("\n");
+                               puts("");
                        }
                }
                fclose(f);
@@ -1021,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. */
 
@@ -1070,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("");
 }