aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Borca <dborca@yahoo.com>2013-11-28 12:50:25 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2013-11-28 12:50:25 +0100
commit72745632a13ccd12232127b31e1656f2f7ebcaff (patch)
tree2548a6297208698dbab4c4a3db3e16961c2cf800
parentdf0d2cd837e564e2653ce9a8b92a32d4eaf6e9c3 (diff)
downloadbusybox-72745632a13ccd12232127b31e1656f2f7ebcaff.tar.gz
ping: try SOCK_DGRAM if no root privileges
Signed-off-by: Daniel Borca <dborca@yahoo.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--networking/ping.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/networking/ping.c b/networking/ping.c
index 5e4771f5a..5d71fe8cc 100644
--- a/networking/ping.c
+++ b/networking/ping.c
@@ -168,9 +168,22 @@ create_icmp_socket(void)
#endif
sock = socket(AF_INET, SOCK_RAW, 1); /* 1 == ICMP */
if (sock < 0) {
- 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);
+ 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);
}
xmove_fd(sock, pingsock);