last_patch95 from vodz:
[oweals/busybox.git] / networking / arping.c
index af44f9267dbf2098b656c731c7049dc91cb187d3..2e1adf0a2cf217212d49c199c1138627aaa8b796 100644 (file)
@@ -302,9 +302,9 @@ int arping_main(int argc, char **argv)
                        break;
                case 'I':
                        if (optarg == NULL)
-                               show_usage();
-                       if (xstrlen(optarg) > IF_NAMESIZE) {
-                               error_msg("Interface name `%s' must be less than %d", optarg,
+                               bb_show_usage();
+                       if (bb_strlen(optarg) > IF_NAMESIZE) {
+                               bb_error_msg("Interface name `%s' must be less than %d", optarg,
                                                  IF_NAMESIZE);
                                exit(2);
                        }
@@ -319,61 +319,61 @@ int arping_main(int argc, char **argv)
                case 'h':
                case '?':
                default:
-                       show_usage();
+                       bb_show_usage();
                }
        }
        argc -= optind;
        argv += optind;
 
        if (argc != 1)
-               show_usage();
+               bb_show_usage();
 
        target = *argv;
 
 
        if (s < 0) {
-               error_msg("socket");
+               bb_error_msg("socket");
                exit(socket_errno);
        }
 
-       if (1) {
+       {
                struct ifreq ifr;
 
                memset(&ifr, 0, sizeof(ifr));
                strncpy(ifr.ifr_name, device, IFNAMSIZ - 1);
                if (ioctl(s, SIOCGIFINDEX, &ifr) < 0) {
-                       error_msg("Interface %s not found", device);
+                       bb_error_msg("Interface %s not found", device);
                        exit(2);
                }
                ifindex = ifr.ifr_ifindex;
 
                if (ioctl(s, SIOCGIFFLAGS, (char *) &ifr)) {
-                       error_msg("SIOCGIFFLAGS");
+                       bb_error_msg("SIOCGIFFLAGS");
                        exit(2);
                }
                if (!(ifr.ifr_flags & IFF_UP)) {
-                       error_msg("Interface %s is down", device);
+                       bb_error_msg("Interface %s is down", device);
                        exit(2);
                }
                if (ifr.ifr_flags & (IFF_NOARP | IFF_LOOPBACK)) {
-                       error_msg("Interface %s is not ARPable", device);
+                       bb_error_msg("Interface %s is not ARPable", device);
                        exit(dad ? 0 : 2);
                }
        }
 
-       if (inet_aton(target, &dst) != 1) {
+       if (!inet_aton(target, &dst)) {
                struct hostent *hp;
 
                hp = gethostbyname2(target, AF_INET);
                if (!hp) {
-                       error_msg("invalid or unknown target %s", target);
+                       bb_error_msg("invalid or unknown target %s", target);
                        exit(2);
                }
                memcpy(&dst, hp->h_addr, 4);
        }
 
-       if (source && inet_aton(source, &src) != 1) {
-               error_msg("invalid source address %s", source);
+       if (source && !inet_aton(source, &src)) {
+               bb_error_msg("invalid source address %s", source);
                exit(2);
        }
 
@@ -385,21 +385,21 @@ int arping_main(int argc, char **argv)
                int probe_fd = socket(AF_INET, SOCK_DGRAM, 0);
 
                if (probe_fd < 0) {
-                       error_msg("socket");
+                       bb_error_msg("socket");
                        exit(2);
                }
                if (device) {
                        if (setsockopt
                                (probe_fd, SOL_SOCKET, SO_BINDTODEVICE, device,
                                 strlen(device) + 1) == -1)
-                               error_msg("WARNING: interface %s is ignored", device);
+                               bb_error_msg("WARNING: interface %s is ignored", device);
                }
                memset(&saddr, 0, sizeof(saddr));
                saddr.sin_family = AF_INET;
                if (src.s_addr) {
                        saddr.sin_addr = src;
                        if (bind(probe_fd, (struct sockaddr *) &saddr, sizeof(saddr)) == -1) {
-                               error_msg("bind");
+                               bb_error_msg("bind");
                                exit(2);
                        }
                } else if (!dad) {
@@ -415,12 +415,12 @@ int arping_main(int argc, char **argv)
                                perror("WARNING: setsockopt(SO_DONTROUTE)");
                        if (connect(probe_fd, (struct sockaddr *) &saddr, sizeof(saddr))
                                == -1) {
-                               error_msg("connect");
+                               bb_error_msg("connect");
                                exit(2);
                        }
                        if (getsockname(probe_fd, (struct sockaddr *) &saddr, &alen) ==
                                -1) {
-                               error_msg("getsockname");
+                               bb_error_msg("getsockname");
                                exit(2);
                        }
                        src = saddr.sin_addr;
@@ -432,31 +432,33 @@ int arping_main(int argc, char **argv)
        me.sll_ifindex = ifindex;
        me.sll_protocol = htons(ETH_P_ARP);
        if (bind(s, (struct sockaddr *) &me, sizeof(me)) == -1) {
-               error_msg("bind");
+               bb_error_msg("bind");
                exit(2);
        }
 
-       if (1) {
+       {
                int alen = sizeof(me);
 
                if (getsockname(s, (struct sockaddr *) &me, &alen) == -1) {
-                       error_msg("getsockname");
+                       bb_error_msg("getsockname");
                        exit(2);
                }
        }
        if (me.sll_halen == 0) {
-               error_msg("Interface \"%s\" is not ARPable (no ll address)", device);
+               bb_error_msg("Interface \"%s\" is not ARPable (no ll address)", device);
                exit(dad ? 0 : 2);
        }
        he = me;
        memset(he.sll_addr, -1, he.sll_halen);
 
-       if (!quiet)
-               printf("ARPING to %s from %s via %s\n", inet_ntoa(dst),
-                          inet_ntoa(src), device ? device : "unknown");
+       if (!quiet) {
+               printf("ARPING to %s", inet_ntoa(dst));
+               printf(" from %s via %s\n", inet_ntoa(src),
+                          device ? device : "unknown");
+       }
 
        if (!src.s_addr && !dad) {
-               error_msg("no src address in the non-DAD mode");
+               bb_error_msg("no src address in the non-DAD mode");
                exit(2);
        }