Hello,

I ran into a case where a call like "arping -D -c 2 -I eth0 10.0.0.64" would 
freeze forever. It is caused by a blocking recfrom call at the end of the code. 
Turns out this was already fixed in the original iputils code. The following 
patch is just a port from iputils which can be found here: 
https://github.com/iputils/iputils/blob/master/arping.c
It also fixes another problem that can occur when the Ethernet connection is 
down.

I successfully tested the code change with busybox 1.24.1. It should also work 
with the current version since this part of the code has not changed since 
then. The following patch is for the current version.

Regards,
Michael

--- a/networking/arping.c            2018-02-09 11:50:56.551059773 +0100
+++ b/networking/arping.c         2018-02-09 11:54:37.494598160 +0100
@@ -423,16 +423,25 @@
                               struct sockaddr_ll from;
                               socklen_t alen = sizeof(from);
                               int cc;
+
+                             sigemptyset(&sset);
+                             sigaddset(&sset, SIGALRM);
+                             sigaddset(&sset, SIGINT);
+                             /* Unblock SIGALRM so that the previously called 
alarm()
+                             * can prevent recvfrom from blocking forever in 
case the
+                             * inherited procmask is blocking SIGALRM and no 
packet
+                             * is received. */
+                             sigprocmask(SIG_UNBLOCK, &sset, &osset);
                                cc = recvfrom(sock_fd, packet, 4096, 0, (struct 
sockaddr *) &from, &alen);
                               if (cc < 0) {
                                               bb_perror_msg("recvfrom");
+                                             if (errno == ENETDOWN)
+                                                             exit(2);
                                               continue;
                               }
-                              sigemptyset(&sset);
-                              sigaddset(&sset, SIGALRM);
-                              sigaddset(&sset, SIGINT);
-                              sigprocmask(SIG_BLOCK, &sset, &osset);
+
+                             sigprocmask(SIG_BLOCK, &sset, NULL);
                               recv_pack(packet, cc, &from);
                               sigprocmask(SIG_SETMASK, &osset, NULL);
               }
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to