summaryrefslogtreecommitdiff
path: root/networking/ping.c
diff options
context:
space:
mode:
authorMatt Kraai <kraai@debian.org>2000-12-22 01:48:07 +0000
committerMatt Kraai <kraai@debian.org>2000-12-22 01:48:07 +0000
commita9819b290848e0a760f3805d5937fa050235d707 (patch)
treeb8cb8d939032c0806d62161b01e5836cb808dc3f /networking/ping.c
parente9f07fb6e83b75a50760599a5d31f494841eddf7 (diff)
downloadbusybox-w32-a9819b290848e0a760f3805d5937fa050235d707.tar.gz
busybox-w32-a9819b290848e0a760f3805d5937fa050235d707.tar.bz2
busybox-w32-a9819b290848e0a760f3805d5937fa050235d707.zip
Use busybox error handling functions wherever possible.
Diffstat (limited to 'networking/ping.c')
-rw-r--r--networking/ping.c30
1 files changed, 11 insertions, 19 deletions
diff --git a/networking/ping.c b/networking/ping.c
index 4be2120c8..e9242e9b7 100644
--- a/networking/ping.c
+++ b/networking/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);