aboutsummaryrefslogtreecommitdiff
path: root/networking
diff options
context:
space:
mode:
Diffstat (limited to 'networking')
-rw-r--r--networking/hostname.c13
-rw-r--r--networking/ping.c30
2 files changed, 16 insertions, 27 deletions
diff --git a/networking/hostname.c b/networking/hostname.c
index 13e52c41d..c64d1602b 100644
--- a/networking/hostname.c
+++ b/networking/hostname.c
@@ -1,6 +1,6 @@
1/* vi: set sw=4 ts=4: */ 1/* vi: set sw=4 ts=4: */
2/* 2/*
3 * $Id: hostname.c,v 1.16 2000/12/07 19:56:48 markw Exp $ 3 * $Id: hostname.c,v 1.17 2000/12/22 01:48:07 kraai Exp $
4 * Mini hostname implementation for busybox 4 * Mini hostname 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>
@@ -40,10 +40,9 @@ void do_sethostname(char *s, int isfile)
40 if (!isfile) { 40 if (!isfile) {
41 if (sethostname(s, strlen(s)) < 0) { 41 if (sethostname(s, strlen(s)) < 0) {
42 if (errno == EPERM) 42 if (errno == EPERM)
43 error_msg("you must be root to change the hostname\n"); 43 error_msg_and_die("you must be root to change the hostname\n");
44 else 44 else
45 perror("sethostname"); 45 perror_msg_and_die("sethostname");
46 exit(1);
47 } 46 }
48 } else { 47 } else {
49 f = xfopen(s, "r"); 48 f = xfopen(s, "r");
@@ -51,10 +50,8 @@ void do_sethostname(char *s, int isfile)
51 fclose(f); 50 fclose(f);
52 if (buf[strlen(buf) - 1] == '\n') 51 if (buf[strlen(buf) - 1] == '\n')
53 buf[strlen(buf) - 1] = 0; 52 buf[strlen(buf) - 1] = 0;
54 if (sethostname(buf, strlen(buf)) < 0) { 53 if (sethostname(buf, strlen(buf)) < 0)
55 perror("sethostname"); 54 perror_msg_and_die("sethostname");
56 exit(1);
57 }
58 } 55 }
59} 56}
60 57
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);