httpd: trivial simplification
[oweals/busybox.git] / networking / zcip.c
index de4ee0b1a8a13f180ce688e9fbb0dd2b19c6ed6f..62350c640d7872ce3cab58d5013d9ece1d707635 100644 (file)
@@ -160,7 +160,8 @@ int zcip_main(int argc, char **argv);
 int zcip_main(int argc, char **argv)
 {
        int state = PROBE;
-       struct ether_addr eth_addr;
+       /* Prevent unaligned traps for ARM (see srand() below) */
+       struct ether_addr eth_addr __attribute__(( aligned(sizeof(unsigned)) ));
        const char *why;
        int fd;
        char *r_opt;
@@ -198,14 +199,12 @@ int zcip_main(int argc, char **argv)
 
        memset(&L, 0, sizeof(L));
 
-       srand(MONOTONIC_US());
-
 #define FOREGROUND (opts & 1)
 #define QUIT       (opts & 2)
        // parse commandline: prog [options] ifname script
        // exactly 2 args; -v accumulates and implies -f
        opt_complementary = "=2:vv:vf";
-       opts = getopt32(argc, argv, "fqr:v", &r_opt, &verbose);
+       opts = getopt32(argv, "fqr:v", &r_opt, &verbose);
        if (!FOREGROUND) {
                /* Do it early, before all bb_xx_msg calls */
                openlog(applet_name, 0, LOG_DAEMON);
@@ -247,17 +246,14 @@ int zcip_main(int argc, char **argv)
        // get the interface's ethernet address
        //memset(&ifr, 0, sizeof(ifr));
        strncpy(ifr.ifr_name, intf, sizeof(ifr.ifr_name));
-       if (ioctl(fd, SIOCGIFHWADDR, &ifr) < 0) {
-               bb_perror_msg_and_die("get ethernet address");
-       }
+       xioctl(fd, SIOCGIFHWADDR, &ifr);
        memcpy(&eth_addr, &ifr.ifr_hwaddr.sa_data, ETH_ALEN);
 
        // start with some stable ip address, either a function of
        // the hardware address or else the last address we used.
        // NOTE: the sequence of addresses we try changes only
        // depending on when we detect conflicts.
-       // (SVID 3 bogon: who says that "short" is always 16 bits?)
-       seed48( (unsigned short*)&ifr.ifr_hwaddr.sa_data );
+       srand(*(unsigned*)&eth_addr);
        if (ip.s_addr == 0)
                pick(&ip);
 
@@ -305,7 +301,12 @@ int zcip_main(int argc, char **argv)
 
                VDBG("...wait %d %s nprobes=%u, nclaims=%u\n",
                                timeout_ms, intf, nprobes, nclaims);
-               switch (poll(fds, 1, timeout_ms)) {
+
+               switch (safe_poll(fds, 1, timeout_ms)) {
+
+               default:
+                       /*bb_perror_msg("poll"); - done in safe_poll */
+                       return EXIT_FAILURE;
 
                // timeout
                case 0:
@@ -393,6 +394,7 @@ int zcip_main(int argc, char **argv)
                                break;
                        } // switch (state)
                        break; // case 0 (timeout)
+
                // packets arriving
                case 1:
                        // We need to adjust the timeout in case we didn't receive
@@ -524,13 +526,9 @@ int zcip_main(int argc, char **argv)
                                nclaims = 0;
                                break;
                        } // switch state
-
                        break; // case 1 (packets arriving)
-               default:
-                       why = "poll";
-                       goto bad;
                } // switch poll
-       }
+       } // while (1)
  bad:
        bb_perror_msg("%s, %s", intf, why);
        return EXIT_FAILURE;