diff options
| author | Matt Kraai <kraai@debian.org> | 2001-07-13 20:56:27 +0000 |
|---|---|---|
| committer | Matt Kraai <kraai@debian.org> | 2001-07-13 20:56:27 +0000 |
| commit | 06ef16563b6914735d5018a1d92fbe992f84d7fd (patch) | |
| tree | 4855b5ca1b496f8d369f55201a1c3eb1ac5aaaa0 | |
| parent | ccd65c9be667d504f67e8a92bb6ab41253374ab9 (diff) | |
| download | busybox-w32-06ef16563b6914735d5018a1d92fbe992f84d7fd.tar.gz busybox-w32-06ef16563b6914735d5018a1d92fbe992f84d7fd.tar.bz2 busybox-w32-06ef16563b6914735d5018a1d92fbe992f84d7fd.zip | |
Allow featureless ping to compile, and featureful ping to shrink
(by Adam Slattery).
| -rw-r--r-- | networking/ping.c | 19 | ||||
| -rw-r--r-- | ping.c | 19 |
2 files changed, 6 insertions, 32 deletions
diff --git a/networking/ping.c b/networking/ping.c index 205133d8c..620a29dc9 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.44 2001/07/12 20:26:31 andersen Exp $ | 3 | * $Id: ping.c,v 1.45 2001/07/13 20:56:27 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> |
| @@ -191,7 +191,7 @@ static void ping(const char *host) | |||
| 191 | int pingsock, c; | 191 | int pingsock, c; |
| 192 | char packet[DEFDATALEN + MAXIPLEN + MAXICMPLEN]; | 192 | char packet[DEFDATALEN + MAXIPLEN + MAXICMPLEN]; |
| 193 | 193 | ||
| 194 | pingsock = create_raw_socket(); | 194 | pingsock = create_icmp_socket(); |
| 195 | 195 | ||
| 196 | memset(&pingaddr, 0, sizeof(struct sockaddr_in)); | 196 | memset(&pingaddr, 0, sizeof(struct sockaddr_in)); |
| 197 | 197 | ||
| @@ -416,25 +416,12 @@ static void unpack(char *buf, int sz, struct sockaddr_in *from) | |||
| 416 | 416 | ||
| 417 | static void ping(const char *host) | 417 | static void ping(const char *host) |
| 418 | { | 418 | { |
| 419 | struct protoent *proto; | ||
| 420 | struct hostent *h; | 419 | struct hostent *h; |
| 421 | char buf[MAXHOSTNAMELEN]; | 420 | char buf[MAXHOSTNAMELEN]; |
| 422 | char packet[datalen + MAXIPLEN + MAXICMPLEN]; | 421 | char packet[datalen + MAXIPLEN + MAXICMPLEN]; |
| 423 | int sockopt; | 422 | int sockopt; |
| 424 | 423 | ||
| 425 | proto = getprotobyname("icmp"); | 424 | pingsock = create_icmp_socket(); |
| 426 | /* if getprotobyname failed, just silently force | ||
| 427 | * proto->p_proto to have the correct value for "icmp" */ | ||
| 428 | if ((pingsock = socket(AF_INET, SOCK_RAW, | ||
| 429 | (proto ? proto->p_proto : 1))) < 0) { /* 1 == ICMP */ | ||
| 430 | if (errno == EPERM) | ||
| 431 | error_msg_and_die("permission denied. (are you root?)"); | ||
| 432 | else | ||
| 433 | perror_msg_and_die(can_not_create_raw_socket); | ||
| 434 | } | ||
| 435 | |||
| 436 | /* drop root privs if running setuid */ | ||
| 437 | setuid(getuid()); | ||
| 438 | 425 | ||
| 439 | memset(&pingaddr, 0, sizeof(struct sockaddr_in)); | 426 | memset(&pingaddr, 0, sizeof(struct sockaddr_in)); |
| 440 | 427 | ||
| @@ -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.44 2001/07/12 20:26:31 andersen Exp $ | 3 | * $Id: ping.c,v 1.45 2001/07/13 20:56:27 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> |
| @@ -191,7 +191,7 @@ static void ping(const char *host) | |||
| 191 | int pingsock, c; | 191 | int pingsock, c; |
| 192 | char packet[DEFDATALEN + MAXIPLEN + MAXICMPLEN]; | 192 | char packet[DEFDATALEN + MAXIPLEN + MAXICMPLEN]; |
| 193 | 193 | ||
| 194 | pingsock = create_raw_socket(); | 194 | pingsock = create_icmp_socket(); |
| 195 | 195 | ||
| 196 | memset(&pingaddr, 0, sizeof(struct sockaddr_in)); | 196 | memset(&pingaddr, 0, sizeof(struct sockaddr_in)); |
| 197 | 197 | ||
| @@ -416,25 +416,12 @@ static void unpack(char *buf, int sz, struct sockaddr_in *from) | |||
| 416 | 416 | ||
| 417 | static void ping(const char *host) | 417 | static void ping(const char *host) |
| 418 | { | 418 | { |
| 419 | struct protoent *proto; | ||
| 420 | struct hostent *h; | 419 | struct hostent *h; |
| 421 | char buf[MAXHOSTNAMELEN]; | 420 | char buf[MAXHOSTNAMELEN]; |
| 422 | char packet[datalen + MAXIPLEN + MAXICMPLEN]; | 421 | char packet[datalen + MAXIPLEN + MAXICMPLEN]; |
| 423 | int sockopt; | 422 | int sockopt; |
| 424 | 423 | ||
| 425 | proto = getprotobyname("icmp"); | 424 | pingsock = create_icmp_socket(); |
| 426 | /* if getprotobyname failed, just silently force | ||
| 427 | * proto->p_proto to have the correct value for "icmp" */ | ||
| 428 | if ((pingsock = socket(AF_INET, SOCK_RAW, | ||
| 429 | (proto ? proto->p_proto : 1))) < 0) { /* 1 == ICMP */ | ||
| 430 | if (errno == EPERM) | ||
| 431 | error_msg_and_die("permission denied. (are you root?)"); | ||
| 432 | else | ||
| 433 | perror_msg_and_die(can_not_create_raw_socket); | ||
| 434 | } | ||
| 435 | |||
| 436 | /* drop root privs if running setuid */ | ||
| 437 | setuid(getuid()); | ||
| 438 | 425 | ||
| 439 | memset(&pingaddr, 0, sizeof(struct sockaddr_in)); | 426 | memset(&pingaddr, 0, sizeof(struct sockaddr_in)); |
| 440 | 427 | ||
