aboutsummaryrefslogtreecommitdiff
path: root/ping.c
diff options
context:
space:
mode:
Diffstat (limited to 'ping.c')
-rw-r--r--ping.c30
1 files changed, 11 insertions, 19 deletions
diff --git a/ping.c b/ping.c
index 4be2120c8..e9242e9b7 100644
--- a/ping.c
+++ b/ping.c
@@ -1,6 +1,6 @@
1/* vi: set sw=4 ts=4: */ 1/* vi: set sw=4 ts=4: */
2/* 2/*
3 * $Id: ping.c,v 1.29 2000/12/18 03:57:16 kraai Exp $ 3 * $Id: ping.c,v 1.30 2000/12/22 01:48:07 kraai Exp $
4 * Mini ping implementation for busybox 4 * Mini ping implementation for busybox
5 * 5 *
6 * Copyright (C) 1999 by Randolph Chung <tausq@debian.org> 6 * Copyright (C) 1999 by Randolph Chung <tausq@debian.org>
@@ -190,10 +190,8 @@ static void ping(const char *host)
190 int pingsock, c; 190 int pingsock, c;
191 char packet[DEFDATALEN + MAXIPLEN + MAXICMPLEN]; 191 char packet[DEFDATALEN + MAXIPLEN + MAXICMPLEN];
192 192
193 if ((pingsock = socket(AF_INET, SOCK_RAW, 1)) < 0) { /* 1 == ICMP */ 193 if ((pingsock = socket(AF_INET, SOCK_RAW, 1)) < 0) /* 1 == ICMP */
194 perror("ping: creating a raw socket"); 194 perror_msg_and_die("creating a raw socket");
195 exit(1);
196 }
197 195
198 /* drop root privs if running setuid */ 196 /* drop root privs if running setuid */
199 setuid(getuid()); 197 setuid(getuid());
@@ -216,12 +214,8 @@ static void ping(const char *host)
216 c = sendto(pingsock, packet, sizeof(packet), 0, 214 c = sendto(pingsock, packet, sizeof(packet), 0,
217 (struct sockaddr *) &pingaddr, sizeof(struct sockaddr_in)); 215 (struct sockaddr *) &pingaddr, sizeof(struct sockaddr_in));
218 216
219 if (c < 0 || c != sizeof(packet)) { 217 if (c < 0 || c != sizeof(packet))
220 if (c < 0) 218 perror_msg_and_die("sendto");
221 perror("ping: sendto");
222 error_msg("write incomplete\n");
223 exit(1);
224 }
225 219
226 signal(SIGALRM, noresp); 220 signal(SIGALRM, noresp);
227 alarm(5); /* give the host 5000ms to respond */ 221 alarm(5); /* give the host 5000ms to respond */
@@ -234,7 +228,7 @@ static void ping(const char *host)
234 (struct sockaddr *) &from, &fromlen)) < 0) { 228 (struct sockaddr *) &from, &fromlen)) < 0) {
235 if (errno == EINTR) 229 if (errno == EINTR)
236 continue; 230 continue;
237 perror("ping: recvfrom"); 231 perror_msg("recvfrom");
238 continue; 232 continue;
239 } 233 }
240 if (c >= 76) { /* ip + icmp */ 234 if (c >= 76) { /* ip + icmp */
@@ -439,12 +433,10 @@ static void ping(const char *host)
439 * proto->p_proto to have the correct value for "icmp" */ 433 * proto->p_proto to have the correct value for "icmp" */
440 if ((pingsock = socket(AF_INET, SOCK_RAW, 434 if ((pingsock = socket(AF_INET, SOCK_RAW,
441 (proto ? proto->p_proto : 1))) < 0) { /* 1 == ICMP */ 435 (proto ? proto->p_proto : 1))) < 0) { /* 1 == ICMP */
442 if (errno == EPERM) { 436 if (errno == EPERM)
443 error_msg("permission denied. (are you root?)\n"); 437 error_msg_and_die("permission denied. (are you root?)\n");
444 } else { 438 else
445 perror("ping: creating a raw socket"); 439 perror_msg_and_die("creating a raw socket");
446 }
447 exit(1);
448 } 440 }
449 441
450 /* drop root privs if running setuid */ 442 /* drop root privs if running setuid */
@@ -498,7 +490,7 @@ static void ping(const char *host)
498 (struct sockaddr *) &from, &fromlen)) < 0) { 490 (struct sockaddr *) &from, &fromlen)) < 0) {
499 if (errno == EINTR) 491 if (errno == EINTR)
500 continue; 492 continue;
501 perror("ping: recvfrom"); 493 perror_msg("recvfrom");
502 continue; 494 continue;
503 } 495 }
504 unpack(packet, c, &from); 496 unpack(packet, c, &from);