blob: c7cbd7078a0b4b767640b3e35cd8220adee0ae4c [file] [log] [blame]
Erik Andersene49d5ec2000-02-08 19:58:47 +00001/* vi: set sw=4 ts=4: */
Eric Andersen485b9551999-12-07 23:14:59 +00002/*
Eric Andersenc7bda1c2004-03-15 08:29:22 +00003 * $Id: ping.c,v 1.56 2004/03/15 08:28:48 andersen Exp $
Eric Andersen485b9551999-12-07 23:14:59 +00004 * Mini ping implementation for busybox
5 *
6 * Copyright (C) 1999 by Randolph Chung <tausq@debian.org>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 *
22 * This version of ping is adapted from the ping in netkit-base 0.10,
23 * which is:
24 *
25 * Copyright (c) 1989 The Regents of the University of California.
26 * All rights reserved.
27 *
28 * This code is derived from software contributed to Berkeley by
29 * Mike Muuss.
Eric Andersenc7bda1c2004-03-15 08:29:22 +000030 *
Eric Andersen485b9551999-12-07 23:14:59 +000031 * Original copyright notice is retained at the end of this file.
32 */
33
Eric Andersen485b9551999-12-07 23:14:59 +000034#include <sys/param.h>
35#include <sys/socket.h>
36#include <sys/file.h>
37#include <sys/time.h>
38#include <sys/times.h>
39#include <sys/signal.h>
40
41#include <netinet/in.h>
42#include <netinet/ip.h>
43#include <netinet/ip_icmp.h>
44#include <arpa/inet.h>
45#include <netdb.h>
46#include <stdio.h>
47#include <stdlib.h>
48#include <errno.h>
Eric Andersened3ef502001-01-27 08:24:39 +000049#include <unistd.h>
50#include <string.h>
51#include <stdlib.h>
Eric Andersencbe31da2001-02-20 06:14:08 +000052#include "busybox.h"
Eric Andersen485b9551999-12-07 23:14:59 +000053
Eric Andersen9ca57d32000-06-19 18:51:53 +000054
Mark Whitley59ab0252001-01-23 22:30:04 +000055static const int DEFDATALEN = 56;
56static const int MAXIPLEN = 60;
57static const int MAXICMPLEN = 76;
58static const int MAXPACKET = 65468;
Eric Andersen485b9551999-12-07 23:14:59 +000059#define MAX_DUP_CHK (8 * 128)
Mark Whitley59ab0252001-01-23 22:30:04 +000060static const int MAXWAIT = 10;
61static const int PINGINTERVAL = 1; /* second */
Eric Andersen485b9551999-12-07 23:14:59 +000062
63#define O_QUIET (1 << 0)
64
65#define A(bit) rcvd_tbl[(bit)>>3] /* identify byte in array */
66#define B(bit) (1 << ((bit) & 0x07)) /* identify bit in byte */
67#define SET(bit) (A(bit) |= B(bit))
68#define CLR(bit) (A(bit) &= (~B(bit)))
69#define TST(bit) (A(bit) & B(bit))
70
Eric Andersene90e7412002-06-06 11:47:00 +000071static void ping(const char *host);
Pavel Roskin0024abc2000-06-07 20:38:15 +000072
Eric Andersen19db07b1999-12-11 08:41:28 +000073/* common routines */
Eric Andersen485b9551999-12-07 23:14:59 +000074static int in_cksum(unsigned short *buf, int sz)
75{
Erik Andersene49d5ec2000-02-08 19:58:47 +000076 int nleft = sz;
77 int sum = 0;
78 unsigned short *w = buf;
79 unsigned short ans = 0;
Eric Andersen485b9551999-12-07 23:14:59 +000080
Erik Andersene49d5ec2000-02-08 19:58:47 +000081 while (nleft > 1) {
82 sum += *w++;
83 nleft -= 2;
84 }
Eric Andersen485b9551999-12-07 23:14:59 +000085
Erik Andersene49d5ec2000-02-08 19:58:47 +000086 if (nleft == 1) {
87 *(unsigned char *) (&ans) = *(unsigned char *) w;
88 sum += ans;
89 }
Eric Andersen485b9551999-12-07 23:14:59 +000090
Erik Andersene49d5ec2000-02-08 19:58:47 +000091 sum = (sum >> 16) + (sum & 0xFFFF);
92 sum += (sum >> 16);
93 ans = ~sum;
94 return (ans);
95}
Eric Andersen485b9551999-12-07 23:14:59 +000096
Eric Andersen19db07b1999-12-11 08:41:28 +000097/* simple version */
Eric Andersenbdfd0d72001-10-24 05:00:29 +000098#ifndef CONFIG_FEATURE_FANCY_PING
Eric Andersenb5474c42002-03-20 11:59:28 +000099static char *hostname = NULL;
Eric Andersenb8886822002-03-21 14:04:43 +0000100static void noresp(int ign)
Eric Andersenb5474c42002-03-20 11:59:28 +0000101{
Eric Andersenb8886822002-03-21 14:04:43 +0000102 printf("No response from %s\n", hostname);
Eric Andersen4e486a52003-01-12 06:08:33 +0000103 exit(EXIT_FAILURE);
Eric Andersenb5474c42002-03-20 11:59:28 +0000104}
Eric Andersen19db07b1999-12-11 08:41:28 +0000105
Pavel Roskin0024abc2000-06-07 20:38:15 +0000106static void ping(const char *host)
Eric Andersen19db07b1999-12-11 08:41:28 +0000107{
Erik Andersene49d5ec2000-02-08 19:58:47 +0000108 struct hostent *h;
109 struct sockaddr_in pingaddr;
110 struct icmp *pkt;
111 int pingsock, c;
112 char packet[DEFDATALEN + MAXIPLEN + MAXICMPLEN];
Eric Andersen19db07b1999-12-11 08:41:28 +0000113
Matt Kraai06ef1652001-07-13 20:56:27 +0000114 pingsock = create_icmp_socket();
Erik Andersene49d5ec2000-02-08 19:58:47 +0000115
116 memset(&pingaddr, 0, sizeof(struct sockaddr_in));
117
118 pingaddr.sin_family = AF_INET;
Matt Kraaic55b8d42001-05-16 15:40:51 +0000119 h = xgethostbyname(host);
Erik Andersene49d5ec2000-02-08 19:58:47 +0000120 memcpy(&pingaddr.sin_addr, h->h_addr, sizeof(pingaddr.sin_addr));
Eric Andersenb5474c42002-03-20 11:59:28 +0000121 hostname = h->h_name;
Erik Andersene49d5ec2000-02-08 19:58:47 +0000122
123 pkt = (struct icmp *) packet;
124 memset(pkt, 0, sizeof(packet));
125 pkt->icmp_type = ICMP_ECHO;
126 pkt->icmp_cksum = in_cksum((unsigned short *) pkt, sizeof(packet));
127
128 c = sendto(pingsock, packet, sizeof(packet), 0,
129 (struct sockaddr *) &pingaddr, sizeof(struct sockaddr_in));
130
Matt Kraaia9819b22000-12-22 01:48:07 +0000131 if (c < 0 || c != sizeof(packet))
Manuel Novoa III cad53642003-03-19 09:13:01 +0000132 bb_perror_msg_and_die("sendto");
Erik Andersene49d5ec2000-02-08 19:58:47 +0000133
134 signal(SIGALRM, noresp);
135 alarm(5); /* give the host 5000ms to respond */
136 /* listen for replies */
137 while (1) {
138 struct sockaddr_in from;
139 size_t fromlen = sizeof(from);
140
141 if ((c = recvfrom(pingsock, packet, sizeof(packet), 0,
142 (struct sockaddr *) &from, &fromlen)) < 0) {
143 if (errno == EINTR)
144 continue;
Manuel Novoa III cad53642003-03-19 09:13:01 +0000145 bb_perror_msg("recvfrom");
Erik Andersene49d5ec2000-02-08 19:58:47 +0000146 continue;
147 }
148 if (c >= 76) { /* ip + icmp */
149 struct iphdr *iphdr = (struct iphdr *) packet;
150
151 pkt = (struct icmp *) (packet + (iphdr->ihl << 2)); /* skip ip hdr */
152 if (pkt->icmp_type == ICMP_ECHOREPLY)
153 break;
154 }
155 }
Eric Andersenb8886822002-03-21 14:04:43 +0000156 printf("%s is alive!\n", hostname);
Pavel Roskin0024abc2000-06-07 20:38:15 +0000157 return;
Eric Andersen19db07b1999-12-11 08:41:28 +0000158}
159
160extern int ping_main(int argc, char **argv)
161{
Erik Andersene49d5ec2000-02-08 19:58:47 +0000162 argc--;
163 argv++;
164 if (argc < 1)
Manuel Novoa III cad53642003-03-19 09:13:01 +0000165 bb_show_usage();
Erik Andersene49d5ec2000-02-08 19:58:47 +0000166 ping(*argv);
Matt Kraai3e856ce2000-12-01 02:55:13 +0000167 return EXIT_SUCCESS;
Eric Andersen19db07b1999-12-11 08:41:28 +0000168}
169
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000170#else /* ! CONFIG_FEATURE_FANCY_PING */
Eric Andersen19db07b1999-12-11 08:41:28 +0000171/* full(er) version */
Eric Andersen19db07b1999-12-11 08:41:28 +0000172static struct sockaddr_in pingaddr;
173static int pingsock = -1;
Mark Whitley59ab0252001-01-23 22:30:04 +0000174static int datalen; /* intentionally uninitialized to work around gcc bug */
Eric Andersen19db07b1999-12-11 08:41:28 +0000175
Matt Kraai369da772002-02-01 16:54:00 +0000176static long ntransmitted, nreceived, nrepeats, pingcount;
177static int myid, options;
178static unsigned long tmin = ULONG_MAX, tmax, tsum;
Eric Andersen19db07b1999-12-11 08:41:28 +0000179static char rcvd_tbl[MAX_DUP_CHK / 8];
180
Eric Andersen14f5c8d2005-04-16 19:39:00 +0000181#ifndef CONFIG_FEATURE_FANCY_PING6
182static
183#endif
184 struct hostent *hostent;
Matt Kraai369da772002-02-01 16:54:00 +0000185
Eric Andersen19db07b1999-12-11 08:41:28 +0000186static void sendping(int);
187static void pingstats(int);
188static void unpack(char *, int, struct sockaddr_in *);
189
Eric Andersen19db07b1999-12-11 08:41:28 +0000190/**************************************************************************/
191
Eric Andersenfad04fd2000-07-14 06:49:52 +0000192static void pingstats(int junk)
Erik Andersene49d5ec2000-02-08 19:58:47 +0000193{
Matt Kraaib938e2f2000-09-20 04:33:30 +0000194 int status;
195
Erik Andersene49d5ec2000-02-08 19:58:47 +0000196 signal(SIGINT, SIG_IGN);
197
Matt Kraai369da772002-02-01 16:54:00 +0000198 printf("\n--- %s ping statistics ---\n", hostent->h_name);
Erik Andersene49d5ec2000-02-08 19:58:47 +0000199 printf("%ld packets transmitted, ", ntransmitted);
200 printf("%ld packets received, ", nreceived);
201 if (nrepeats)
202 printf("%ld duplicates, ", nrepeats);
203 if (ntransmitted)
204 printf("%ld%% packet loss\n",
205 (ntransmitted - nreceived) * 100 / ntransmitted);
206 if (nreceived)
207 printf("round-trip min/avg/max = %lu.%lu/%lu.%lu/%lu.%lu ms\n",
208 tmin / 10, tmin % 10,
209 (tsum / (nreceived + nrepeats)) / 10,
210 (tsum / (nreceived + nrepeats)) % 10, tmax / 10, tmax % 10);
Matt Kraaib938e2f2000-09-20 04:33:30 +0000211 if (nreceived != 0)
212 status = EXIT_SUCCESS;
213 else
214 status = EXIT_FAILURE;
215 exit(status);
Eric Andersen485b9551999-12-07 23:14:59 +0000216}
217
Eric Andersenfad04fd2000-07-14 06:49:52 +0000218static void sendping(int junk)
Eric Andersen485b9551999-12-07 23:14:59 +0000219{
Erik Andersene49d5ec2000-02-08 19:58:47 +0000220 struct icmp *pkt;
221 int i;
Pavel Roskin0024abc2000-06-07 20:38:15 +0000222 char packet[datalen + 8];
Eric Andersen485b9551999-12-07 23:14:59 +0000223
Erik Andersene49d5ec2000-02-08 19:58:47 +0000224 pkt = (struct icmp *) packet;
Eric Andersen485b9551999-12-07 23:14:59 +0000225
Erik Andersene49d5ec2000-02-08 19:58:47 +0000226 pkt->icmp_type = ICMP_ECHO;
227 pkt->icmp_code = 0;
228 pkt->icmp_cksum = 0;
229 pkt->icmp_seq = ntransmitted++;
230 pkt->icmp_id = myid;
231 CLR(pkt->icmp_seq % MAX_DUP_CHK);
Eric Andersen485b9551999-12-07 23:14:59 +0000232
Erik Andersene49d5ec2000-02-08 19:58:47 +0000233 gettimeofday((struct timeval *) &packet[8], NULL);
234 pkt->icmp_cksum = in_cksum((unsigned short *) pkt, sizeof(packet));
Eric Andersen485b9551999-12-07 23:14:59 +0000235
Erik Andersene49d5ec2000-02-08 19:58:47 +0000236 i = sendto(pingsock, packet, sizeof(packet), 0,
237 (struct sockaddr *) &pingaddr, sizeof(struct sockaddr_in));
238
Pavel Roskin0024abc2000-06-07 20:38:15 +0000239 if (i < 0)
Manuel Novoa III cad53642003-03-19 09:13:01 +0000240 bb_perror_msg_and_die("sendto");
Eric Andersenfad04fd2000-07-14 06:49:52 +0000241 else if ((size_t)i != sizeof(packet))
Manuel Novoa III cad53642003-03-19 09:13:01 +0000242 bb_error_msg_and_die("ping wrote %d chars; %d expected", i,
Pavel Roskin0024abc2000-06-07 20:38:15 +0000243 (int)sizeof(packet));
Erik Andersene49d5ec2000-02-08 19:58:47 +0000244
245 signal(SIGALRM, sendping);
246 if (pingcount == 0 || ntransmitted < pingcount) { /* schedule next in 1s */
247 alarm(PINGINTERVAL);
248 } else { /* done, wait for the last ping to come back */
249 /* todo, don't necessarily need to wait so long... */
250 signal(SIGALRM, pingstats);
251 alarm(MAXWAIT);
252 }
Eric Andersen485b9551999-12-07 23:14:59 +0000253}
Erik Andersene49d5ec2000-02-08 19:58:47 +0000254
Erik Andersen227a59b2000-04-25 23:24:55 +0000255static char *icmp_type_name (int id)
256{
257 switch (id) {
258 case ICMP_ECHOREPLY: return "Echo Reply";
259 case ICMP_DEST_UNREACH: return "Destination Unreachable";
260 case ICMP_SOURCE_QUENCH: return "Source Quench";
261 case ICMP_REDIRECT: return "Redirect (change route)";
262 case ICMP_ECHO: return "Echo Request";
263 case ICMP_TIME_EXCEEDED: return "Time Exceeded";
264 case ICMP_PARAMETERPROB: return "Parameter Problem";
265 case ICMP_TIMESTAMP: return "Timestamp Request";
266 case ICMP_TIMESTAMPREPLY: return "Timestamp Reply";
267 case ICMP_INFO_REQUEST: return "Information Request";
268 case ICMP_INFO_REPLY: return "Information Reply";
269 case ICMP_ADDRESS: return "Address Mask Request";
270 case ICMP_ADDRESSREPLY: return "Address Mask Reply";
271 default: return "unknown ICMP type";
272 }
273}
274
Eric Andersen485b9551999-12-07 23:14:59 +0000275static void unpack(char *buf, int sz, struct sockaddr_in *from)
276{
Erik Andersene49d5ec2000-02-08 19:58:47 +0000277 struct icmp *icmppkt;
278 struct iphdr *iphdr;
279 struct timeval tv, *tp;
280 int hlen, dupflag;
281 unsigned long triptime;
Eric Andersen485b9551999-12-07 23:14:59 +0000282
Erik Andersene49d5ec2000-02-08 19:58:47 +0000283 gettimeofday(&tv, NULL);
Eric Andersen485b9551999-12-07 23:14:59 +0000284
Erik Andersene49d5ec2000-02-08 19:58:47 +0000285 /* check IP header */
286 iphdr = (struct iphdr *) buf;
287 hlen = iphdr->ihl << 2;
288 /* discard if too short */
Pavel Roskin0024abc2000-06-07 20:38:15 +0000289 if (sz < (datalen + ICMP_MINLEN))
Erik Andersene49d5ec2000-02-08 19:58:47 +0000290 return;
Eric Andersen485b9551999-12-07 23:14:59 +0000291
Erik Andersene49d5ec2000-02-08 19:58:47 +0000292 sz -= hlen;
293 icmppkt = (struct icmp *) (buf + hlen);
294
Erik Andersen227a59b2000-04-25 23:24:55 +0000295 if (icmppkt->icmp_id != myid)
296 return; /* not our ping */
297
Erik Andersene49d5ec2000-02-08 19:58:47 +0000298 if (icmppkt->icmp_type == ICMP_ECHOREPLY) {
Erik Andersen227a59b2000-04-25 23:24:55 +0000299 ++nreceived;
Erik Andersene49d5ec2000-02-08 19:58:47 +0000300 tp = (struct timeval *) icmppkt->icmp_data;
301
302 if ((tv.tv_usec -= tp->tv_usec) < 0) {
303 --tv.tv_sec;
304 tv.tv_usec += 1000000;
305 }
306 tv.tv_sec -= tp->tv_sec;
307
308 triptime = tv.tv_sec * 10000 + (tv.tv_usec / 100);
309 tsum += triptime;
310 if (triptime < tmin)
311 tmin = triptime;
312 if (triptime > tmax)
313 tmax = triptime;
314
315 if (TST(icmppkt->icmp_seq % MAX_DUP_CHK)) {
316 ++nrepeats;
317 --nreceived;
318 dupflag = 1;
319 } else {
320 SET(icmppkt->icmp_seq % MAX_DUP_CHK);
321 dupflag = 0;
322 }
323
324 if (options & O_QUIET)
325 return;
326
327 printf("%d bytes from %s: icmp_seq=%u", sz,
328 inet_ntoa(*(struct in_addr *) &from->sin_addr.s_addr),
329 icmppkt->icmp_seq);
330 printf(" ttl=%d", iphdr->ttl);
331 printf(" time=%lu.%lu ms", triptime / 10, triptime % 10);
332 if (dupflag)
333 printf(" (DUP!)");
334 printf("\n");
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000335 } else
Erik Andersen227a59b2000-04-25 23:24:55 +0000336 if (icmppkt->icmp_type != ICMP_ECHO)
Manuel Novoa III cad53642003-03-19 09:13:01 +0000337 bb_error_msg("Warning: Got ICMP %d (%s)",
Erik Andersen227a59b2000-04-25 23:24:55 +0000338 icmppkt->icmp_type, icmp_type_name (icmppkt->icmp_type));
Eric Andersen485b9551999-12-07 23:14:59 +0000339}
340
Eric Andersene90e7412002-06-06 11:47:00 +0000341static void ping(const char *host)
Eric Andersen485b9551999-12-07 23:14:59 +0000342{
Pavel Roskin0024abc2000-06-07 20:38:15 +0000343 char packet[datalen + MAXIPLEN + MAXICMPLEN];
Erik Andersene49d5ec2000-02-08 19:58:47 +0000344 int sockopt;
345
Matt Kraai06ef1652001-07-13 20:56:27 +0000346 pingsock = create_icmp_socket();
Eric Andersen485b9551999-12-07 23:14:59 +0000347
Erik Andersene49d5ec2000-02-08 19:58:47 +0000348 memset(&pingaddr, 0, sizeof(struct sockaddr_in));
Eric Andersen19db07b1999-12-11 08:41:28 +0000349
Erik Andersene49d5ec2000-02-08 19:58:47 +0000350 pingaddr.sin_family = AF_INET;
Matt Kraai369da772002-02-01 16:54:00 +0000351 hostent = xgethostbyname(host);
352 if (hostent->h_addrtype != AF_INET)
Manuel Novoa III cad53642003-03-19 09:13:01 +0000353 bb_error_msg_and_die("unknown address type; only AF_INET is currently supported.");
Erik Andersene49d5ec2000-02-08 19:58:47 +0000354
Matt Kraai369da772002-02-01 16:54:00 +0000355 memcpy(&pingaddr.sin_addr, hostent->h_addr, sizeof(pingaddr.sin_addr));
Erik Andersene49d5ec2000-02-08 19:58:47 +0000356
357 /* enable broadcast pings */
358 sockopt = 1;
359 setsockopt(pingsock, SOL_SOCKET, SO_BROADCAST, (char *) &sockopt,
360 sizeof(sockopt));
361
362 /* set recv buf for broadcast pings */
363 sockopt = 48 * 1024;
364 setsockopt(pingsock, SOL_SOCKET, SO_RCVBUF, (char *) &sockopt,
365 sizeof(sockopt));
366
367 printf("PING %s (%s): %d data bytes\n",
Matt Kraai369da772002-02-01 16:54:00 +0000368 hostent->h_name,
Erik Andersene49d5ec2000-02-08 19:58:47 +0000369 inet_ntoa(*(struct in_addr *) &pingaddr.sin_addr.s_addr),
Pavel Roskin0024abc2000-06-07 20:38:15 +0000370 datalen);
Erik Andersene49d5ec2000-02-08 19:58:47 +0000371
372 signal(SIGINT, pingstats);
373
374 /* start the ping's going ... */
375 sendping(0);
376
377 /* listen for replies */
378 while (1) {
379 struct sockaddr_in from;
Erik Andersen1d1d9502000-04-21 01:26:49 +0000380 socklen_t fromlen = (socklen_t) sizeof(from);
Erik Andersene49d5ec2000-02-08 19:58:47 +0000381 int c;
382
383 if ((c = recvfrom(pingsock, packet, sizeof(packet), 0,
384 (struct sockaddr *) &from, &fromlen)) < 0) {
385 if (errno == EINTR)
386 continue;
Manuel Novoa III cad53642003-03-19 09:13:01 +0000387 bb_perror_msg("recvfrom");
Erik Andersene49d5ec2000-02-08 19:58:47 +0000388 continue;
389 }
390 unpack(packet, c, &from);
391 if (pingcount > 0 && nreceived >= pingcount)
392 break;
393 }
394 pingstats(0);
Eric Andersen485b9551999-12-07 23:14:59 +0000395}
396
397extern int ping_main(int argc, char **argv)
398{
Erik Andersene49d5ec2000-02-08 19:58:47 +0000399 char *thisarg;
Eric Andersen485b9551999-12-07 23:14:59 +0000400
Mark Whitley59ab0252001-01-23 22:30:04 +0000401 datalen = DEFDATALEN; /* initialized here rather than in global scope to work around gcc bug */
402
Erik Andersene49d5ec2000-02-08 19:58:47 +0000403 argc--;
404 argv++;
405 options = 0;
406 /* Parse any options */
Erik Andersen9cf3bfa2000-04-13 18:49:43 +0000407 while (argc >= 1 && **argv == '-') {
Erik Andersene49d5ec2000-02-08 19:58:47 +0000408 thisarg = *argv;
409 thisarg++;
410 switch (*thisarg) {
411 case 'q':
412 options |= O_QUIET;
413 break;
414 case 'c':
Pavel Roskin0024abc2000-06-07 20:38:15 +0000415 if (--argc <= 0)
Manuel Novoa III cad53642003-03-19 09:13:01 +0000416 bb_show_usage();
Erik Andersene49d5ec2000-02-08 19:58:47 +0000417 argv++;
418 pingcount = atoi(*argv);
419 break;
Pavel Roskin0024abc2000-06-07 20:38:15 +0000420 case 's':
421 if (--argc <= 0)
Manuel Novoa III cad53642003-03-19 09:13:01 +0000422 bb_show_usage();
Pavel Roskin0024abc2000-06-07 20:38:15 +0000423 argv++;
424 datalen = atoi(*argv);
425 break;
Erik Andersene49d5ec2000-02-08 19:58:47 +0000426 default:
Manuel Novoa III cad53642003-03-19 09:13:01 +0000427 bb_show_usage();
Erik Andersene49d5ec2000-02-08 19:58:47 +0000428 }
429 argc--;
430 argv++;
431 }
432 if (argc < 1)
Manuel Novoa III cad53642003-03-19 09:13:01 +0000433 bb_show_usage();
Erik Andersene49d5ec2000-02-08 19:58:47 +0000434
435 myid = getpid() & 0xFFFF;
Eric Andersene90e7412002-06-06 11:47:00 +0000436 ping(*argv);
437 return EXIT_SUCCESS;
Eric Andersen485b9551999-12-07 23:14:59 +0000438}
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000439#endif /* ! CONFIG_FEATURE_FANCY_PING */
Eric Andersen485b9551999-12-07 23:14:59 +0000440
441/*
442 * Copyright (c) 1989 The Regents of the University of California.
443 * All rights reserved.
444 *
445 * This code is derived from software contributed to Berkeley by
446 * Mike Muuss.
447 *
448 * Redistribution and use in source and binary forms, with or without
449 * modification, are permitted provided that the following conditions
450 * are met:
451 * 1. Redistributions of source code must retain the above copyright
452 * notice, this list of conditions and the following disclaimer.
453 * 2. Redistributions in binary form must reproduce the above copyright
454 * notice, this list of conditions and the following disclaimer in the
455 * documentation and/or other materials provided with the distribution.
Eric Andersen4e573f42000-11-14 23:29:24 +0000456 *
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000457 * 3. <BSD Advertising Clause omitted per the July 22, 1999 licensing change
458 * ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change>
Eric Andersen4e573f42000-11-14 23:29:24 +0000459 *
Eric Andersen485b9551999-12-07 23:14:59 +0000460 * 4. Neither the name of the University nor the names of its contributors
461 * may be used to endorse or promote products derived from this software
462 * without specific prior written permission.
463 *
464 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
465 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
466 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
467 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
468 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
469 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
470 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
471 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
472 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
473 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
474 * SUCH DAMAGE.
475 */