ping: revert "try SOCK_DGRAM if no root privileges"
authorDenys Vlasenko <vda.linux@googlemail.com>
Thu, 9 Jan 2014 10:53:26 +0000 (11:53 +0100)
committerDenys Vlasenko <vda.linux@googlemail.com>
Thu, 9 Jan 2014 10:53:26 +0000 (11:53 +0100)
It wasn't working, and fixes on top of it would make ping
noticeably larger.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
networking/ping.c

index 5d71fe8cc5ab0efaf6a720e90740f47a4543318e..5e4771f5a03f762e2d0ebf1526aa50ba92d93de6 100644 (file)
@@ -168,22 +168,9 @@ create_icmp_socket(void)
 #endif
                sock = socket(AF_INET, SOCK_RAW, 1); /* 1 == ICMP */
        if (sock < 0) {
-               if (errno != EPERM)
-                       bb_perror_msg_and_die(bb_msg_can_not_create_raw_socket);
-#if defined(__linux__) || defined(__APPLE__)
-               /* We don't have root privileges.  Try SOCK_DGRAM instead.
-                * Linux needs net.ipv4.ping_group_range for this to work.
-                * MacOSX allows ICMP_ECHO, ICMP_TSTAMP or ICMP_MASKREQ
-                */
-#if ENABLE_PING6
-               if (lsa->u.sa.sa_family == AF_INET6)
-                       sock = socket(AF_INET6, SOCK_DGRAM, IPPROTO_ICMPV6);
-               else
-#endif
-                       sock = socket(AF_INET, SOCK_DGRAM, 1); /* 1 == ICMP */
-               if (sock < 0)
-#endif
-               bb_error_msg_and_die(bb_msg_perm_denied_are_you_root);
+               if (errno == EPERM)
+                       bb_error_msg_and_die(bb_msg_perm_denied_are_you_root);
+               bb_perror_msg_and_die(bb_msg_can_not_create_raw_socket);
        }
 
        xmove_fd(sock, pingsock);