fix numbering in switch(): we don't have "del" anymore,
[oweals/busybox.git] / networking / libiproute / iptunnel.c
index 2b9d3055ecc7830b77ade2308e9e948d98e7b5b7..a67803ff43ca73e067ee8fa06d3b529992f2f496 100644 (file)
@@ -42,7 +42,7 @@ static int do_ioctl_get_ifindex(char *dev)
        struct ifreq ifr;
        int fd;
 
-       strcpy(ifr.ifr_name, dev);
+       strncpy(ifr.ifr_name, dev, sizeof(ifr.ifr_name));
        fd = xsocket(AF_INET, SOCK_DGRAM, 0);
        if (ioctl(fd, SIOCGIFINDEX, &ifr)) {
                bb_perror_msg("ioctl");
@@ -57,7 +57,7 @@ static int do_ioctl_get_iftype(char *dev)
        struct ifreq ifr;
        int fd;
 
-       strcpy(ifr.ifr_name, dev);
+       strncpy(ifr.ifr_name, dev, sizeof(ifr.ifr_name));
        fd = xsocket(AF_INET, SOCK_DGRAM, 0);
        if (ioctl(fd, SIOCGIFHWADDR, &ifr)) {
                bb_perror_msg("ioctl");
@@ -91,7 +91,7 @@ static int do_get_ioctl(char *basedev, struct ip_tunnel_parm *p)
        int fd;
        int err;
 
-       strcpy(ifr.ifr_name, basedev);
+       strncpy(ifr.ifr_name, basedev, sizeof(ifr.ifr_name));
        ifr.ifr_ifru.ifru_data = (void*)p;
        fd = xsocket(AF_INET, SOCK_DGRAM, 0);
        err = ioctl(fd, SIOCGETTUNNEL, &ifr);
@@ -109,9 +109,9 @@ static int do_add_ioctl(int cmd, char *basedev, struct ip_tunnel_parm *p)
        int err;
 
        if (cmd == SIOCCHGTUNNEL && p->name[0]) {
-               strcpy(ifr.ifr_name, p->name);
+               strncpy(ifr.ifr_name, p->name, sizeof(ifr.ifr_name));
        } else {
-               strcpy(ifr.ifr_name, basedev);
+               strncpy(ifr.ifr_name, basedev, sizeof(ifr.ifr_name));
        }
        ifr.ifr_ifru.ifru_data = (void*)p;
        fd = xsocket(AF_INET, SOCK_DGRAM, 0);
@@ -130,9 +130,9 @@ static int do_del_ioctl(char *basedev, struct ip_tunnel_parm *p)
        int err;
 
        if (p->name[0]) {
-               strcpy(ifr.ifr_name, p->name);
+               strncpy(ifr.ifr_name, p->name, sizeof(ifr.ifr_name));
        } else {
-               strcpy(ifr.ifr_name, basedev);
+               strncpy(ifr.ifr_name, basedev, sizeof(ifr.ifr_name));
        }
        ifr.ifr_ifru.ifru_data = (void*)p;
        fd = xsocket(AF_INET, SOCK_DGRAM, 0);
@@ -267,7 +267,7 @@ static int parse_args(int argc, char **argv, int cmd, struct ip_tunnel_parm *p)
                        }
                } else if (strcmp(*argv, "tos") == 0 ||
                           matches(*argv, "dsfield") == 0) {
-                       __u32 uval;
+                       uint32_t uval;
                        NEXT_ARG();
                        if (strcmp(*argv, "inherit") != 0) {
                                if (rtnl_dsfield_a2n(&uval, *argv))
@@ -409,46 +409,46 @@ static void print_tunnel(struct ip_tunnel_parm *p)
        if (p->iph.tos) {
                SPRINT_BUF(b1);
                printf(" tos");
-               if (p->iph.tos&1)
+               if (p->iph.tos & 1)
                        printf(" inherit");
-               if (p->iph.tos&~1)
-                       printf("%c%s ", p->iph.tos&1 ? '/' : ' ',
-                              rtnl_dsfield_n2a(p->iph.tos&~1, b1, sizeof(b1)));
+               if (p->iph.tos & ~1)
+                       printf("%c%s ", p->iph.tos & 1 ? '/' : ' ',
+                              rtnl_dsfield_n2a(p->iph.tos & ~1, b1, sizeof(b1)));
        }
-       if (!(p->iph.frag_off&htons(IP_DF)))
+       if (!(p->iph.frag_off & htons(IP_DF)))
                printf(" nopmtudisc");
 
-       if ((p->i_flags&GRE_KEY) && (p->o_flags&GRE_KEY) && p->o_key == p->i_key)
+       if ((p->i_flags & GRE_KEY) && (p->o_flags & GRE_KEY) && p->o_key == p->i_key)
                printf(" key %s", s3);
-       else if ((p->i_flags|p->o_flags)&GRE_KEY) {
-               if (p->i_flags&GRE_KEY)
+       else if ((p->i_flags | p->o_flags) & GRE_KEY) {
+               if (p->i_flags & GRE_KEY)
                        printf(" ikey %s ", s3);
-               if (p->o_flags&GRE_KEY)
+               if (p->o_flags & GRE_KEY)
                        printf(" okey %s ", s4);
        }
 
-       if (p->i_flags&GRE_SEQ)
+       if (p->i_flags & GRE_SEQ)
                printf("%s  Drop packets out of sequence.\n", _SL_);
-       if (p->i_flags&GRE_CSUM)
+       if (p->i_flags & GRE_CSUM)
                printf("%s  Checksum in received packet is required.", _SL_);
-       if (p->o_flags&GRE_SEQ)
+       if (p->o_flags & GRE_SEQ)
                printf("%s  Sequence packets on output.", _SL_);
-       if (p->o_flags&GRE_CSUM)
+       if (p->o_flags & GRE_CSUM)
                printf("%s  Checksum output packets.", _SL_);
 }
 
 static int do_tunnels_list(struct ip_tunnel_parm *p)
 {
        char name[IFNAMSIZ];
-       unsigned long  rx_bytes, rx_packets, rx_errs, rx_drops,
-       rx_fifo, rx_frame,
-       tx_bytes, tx_packets, tx_errs, tx_drops,
-       tx_fifo, tx_colls, tx_carrier, rx_multi;
+       unsigned long rx_bytes, rx_packets, rx_errs, rx_drops,
+               rx_fifo, rx_frame,
+               tx_bytes, tx_packets, tx_errs, tx_drops,
+               tx_fifo, tx_colls, tx_carrier, rx_multi;
        int type;
        struct ip_tunnel_parm p1;
-
        char buf[512];
        FILE *fp = fopen("/proc/net/dev", "r");
+
        if (fp == NULL) {
                perror("fopen");
                return -1;
@@ -459,8 +459,10 @@ static int do_tunnels_list(struct ip_tunnel_parm *p)
 
        while (fgets(buf, sizeof(buf), fp) != NULL) {
                char *ptr;
-               buf[sizeof(buf) - 1] = 0;
-               if ((ptr = strchr(buf, ':')) == NULL ||
+
+               /*buf[sizeof(buf) - 1] = 0; - fgets is safe anyway */
+               ptr = strchr(buf, ':');
+               if (ptr == NULL ||
                    (*ptr++ = 0, sscanf(buf, "%s", name) != 1)) {
                        bb_error_msg("wrong format of /proc/net/dev. Sorry");
                        return -1;
@@ -541,6 +543,5 @@ int do_iptunnel(int argc, char **argv)
        } else
                return do_show(0, NULL);
 
-       bb_error_msg("command \"%s\" is unknown", *argv);
-       exit(-1);
+       bb_error_msg_and_die("command \"%s\" is unknown", *argv);
 }