aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>1999-12-11 08:41:28 +0000
committerEric Andersen <andersen@codepoet.org>1999-12-11 08:41:28 +0000
commit19db07b3d4ca4c333f9a53bfbc113b44f3c55750 (patch)
tree6c916e01a70d0d351778cffbee53a2d7e3d2f3b5
parent59248bad97413798ac0cfdc5fcc75c7635a7ab1c (diff)
downloadbusybox-w32-19db07b3d4ca4c333f9a53bfbc113b44f3c55750.tar.gz
busybox-w32-19db07b3d4ca4c333f9a53bfbc113b44f3c55750.tar.bz2
busybox-w32-19db07b3d4ca4c333f9a53bfbc113b44f3c55750.zip
Ok, so this is reallt 0.38...
-Erik
-rw-r--r--Changelog4
-rw-r--r--applets/busybox.c3
-rw-r--r--busybox.c3
-rw-r--r--busybox.def.h3
-rw-r--r--coreutils/mkfifo.c61
-rw-r--r--internal.h3
-rw-r--r--mkfifo.c61
-rw-r--r--networking/ping.c164
-rw-r--r--ping.c164
9 files changed, 381 insertions, 85 deletions
diff --git a/Changelog b/Changelog
index b5bbddcf0..6db788d4d 100644
--- a/Changelog
+++ b/Changelog
@@ -1,6 +1,6 @@
10.39 10.39
2 * New Apps: ping and hostname contributed by Randolph Chung 2 * New Apps: ping, hostname, and mkfifo contributed by Randolph Chung
3 <tausq@debian.org>. 2 items off the TODO list! 3 <tausq@debian.org>. 3 items off the TODO list!
4 * I wrote free (just calls "cat /proc/meminfo"). 4 * I wrote free (just calls "cat /proc/meminfo").
5 * Added tail, based on tail from GNU textutils-1.19, but adjusted 5 * Added tail, based on tail from GNU textutils-1.19, but adjusted
6 to suit my evil purposes. Costs 6k. I'll make it smaller sometime. 6 to suit my evil purposes. Costs 6k. I'll make it smaller sometime.
diff --git a/applets/busybox.c b/applets/busybox.c
index d1eb38a0b..4d676e7c0 100644
--- a/applets/busybox.c
+++ b/applets/busybox.c
@@ -114,6 +114,9 @@ static const struct Applet applets[] = {
114#ifdef BB_MKDIR //bin 114#ifdef BB_MKDIR //bin
115 {"mkdir", mkdir_main}, 115 {"mkdir", mkdir_main},
116#endif 116#endif
117#ifdef BB_MKFIFO //usr/bin
118 {"mkfifo", mkfifo_main},
119#endif
117#ifdef BB_MKNOD //bin 120#ifdef BB_MKNOD //bin
118 {"mknod", mknod_main}, 121 {"mknod", mknod_main},
119#endif 122#endif
diff --git a/busybox.c b/busybox.c
index d1eb38a0b..4d676e7c0 100644
--- a/busybox.c
+++ b/busybox.c
@@ -114,6 +114,9 @@ static const struct Applet applets[] = {
114#ifdef BB_MKDIR //bin 114#ifdef BB_MKDIR //bin
115 {"mkdir", mkdir_main}, 115 {"mkdir", mkdir_main},
116#endif 116#endif
117#ifdef BB_MKFIFO //usr/bin
118 {"mkfifo", mkfifo_main},
119#endif
117#ifdef BB_MKNOD //bin 120#ifdef BB_MKNOD //bin
118 {"mknod", mknod_main}, 121 {"mknod", mknod_main},
119#endif 122#endif
diff --git a/busybox.def.h b/busybox.def.h
index 30533616a..402f2bce3 100644
--- a/busybox.def.h
+++ b/busybox.def.h
@@ -38,6 +38,7 @@
38//#define BB_MAKEDEVS 38//#define BB_MAKEDEVS
39//#define BB_MATH 39//#define BB_MATH
40#define BB_MKDIR 40#define BB_MKDIR
41//#define BB_MKFIFO
41#define BB_MKNOD 42#define BB_MKNOD
42#define BB_MKSWAP 43#define BB_MKSWAP
43//#define BB_MNC 44//#define BB_MNC
@@ -99,3 +100,5 @@
99#define BB_FEATURE_LS_TIMESTAMPS 100#define BB_FEATURE_LS_TIMESTAMPS
100// enable ls -p and -F 101// enable ls -p and -F
101#define BB_FEATURE_LS_FILETYPES 102#define BB_FEATURE_LS_FILETYPES
103// simplified ping
104//#define BB_SIMPLE_PING
diff --git a/coreutils/mkfifo.c b/coreutils/mkfifo.c
new file mode 100644
index 000000000..676592ac7
--- /dev/null
+++ b/coreutils/mkfifo.c
@@ -0,0 +1,61 @@
1/*
2 * Mini mkfifo implementation for busybox
3 *
4 * Copyright (C) 1999 by Randolph Chung <tausq@debian.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 */
21
22#include "internal.h"
23#include <stdio.h>
24#include <sys/types.h>
25#include <sys/stat.h>
26#include <errno.h>
27
28static const char mkfifo_usage[] = "mkfifo [OPTIONS] name\n\n"
29"Create the named fifo\n\n"
30"Options:\n"
31"\t-m\tcreate the fifo with the specified mode; default = a=rw-umask\n";
32
33extern int mkfifo_main(int argc, char **argv)
34{
35 char *thisarg;
36 mode_t mode = 0666;
37 argc--;
38 argv++;
39
40 /* Parse any options */
41 while (argc > 1) {
42 if (**argv != '-') usage(mkfifo_usage);
43 thisarg = *argv; thisarg++;
44 switch (*thisarg) {
45 case 'm':
46 argc--; argv++;
47 parse_mode(*argv, &mode);
48 break;
49 default:
50 usage (mkfifo_usage);
51 }
52 argc--; argv++;
53 }
54 if (argc < 1) usage (mkfifo_usage);
55 if (mkfifo(*argv, mode) < 0) {
56 perror("mkfifo");
57 exit(255);
58 } else {
59 exit(TRUE);
60 }
61}
diff --git a/internal.h b/internal.h
index 95df64c63..3cf777418 100644
--- a/internal.h
+++ b/internal.h
@@ -69,7 +69,6 @@ extern int false_main(int argc, char** argv);
69extern int fdisk_main(int argc, char** argv); 69extern int fdisk_main(int argc, char** argv);
70extern int fdflush_main(int argc, char **argv); 70extern int fdflush_main(int argc, char **argv);
71extern int fsck_minix_main(int argc, char **argv); 71extern int fsck_minix_main(int argc, char **argv);
72extern int mkfs_minix_main(int argc, char **argv);
73extern int find_main(int argc, char** argv); 72extern int find_main(int argc, char** argv);
74extern int free_main(int argc, char** argv); 73extern int free_main(int argc, char** argv);
75extern int grep_main(int argc, char** argv); 74extern int grep_main(int argc, char** argv);
@@ -89,6 +88,8 @@ extern int deallocvt_main(int argc, char** argv);
89extern int makedevs_main(int argc, char** argv); 88extern int makedevs_main(int argc, char** argv);
90extern int math_main(int argc, char** argv); 89extern int math_main(int argc, char** argv);
91extern int mkdir_main(int argc, char** argv); 90extern int mkdir_main(int argc, char** argv);
91extern int mkfifo_main(int argc, char **argv);
92extern int mkfs_minix_main(int argc, char **argv);
92extern int mknod_main(int argc, char** argv); 93extern int mknod_main(int argc, char** argv);
93extern int mkswap_main(int argc, char** argv); 94extern int mkswap_main(int argc, char** argv);
94extern int mnc_main(int argc, char** argv); 95extern int mnc_main(int argc, char** argv);
diff --git a/mkfifo.c b/mkfifo.c
new file mode 100644
index 000000000..676592ac7
--- /dev/null
+++ b/mkfifo.c
@@ -0,0 +1,61 @@
1/*
2 * Mini mkfifo implementation for busybox
3 *
4 * Copyright (C) 1999 by Randolph Chung <tausq@debian.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 */
21
22#include "internal.h"
23#include <stdio.h>
24#include <sys/types.h>
25#include <sys/stat.h>
26#include <errno.h>
27
28static const char mkfifo_usage[] = "mkfifo [OPTIONS] name\n\n"
29"Create the named fifo\n\n"
30"Options:\n"
31"\t-m\tcreate the fifo with the specified mode; default = a=rw-umask\n";
32
33extern int mkfifo_main(int argc, char **argv)
34{
35 char *thisarg;
36 mode_t mode = 0666;
37 argc--;
38 argv++;
39
40 /* Parse any options */
41 while (argc > 1) {
42 if (**argv != '-') usage(mkfifo_usage);
43 thisarg = *argv; thisarg++;
44 switch (*thisarg) {
45 case 'm':
46 argc--; argv++;
47 parse_mode(*argv, &mode);
48 break;
49 default:
50 usage (mkfifo_usage);
51 }
52 argc--; argv++;
53 }
54 if (argc < 1) usage (mkfifo_usage);
55 if (mkfifo(*argv, mode) < 0) {
56 perror("mkfifo");
57 exit(255);
58 } else {
59 exit(TRUE);
60 }
61}
diff --git a/networking/ping.c b/networking/ping.c
index 4176ab390..92b62def3 100644
--- a/networking/ping.c
+++ b/networking/ping.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: ping.c,v 1.5 1999/12/09 06:11:36 andersen Exp $ 2 * $Id: ping.c,v 1.6 1999/12/11 08:41:28 andersen 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>
@@ -63,28 +63,7 @@
63#define CLR(bit) (A(bit) &= (~B(bit))) 63#define CLR(bit) (A(bit) &= (~B(bit)))
64#define TST(bit) (A(bit) & B(bit)) 64#define TST(bit) (A(bit) & B(bit))
65 65
66static const char* ping_usage = "ping [OPTION]... host\n\n" 66/* common routines */
67"Send ICMP ECHO_REQUEST packets to network hosts.\n\n"
68"Options:\n"
69"\t-q\t\tQuiet mode, only displays output at start and when finished.\n"
70"\t-c COUNT\tSend only COUNT pings.\n";
71
72static char *hostname = NULL;
73static struct sockaddr_in pingaddr;
74static int pingsock = -1;
75static long ntransmitted = 0, nreceived = 0, nrepeats = 0, pingcount = 0;
76static int myid = 0, options = 0;
77static unsigned long tmin = ULONG_MAX, tmax = 0, tsum = 0;
78static char rcvd_tbl[MAX_DUP_CHK / 8];
79
80static void pingstats(int);
81static void sendping(int);
82static void unpack(char *, int, struct sockaddr_in *);
83static void ping(char *);
84static int in_cksum(unsigned short *, int);
85
86/**************************************************************************/
87
88static int in_cksum(unsigned short *buf, int sz) 67static int in_cksum(unsigned short *buf, int sz)
89{ 68{
90 int nleft = sz; 69 int nleft = sz;
@@ -108,6 +87,114 @@ static int in_cksum(unsigned short *buf, int sz)
108 return(ans); 87 return(ans);
109} 88}
110 89
90/* simple version */
91#ifdef BB_SIMPLE_PING
92static const char* ping_usage = "ping host\n\n";
93
94static char* hostname = NULL;
95
96static void noresp(int ign)
97{
98 printf("No response from %s\n", hostname);
99 exit(0);
100}
101
102static int ping(const char *host)
103{
104 struct hostent *h;
105 struct sockaddr_in pingaddr;
106 struct icmp *pkt;
107 int pingsock, c;
108 char packet[DEFDATALEN + MAXIPLEN + MAXICMPLEN];
109
110 if ((pingsock = socket(AF_INET, SOCK_RAW, 1)) < 0) { /* 1 == ICMP */
111 perror("ping");
112 exit(1);
113 }
114
115 /* drop root privs if running setuid */
116 setuid(getuid());
117
118 memset(&pingaddr, 0, sizeof(struct sockaddr_in));
119 pingaddr.sin_family = AF_INET;
120 if (!(h = gethostbyname(host))) {
121 fprintf(stderr, "ping: unknown host %s\n", host);
122 exit(1);
123 }
124 memcpy(&pingaddr.sin_addr, h->h_addr, sizeof(pingaddr.sin_addr));
125 hostname = h->h_name;
126
127 pkt = (struct icmp *)packet;
128 memset(pkt, 0, sizeof(packet));
129 pkt->icmp_type = ICMP_ECHO;
130 pkt->icmp_cksum = in_cksum((unsigned short *)pkt, sizeof(packet));
131
132 c = sendto(pingsock, packet, sizeof(packet), 0,
133 (struct sockaddr *)&pingaddr, sizeof(struct sockaddr_in));
134
135 if (c < 0 || c != sizeof(packet)) {
136 if (c < 0) perror("ping");
137 fprintf(stderr, "ping: write incomplete\n");
138 exit(1);
139 }
140
141 signal(SIGALRM, noresp);
142 alarm(5); /* give the host 5000ms to respond */
143 /* listen for replies */
144 while (1) {
145 struct sockaddr_in from;
146 size_t fromlen = sizeof(from);
147
148 if ((c = recvfrom(pingsock, packet, sizeof(packet), 0,
149 (struct sockaddr *)&from, &fromlen)) < 0) {
150 if (errno == EINTR) continue;
151 perror("ping");
152 continue;
153 }
154 if (c >= 76) { /* ip + icmp */
155 struct iphdr *iphdr = (struct iphdr *)packet;
156 pkt = (struct icmp *)(packet + (iphdr->ihl << 2)); /* skip ip hdr */
157 if (pkt->icmp_type == ICMP_ECHOREPLY) break;
158 }
159 }
160 printf("%s is alive!\n", hostname);
161 return(TRUE);
162}
163
164extern int ping_main(int argc, char **argv)
165{
166 argc--;
167 argv++;
168 if (argc < 1) usage(ping_usage);
169 ping(*argv);
170 exit(TRUE);
171}
172
173#else
174/* full(er) version */
175static const char* ping_usage = "ping [OPTION]... host\n\n"
176"Send ICMP ECHO_REQUEST packets to network hosts.\n\n"
177"Options:\n"
178"\t-q\t\tQuiet mode, only displays output at start and when finished.\n"
179"\t-c COUNT\tSend only COUNT pings.\n";
180
181static char *hostname = NULL;
182static struct sockaddr_in pingaddr;
183static int pingsock = -1;
184
185static long ntransmitted = 0, nreceived = 0, nrepeats = 0, pingcount = 0;
186static int myid = 0, options = 0;
187static unsigned long tmin = ULONG_MAX, tmax = 0, tsum = 0;
188static char rcvd_tbl[MAX_DUP_CHK / 8];
189
190static void sendping(int);
191static void pingstats(int);
192static void unpack(char *, int, struct sockaddr_in *);
193
194static void ping(char *);
195
196/**************************************************************************/
197
111static void pingstats(int ign) { 198static void pingstats(int ign) {
112 signal(SIGINT, SIG_IGN); 199 signal(SIGINT, SIG_IGN);
113 200
@@ -249,24 +336,20 @@ static void ping(char *host)
249 336
250 memset(&pingaddr, 0, sizeof(struct sockaddr_in)); 337 memset(&pingaddr, 0, sizeof(struct sockaddr_in));
251 pingaddr.sin_family = AF_INET; 338 pingaddr.sin_family = AF_INET;
252 if (inet_aton(host, &pingaddr.sin_addr)) { 339 if (!(h = gethostbyname(host))) {
253 hostname = host; 340 fprintf(stderr, "ping: unknown host %s\n", host);
254 } else { 341 exit(1);
255 if (!(h = gethostbyname(host))) { 342 }
256 fprintf(stderr, "ping: unknown host %s\n", host);
257 exit(1);
258 }
259 343
260 if (h->h_addrtype != AF_INET) { 344 if (h->h_addrtype != AF_INET) {
261 fprintf(stderr, "ping: unknown address type; only AF_INET is currently supported.\n"); 345 fprintf(stderr, "ping: unknown address type; only AF_INET is currently supported.\n");
262 exit(1); 346 exit(1);
263 }
264
265 pingaddr.sin_family = AF_INET; /* h->h_addrtype */
266 memcpy(&pingaddr.sin_addr, h->h_addr, sizeof(pingaddr.sin_addr));
267 strncpy(buf, h->h_name, sizeof(buf)-1);
268 hostname = buf;
269 } 347 }
348
349 pingaddr.sin_family = AF_INET; /* h->h_addrtype */
350 memcpy(&pingaddr.sin_addr, h->h_addr, sizeof(pingaddr.sin_addr));
351 strncpy(buf, h->h_name, sizeof(buf)-1);
352 hostname = buf;
270 353
271 /* enable broadcast pings */ 354 /* enable broadcast pings */
272 sockopt = 1; 355 sockopt = 1;
@@ -331,6 +414,7 @@ extern int ping_main(int argc, char **argv)
331 ping(*argv); 414 ping(*argv);
332 exit(TRUE); 415 exit(TRUE);
333} 416}
417#endif
334 418
335/* 419/*
336 * Copyright (c) 1989 The Regents of the University of California. 420 * Copyright (c) 1989 The Regents of the University of California.
@@ -367,5 +451,3 @@ extern int ping_main(int argc, char **argv)
367 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 451 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
368 * SUCH DAMAGE. 452 * SUCH DAMAGE.
369 */ 453 */
370
371
diff --git a/ping.c b/ping.c
index 4176ab390..92b62def3 100644
--- a/ping.c
+++ b/ping.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: ping.c,v 1.5 1999/12/09 06:11:36 andersen Exp $ 2 * $Id: ping.c,v 1.6 1999/12/11 08:41:28 andersen 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>
@@ -63,28 +63,7 @@
63#define CLR(bit) (A(bit) &= (~B(bit))) 63#define CLR(bit) (A(bit) &= (~B(bit)))
64#define TST(bit) (A(bit) & B(bit)) 64#define TST(bit) (A(bit) & B(bit))
65 65
66static const char* ping_usage = "ping [OPTION]... host\n\n" 66/* common routines */
67"Send ICMP ECHO_REQUEST packets to network hosts.\n\n"
68"Options:\n"
69"\t-q\t\tQuiet mode, only displays output at start and when finished.\n"
70"\t-c COUNT\tSend only COUNT pings.\n";
71
72static char *hostname = NULL;
73static struct sockaddr_in pingaddr;
74static int pingsock = -1;
75static long ntransmitted = 0, nreceived = 0, nrepeats = 0, pingcount = 0;
76static int myid = 0, options = 0;
77static unsigned long tmin = ULONG_MAX, tmax = 0, tsum = 0;
78static char rcvd_tbl[MAX_DUP_CHK / 8];
79
80static void pingstats(int);
81static void sendping(int);
82static void unpack(char *, int, struct sockaddr_in *);
83static void ping(char *);
84static int in_cksum(unsigned short *, int);
85
86/**************************************************************************/
87
88static int in_cksum(unsigned short *buf, int sz) 67static int in_cksum(unsigned short *buf, int sz)
89{ 68{
90 int nleft = sz; 69 int nleft = sz;
@@ -108,6 +87,114 @@ static int in_cksum(unsigned short *buf, int sz)
108 return(ans); 87 return(ans);
109} 88}
110 89
90/* simple version */
91#ifdef BB_SIMPLE_PING
92static const char* ping_usage = "ping host\n\n";
93
94static char* hostname = NULL;
95
96static void noresp(int ign)
97{
98 printf("No response from %s\n", hostname);
99 exit(0);
100}
101
102static int ping(const char *host)
103{
104 struct hostent *h;
105 struct sockaddr_in pingaddr;
106 struct icmp *pkt;
107 int pingsock, c;
108 char packet[DEFDATALEN + MAXIPLEN + MAXICMPLEN];
109
110 if ((pingsock = socket(AF_INET, SOCK_RAW, 1)) < 0) { /* 1 == ICMP */
111 perror("ping");
112 exit(1);
113 }
114
115 /* drop root privs if running setuid */
116 setuid(getuid());
117
118 memset(&pingaddr, 0, sizeof(struct sockaddr_in));
119 pingaddr.sin_family = AF_INET;
120 if (!(h = gethostbyname(host))) {
121 fprintf(stderr, "ping: unknown host %s\n", host);
122 exit(1);
123 }
124 memcpy(&pingaddr.sin_addr, h->h_addr, sizeof(pingaddr.sin_addr));
125 hostname = h->h_name;
126
127 pkt = (struct icmp *)packet;
128 memset(pkt, 0, sizeof(packet));
129 pkt->icmp_type = ICMP_ECHO;
130 pkt->icmp_cksum = in_cksum((unsigned short *)pkt, sizeof(packet));
131
132 c = sendto(pingsock, packet, sizeof(packet), 0,
133 (struct sockaddr *)&pingaddr, sizeof(struct sockaddr_in));
134
135 if (c < 0 || c != sizeof(packet)) {
136 if (c < 0) perror("ping");
137 fprintf(stderr, "ping: write incomplete\n");
138 exit(1);
139 }
140
141 signal(SIGALRM, noresp);
142 alarm(5); /* give the host 5000ms to respond */
143 /* listen for replies */
144 while (1) {
145 struct sockaddr_in from;
146 size_t fromlen = sizeof(from);
147
148 if ((c = recvfrom(pingsock, packet, sizeof(packet), 0,
149 (struct sockaddr *)&from, &fromlen)) < 0) {
150 if (errno == EINTR) continue;
151 perror("ping");
152 continue;
153 }
154 if (c >= 76) { /* ip + icmp */
155 struct iphdr *iphdr = (struct iphdr *)packet;
156 pkt = (struct icmp *)(packet + (iphdr->ihl << 2)); /* skip ip hdr */
157 if (pkt->icmp_type == ICMP_ECHOREPLY) break;
158 }
159 }
160 printf("%s is alive!\n", hostname);
161 return(TRUE);
162}
163
164extern int ping_main(int argc, char **argv)
165{
166 argc--;
167 argv++;
168 if (argc < 1) usage(ping_usage);
169 ping(*argv);
170 exit(TRUE);
171}
172
173#else
174/* full(er) version */
175static const char* ping_usage = "ping [OPTION]... host\n\n"
176"Send ICMP ECHO_REQUEST packets to network hosts.\n\n"
177"Options:\n"
178"\t-q\t\tQuiet mode, only displays output at start and when finished.\n"
179"\t-c COUNT\tSend only COUNT pings.\n";
180
181static char *hostname = NULL;
182static struct sockaddr_in pingaddr;
183static int pingsock = -1;
184
185static long ntransmitted = 0, nreceived = 0, nrepeats = 0, pingcount = 0;
186static int myid = 0, options = 0;
187static unsigned long tmin = ULONG_MAX, tmax = 0, tsum = 0;
188static char rcvd_tbl[MAX_DUP_CHK / 8];
189
190static void sendping(int);
191static void pingstats(int);
192static void unpack(char *, int, struct sockaddr_in *);
193
194static void ping(char *);
195
196/**************************************************************************/
197
111static void pingstats(int ign) { 198static void pingstats(int ign) {
112 signal(SIGINT, SIG_IGN); 199 signal(SIGINT, SIG_IGN);
113 200
@@ -249,24 +336,20 @@ static void ping(char *host)
249 336
250 memset(&pingaddr, 0, sizeof(struct sockaddr_in)); 337 memset(&pingaddr, 0, sizeof(struct sockaddr_in));
251 pingaddr.sin_family = AF_INET; 338 pingaddr.sin_family = AF_INET;
252 if (inet_aton(host, &pingaddr.sin_addr)) { 339 if (!(h = gethostbyname(host))) {
253 hostname = host; 340 fprintf(stderr, "ping: unknown host %s\n", host);
254 } else { 341 exit(1);
255 if (!(h = gethostbyname(host))) { 342 }
256 fprintf(stderr, "ping: unknown host %s\n", host);
257 exit(1);
258 }
259 343
260 if (h->h_addrtype != AF_INET) { 344 if (h->h_addrtype != AF_INET) {
261 fprintf(stderr, "ping: unknown address type; only AF_INET is currently supported.\n"); 345 fprintf(stderr, "ping: unknown address type; only AF_INET is currently supported.\n");
262 exit(1); 346 exit(1);
263 }
264
265 pingaddr.sin_family = AF_INET; /* h->h_addrtype */
266 memcpy(&pingaddr.sin_addr, h->h_addr, sizeof(pingaddr.sin_addr));
267 strncpy(buf, h->h_name, sizeof(buf)-1);
268 hostname = buf;
269 } 347 }
348
349 pingaddr.sin_family = AF_INET; /* h->h_addrtype */
350 memcpy(&pingaddr.sin_addr, h->h_addr, sizeof(pingaddr.sin_addr));
351 strncpy(buf, h->h_name, sizeof(buf)-1);
352 hostname = buf;
270 353
271 /* enable broadcast pings */ 354 /* enable broadcast pings */
272 sockopt = 1; 355 sockopt = 1;
@@ -331,6 +414,7 @@ extern int ping_main(int argc, char **argv)
331 ping(*argv); 414 ping(*argv);
332 exit(TRUE); 415 exit(TRUE);
333} 416}
417#endif
334 418
335/* 419/*
336 * Copyright (c) 1989 The Regents of the University of California. 420 * Copyright (c) 1989 The Regents of the University of California.
@@ -367,5 +451,3 @@ extern int ping_main(int argc, char **argv)
367 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 451 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
368 * SUCH DAMAGE. 452 * SUCH DAMAGE.
369 */ 453 */
370
371