aboutsummaryrefslogtreecommitdiff
path: root/ping.c
diff options
context:
space:
mode:
Diffstat (limited to 'ping.c')
-rw-r--r--ping.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/ping.c b/ping.c
index 5cadac3e8..5b680195a 100644
--- a/ping.c
+++ b/ping.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: ping.c,v 1.8 2000/01/29 05:52:40 erik Exp $ 2 * $Id: ping.c,v 1.9 2000/01/29 06:29:32 erik Exp $
3 * Mini ping implementation for busybox 3 * Mini ping implementation for busybox
4 * 4 *
5 * Copyright (C) 1999 by Randolph Chung <tausq@debian.org> 5 * Copyright (C) 1999 by Randolph Chung <tausq@debian.org>
@@ -312,14 +312,17 @@ static void unpack(char *buf, int sz, struct sockaddr_in *from)
312 312
313static void ping(char *host) 313static void ping(char *host)
314{ 314{
315 struct protoent *proto=NULL; 315 struct protoent *proto;
316 struct hostent *h; 316 struct hostent *h;
317 char buf[MAXHOSTNAMELEN]; 317 char buf[MAXHOSTNAMELEN];
318 char packet[DEFDATALEN + MAXIPLEN + MAXICMPLEN]; 318 char packet[DEFDATALEN + MAXIPLEN + MAXICMPLEN];
319 int sockopt; 319 int sockopt;
320 320
321 proto = getprotobyname("icmp"); 321 proto = getprotobyname("icmp");
322 if ((pingsock = socket(AF_INET, SOCK_RAW, (proto)? proto->p_proto : 1 )) < 0) { /* 1 == ICMP */ 322 /* if getprotobyname failed, just silently force
323 * proto->p_proto to have the correct value for "icmp" */
324 if ((pingsock = socket(AF_INET, SOCK_RAW,
325 (proto ? proto->p_proto : 1))) < 0) { /* 1 == ICMP */
323 if (errno == EPERM) { 326 if (errno == EPERM) {
324 fprintf(stderr, "ping: permission denied. (are you root?)\n"); 327 fprintf(stderr, "ping: permission denied. (are you root?)\n");
325 } else { 328 } else {