blob: 646f4ac37e401c2ee75e536ee470bcec5b8845c5 [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 *
Rob Landley42eddba2005-12-15 08:04:17 +00008 * Adapted from the ping in netkit-base 0.10:
Eric Andersen485b9551999-12-07 23:14:59 +00009 * Copyright (c) 1989 The Regents of the University of California.
Rob Landley42eddba2005-12-15 08:04:17 +000010 * Derived from software contributed to Berkeley by Mike Muuss.
Eric Andersen485b9551999-12-07 23:14:59 +000011 *
Rob Landley42eddba2005-12-15 08:04:17 +000012 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
Eric Andersen485b9551999-12-07 23:14:59 +000013 */
14
Eric Andersen485b9551999-12-07 23:14:59 +000015#include <sys/param.h>
16#include <sys/socket.h>
17#include <sys/file.h>
18#include <sys/time.h>
19#include <sys/times.h>
20#include <sys/signal.h>
21
22#include <netinet/in.h>
23#include <netinet/ip.h>
24#include <netinet/ip_icmp.h>
25#include <arpa/inet.h>
26#include <netdb.h>
27#include <stdio.h>
28#include <stdlib.h>
29#include <errno.h>
Eric Andersened3ef502001-01-27 08:24:39 +000030#include <unistd.h>
31#include <string.h>
32#include <stdlib.h>
Eric Andersencbe31da2001-02-20 06:14:08 +000033#include "busybox.h"
Eric Andersen485b9551999-12-07 23:14:59 +000034
Eric Andersen9ca57d32000-06-19 18:51:53 +000035
Mark Whitley59ab0252001-01-23 22:30:04 +000036static const int DEFDATALEN = 56;
37static const int MAXIPLEN = 60;
38static const int MAXICMPLEN = 76;
39static const int MAXPACKET = 65468;
Eric Andersen485b9551999-12-07 23:14:59 +000040#define MAX_DUP_CHK (8 * 128)
Mark Whitley59ab0252001-01-23 22:30:04 +000041static const int MAXWAIT = 10;
42static const int PINGINTERVAL = 1; /* second */
Eric Andersen485b9551999-12-07 23:14:59 +000043
44#define O_QUIET (1 << 0)
45
46#define A(bit) rcvd_tbl[(bit)>>3] /* identify byte in array */
47#define B(bit) (1 << ((bit) & 0x07)) /* identify bit in byte */
48#define SET(bit) (A(bit) |= B(bit))
49#define CLR(bit) (A(bit) &= (~B(bit)))
50#define TST(bit) (A(bit) & B(bit))
51
Eric Andersene90e7412002-06-06 11:47:00 +000052static void ping(const char *host);
Pavel Roskin0024abc2000-06-07 20:38:15 +000053
Eric Andersen19db07b1999-12-11 08:41:28 +000054/* common routines */
Eric Andersen485b9551999-12-07 23:14:59 +000055static int in_cksum(unsigned short *buf, int sz)
56{
Erik Andersene49d5ec2000-02-08 19:58:47 +000057 int nleft = sz;
58 int sum = 0;
59 unsigned short *w = buf;
60 unsigned short ans = 0;
Eric Andersen485b9551999-12-07 23:14:59 +000061
Erik Andersene49d5ec2000-02-08 19:58:47 +000062 while (nleft > 1) {
63 sum += *w++;
64 nleft -= 2;
65 }
Eric Andersen485b9551999-12-07 23:14:59 +000066
Erik Andersene49d5ec2000-02-08 19:58:47 +000067 if (nleft == 1) {
68 *(unsigned char *) (&ans) = *(unsigned char *) w;
69 sum += ans;
70 }
Eric Andersen485b9551999-12-07 23:14:59 +000071
Erik Andersene49d5ec2000-02-08 19:58:47 +000072 sum = (sum >> 16) + (sum & 0xFFFF);
73 sum += (sum >> 16);
74 ans = ~sum;
75 return (ans);
76}
Eric Andersen485b9551999-12-07 23:14:59 +000077
Eric Andersen19db07b1999-12-11 08:41:28 +000078/* simple version */
Eric Andersenbdfd0d72001-10-24 05:00:29 +000079#ifndef CONFIG_FEATURE_FANCY_PING
Eric Andersenb5474c42002-03-20 11:59:28 +000080static char *hostname = NULL;
Eric Andersenb8886822002-03-21 14:04:43 +000081static void noresp(int ign)
Eric Andersenb5474c42002-03-20 11:59:28 +000082{
Eric Andersenb8886822002-03-21 14:04:43 +000083 printf("No response from %s\n", hostname);
Eric Andersen4e486a52003-01-12 06:08:33 +000084 exit(EXIT_FAILURE);
Eric Andersenb5474c42002-03-20 11:59:28 +000085}
Eric Andersen19db07b1999-12-11 08:41:28 +000086
Pavel Roskin0024abc2000-06-07 20:38:15 +000087static void ping(const char *host)
Eric Andersen19db07b1999-12-11 08:41:28 +000088{
Erik Andersene49d5ec2000-02-08 19:58:47 +000089 struct hostent *h;
90 struct sockaddr_in pingaddr;
91 struct icmp *pkt;
92 int pingsock, c;
93 char packet[DEFDATALEN + MAXIPLEN + MAXICMPLEN];
Eric Andersen19db07b1999-12-11 08:41:28 +000094
Matt Kraai06ef1652001-07-13 20:56:27 +000095 pingsock = create_icmp_socket();
Erik Andersene49d5ec2000-02-08 19:58:47 +000096
97 memset(&pingaddr, 0, sizeof(struct sockaddr_in));
98
99 pingaddr.sin_family = AF_INET;
Matt Kraaic55b8d42001-05-16 15:40:51 +0000100 h = xgethostbyname(host);
Erik Andersene49d5ec2000-02-08 19:58:47 +0000101 memcpy(&pingaddr.sin_addr, h->h_addr, sizeof(pingaddr.sin_addr));
Eric Andersenb5474c42002-03-20 11:59:28 +0000102 hostname = h->h_name;
Erik Andersene49d5ec2000-02-08 19:58:47 +0000103
104 pkt = (struct icmp *) packet;
105 memset(pkt, 0, sizeof(packet));
106 pkt->icmp_type = ICMP_ECHO;
107 pkt->icmp_cksum = in_cksum((unsigned short *) pkt, sizeof(packet));
108
109 c = sendto(pingsock, packet, sizeof(packet), 0,
110 (struct sockaddr *) &pingaddr, sizeof(struct sockaddr_in));
111
Matt Kraaia9819b22000-12-22 01:48:07 +0000112 if (c < 0 || c != sizeof(packet))
Manuel Novoa III cad53642003-03-19 09:13:01 +0000113 bb_perror_msg_and_die("sendto");
Erik Andersene49d5ec2000-02-08 19:58:47 +0000114
115 signal(SIGALRM, noresp);
116 alarm(5); /* give the host 5000ms to respond */
117 /* listen for replies */
118 while (1) {
119 struct sockaddr_in from;
Mike Frysinger03e827a2005-07-26 23:00:59 +0000120 socklen_t fromlen = sizeof(from);
Erik Andersene49d5ec2000-02-08 19:58:47 +0000121
122 if ((c = recvfrom(pingsock, packet, sizeof(packet), 0,
123 (struct sockaddr *) &from, &fromlen)) < 0) {
124 if (errno == EINTR)
125 continue;
Manuel Novoa III cad53642003-03-19 09:13:01 +0000126 bb_perror_msg("recvfrom");
Erik Andersene49d5ec2000-02-08 19:58:47 +0000127 continue;
128 }
129 if (c >= 76) { /* ip + icmp */
130 struct iphdr *iphdr = (struct iphdr *) packet;
131
132 pkt = (struct icmp *) (packet + (iphdr->ihl << 2)); /* skip ip hdr */
133 if (pkt->icmp_type == ICMP_ECHOREPLY)
134 break;
135 }
136 }
Eric Andersenb8886822002-03-21 14:04:43 +0000137 printf("%s is alive!\n", hostname);
Pavel Roskin0024abc2000-06-07 20:38:15 +0000138 return;
Eric Andersen19db07b1999-12-11 08:41:28 +0000139}
140
141extern int ping_main(int argc, char **argv)
142{
Erik Andersene49d5ec2000-02-08 19:58:47 +0000143 argc--;
144 argv++;
145 if (argc < 1)
Manuel Novoa III cad53642003-03-19 09:13:01 +0000146 bb_show_usage();
Erik Andersene49d5ec2000-02-08 19:58:47 +0000147 ping(*argv);
Matt Kraai3e856ce2000-12-01 02:55:13 +0000148 return EXIT_SUCCESS;
Eric Andersen19db07b1999-12-11 08:41:28 +0000149}
150
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000151#else /* ! CONFIG_FEATURE_FANCY_PING */
Eric Andersen19db07b1999-12-11 08:41:28 +0000152/* full(er) version */
Eric Andersen19db07b1999-12-11 08:41:28 +0000153static struct sockaddr_in pingaddr;
154static int pingsock = -1;
Mark Whitley59ab0252001-01-23 22:30:04 +0000155static int datalen; /* intentionally uninitialized to work around gcc bug */
Eric Andersen19db07b1999-12-11 08:41:28 +0000156
Matt Kraai369da772002-02-01 16:54:00 +0000157static long ntransmitted, nreceived, nrepeats, pingcount;
158static int myid, options;
159static unsigned long tmin = ULONG_MAX, tmax, tsum;
Eric Andersen19db07b1999-12-11 08:41:28 +0000160static char rcvd_tbl[MAX_DUP_CHK / 8];
161
Eric Andersen14f5c8d2005-04-16 19:39:00 +0000162#ifndef CONFIG_FEATURE_FANCY_PING6
163static
164#endif
165 struct hostent *hostent;
Matt Kraai369da772002-02-01 16:54:00 +0000166
Eric Andersen19db07b1999-12-11 08:41:28 +0000167static void sendping(int);
168static void pingstats(int);
169static void unpack(char *, int, struct sockaddr_in *);
170
Eric Andersen19db07b1999-12-11 08:41:28 +0000171/**************************************************************************/
172
Eric Andersenfad04fd2000-07-14 06:49:52 +0000173static void pingstats(int junk)
Erik Andersene49d5ec2000-02-08 19:58:47 +0000174{
Matt Kraaib938e2f2000-09-20 04:33:30 +0000175 int status;
176
Erik Andersene49d5ec2000-02-08 19:58:47 +0000177 signal(SIGINT, SIG_IGN);
178
Matt Kraai369da772002-02-01 16:54:00 +0000179 printf("\n--- %s ping statistics ---\n", hostent->h_name);
Erik Andersene49d5ec2000-02-08 19:58:47 +0000180 printf("%ld packets transmitted, ", ntransmitted);
181 printf("%ld packets received, ", nreceived);
182 if (nrepeats)
183 printf("%ld duplicates, ", nrepeats);
184 if (ntransmitted)
185 printf("%ld%% packet loss\n",
186 (ntransmitted - nreceived) * 100 / ntransmitted);
187 if (nreceived)
188 printf("round-trip min/avg/max = %lu.%lu/%lu.%lu/%lu.%lu ms\n",
189 tmin / 10, tmin % 10,
190 (tsum / (nreceived + nrepeats)) / 10,
191 (tsum / (nreceived + nrepeats)) % 10, tmax / 10, tmax % 10);
Matt Kraaib938e2f2000-09-20 04:33:30 +0000192 if (nreceived != 0)
193 status = EXIT_SUCCESS;
194 else
195 status = EXIT_FAILURE;
196 exit(status);
Eric Andersen485b9551999-12-07 23:14:59 +0000197}
198
Eric Andersenfad04fd2000-07-14 06:49:52 +0000199static void sendping(int junk)
Eric Andersen485b9551999-12-07 23:14:59 +0000200{
Erik Andersene49d5ec2000-02-08 19:58:47 +0000201 struct icmp *pkt;
202 int i;
Pavel Roskin0024abc2000-06-07 20:38:15 +0000203 char packet[datalen + 8];
Eric Andersen485b9551999-12-07 23:14:59 +0000204
Erik Andersene49d5ec2000-02-08 19:58:47 +0000205 pkt = (struct icmp *) packet;
Eric Andersen485b9551999-12-07 23:14:59 +0000206
Erik Andersene49d5ec2000-02-08 19:58:47 +0000207 pkt->icmp_type = ICMP_ECHO;
208 pkt->icmp_code = 0;
209 pkt->icmp_cksum = 0;
Mike Frysinger887a1ad2005-09-15 01:32:48 +0000210 pkt->icmp_seq = htons(ntransmitted++);
Erik Andersene49d5ec2000-02-08 19:58:47 +0000211 pkt->icmp_id = myid;
Mike Frysinger887a1ad2005-09-15 01:32:48 +0000212 CLR(ntohs(pkt->icmp_seq) % MAX_DUP_CHK);
Eric Andersen485b9551999-12-07 23:14:59 +0000213
Erik Andersene49d5ec2000-02-08 19:58:47 +0000214 gettimeofday((struct timeval *) &packet[8], NULL);
215 pkt->icmp_cksum = in_cksum((unsigned short *) pkt, sizeof(packet));
Eric Andersen485b9551999-12-07 23:14:59 +0000216
Erik Andersene49d5ec2000-02-08 19:58:47 +0000217 i = sendto(pingsock, packet, sizeof(packet), 0,
218 (struct sockaddr *) &pingaddr, sizeof(struct sockaddr_in));
219
Pavel Roskin0024abc2000-06-07 20:38:15 +0000220 if (i < 0)
Manuel Novoa III cad53642003-03-19 09:13:01 +0000221 bb_perror_msg_and_die("sendto");
Eric Andersenfad04fd2000-07-14 06:49:52 +0000222 else if ((size_t)i != sizeof(packet))
Manuel Novoa III cad53642003-03-19 09:13:01 +0000223 bb_error_msg_and_die("ping wrote %d chars; %d expected", i,
Pavel Roskin0024abc2000-06-07 20:38:15 +0000224 (int)sizeof(packet));
Erik Andersene49d5ec2000-02-08 19:58:47 +0000225
226 signal(SIGALRM, sendping);
227 if (pingcount == 0 || ntransmitted < pingcount) { /* schedule next in 1s */
228 alarm(PINGINTERVAL);
229 } else { /* done, wait for the last ping to come back */
230 /* todo, don't necessarily need to wait so long... */
231 signal(SIGALRM, pingstats);
232 alarm(MAXWAIT);
233 }
Eric Andersen485b9551999-12-07 23:14:59 +0000234}
Erik Andersene49d5ec2000-02-08 19:58:47 +0000235
Erik Andersen227a59b2000-04-25 23:24:55 +0000236static char *icmp_type_name (int id)
237{
238 switch (id) {
239 case ICMP_ECHOREPLY: return "Echo Reply";
240 case ICMP_DEST_UNREACH: return "Destination Unreachable";
241 case ICMP_SOURCE_QUENCH: return "Source Quench";
242 case ICMP_REDIRECT: return "Redirect (change route)";
243 case ICMP_ECHO: return "Echo Request";
244 case ICMP_TIME_EXCEEDED: return "Time Exceeded";
245 case ICMP_PARAMETERPROB: return "Parameter Problem";
246 case ICMP_TIMESTAMP: return "Timestamp Request";
247 case ICMP_TIMESTAMPREPLY: return "Timestamp Reply";
248 case ICMP_INFO_REQUEST: return "Information Request";
249 case ICMP_INFO_REPLY: return "Information Reply";
250 case ICMP_ADDRESS: return "Address Mask Request";
251 case ICMP_ADDRESSREPLY: return "Address Mask Reply";
252 default: return "unknown ICMP type";
253 }
254}
255
Eric Andersen485b9551999-12-07 23:14:59 +0000256static void unpack(char *buf, int sz, struct sockaddr_in *from)
257{
Erik Andersene49d5ec2000-02-08 19:58:47 +0000258 struct icmp *icmppkt;
259 struct iphdr *iphdr;
260 struct timeval tv, *tp;
261 int hlen, dupflag;
262 unsigned long triptime;
Eric Andersen485b9551999-12-07 23:14:59 +0000263
Erik Andersene49d5ec2000-02-08 19:58:47 +0000264 gettimeofday(&tv, NULL);
Eric Andersen485b9551999-12-07 23:14:59 +0000265
Erik Andersene49d5ec2000-02-08 19:58:47 +0000266 /* check IP header */
267 iphdr = (struct iphdr *) buf;
268 hlen = iphdr->ihl << 2;
269 /* discard if too short */
Pavel Roskin0024abc2000-06-07 20:38:15 +0000270 if (sz < (datalen + ICMP_MINLEN))
Erik Andersene49d5ec2000-02-08 19:58:47 +0000271 return;
Eric Andersen485b9551999-12-07 23:14:59 +0000272
Erik Andersene49d5ec2000-02-08 19:58:47 +0000273 sz -= hlen;
274 icmppkt = (struct icmp *) (buf + hlen);
275
Erik Andersen227a59b2000-04-25 23:24:55 +0000276 if (icmppkt->icmp_id != myid)
277 return; /* not our ping */
278
Erik Andersene49d5ec2000-02-08 19:58:47 +0000279 if (icmppkt->icmp_type == ICMP_ECHOREPLY) {
Mike Frysinger887a1ad2005-09-15 01:32:48 +0000280 u_int16_t recv_seq = ntohs(icmppkt->icmp_seq);
Erik Andersen227a59b2000-04-25 23:24:55 +0000281 ++nreceived;
Erik Andersene49d5ec2000-02-08 19:58:47 +0000282 tp = (struct timeval *) icmppkt->icmp_data;
283
284 if ((tv.tv_usec -= tp->tv_usec) < 0) {
285 --tv.tv_sec;
286 tv.tv_usec += 1000000;
287 }
288 tv.tv_sec -= tp->tv_sec;
289
290 triptime = tv.tv_sec * 10000 + (tv.tv_usec / 100);
291 tsum += triptime;
292 if (triptime < tmin)
293 tmin = triptime;
294 if (triptime > tmax)
295 tmax = triptime;
296
Mike Frysinger887a1ad2005-09-15 01:32:48 +0000297 if (TST(recv_seq % MAX_DUP_CHK)) {
Erik Andersene49d5ec2000-02-08 19:58:47 +0000298 ++nrepeats;
299 --nreceived;
300 dupflag = 1;
301 } else {
Mike Frysinger887a1ad2005-09-15 01:32:48 +0000302 SET(recv_seq % MAX_DUP_CHK);
Erik Andersene49d5ec2000-02-08 19:58:47 +0000303 dupflag = 0;
304 }
305
306 if (options & O_QUIET)
307 return;
308
309 printf("%d bytes from %s: icmp_seq=%u", sz,
310 inet_ntoa(*(struct in_addr *) &from->sin_addr.s_addr),
Mike Frysinger887a1ad2005-09-15 01:32:48 +0000311 recv_seq);
Erik Andersene49d5ec2000-02-08 19:58:47 +0000312 printf(" ttl=%d", iphdr->ttl);
313 printf(" time=%lu.%lu ms", triptime / 10, triptime % 10);
314 if (dupflag)
315 printf(" (DUP!)");
316 printf("\n");
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000317 } else
Erik Andersen227a59b2000-04-25 23:24:55 +0000318 if (icmppkt->icmp_type != ICMP_ECHO)
Manuel Novoa III cad53642003-03-19 09:13:01 +0000319 bb_error_msg("Warning: Got ICMP %d (%s)",
Erik Andersen227a59b2000-04-25 23:24:55 +0000320 icmppkt->icmp_type, icmp_type_name (icmppkt->icmp_type));
Rob Landley42eddba2005-12-15 08:04:17 +0000321 fflush(stdout);
Eric Andersen485b9551999-12-07 23:14:59 +0000322}
323
Eric Andersene90e7412002-06-06 11:47:00 +0000324static void ping(const char *host)
Eric Andersen485b9551999-12-07 23:14:59 +0000325{
Pavel Roskin0024abc2000-06-07 20:38:15 +0000326 char packet[datalen + MAXIPLEN + MAXICMPLEN];
Erik Andersene49d5ec2000-02-08 19:58:47 +0000327 int sockopt;
328
Matt Kraai06ef1652001-07-13 20:56:27 +0000329 pingsock = create_icmp_socket();
Eric Andersen485b9551999-12-07 23:14:59 +0000330
Erik Andersene49d5ec2000-02-08 19:58:47 +0000331 memset(&pingaddr, 0, sizeof(struct sockaddr_in));
Eric Andersen19db07b1999-12-11 08:41:28 +0000332
Erik Andersene49d5ec2000-02-08 19:58:47 +0000333 pingaddr.sin_family = AF_INET;
Matt Kraai369da772002-02-01 16:54:00 +0000334 hostent = xgethostbyname(host);
335 if (hostent->h_addrtype != AF_INET)
Manuel Novoa III cad53642003-03-19 09:13:01 +0000336 bb_error_msg_and_die("unknown address type; only AF_INET is currently supported.");
Erik Andersene49d5ec2000-02-08 19:58:47 +0000337
Matt Kraai369da772002-02-01 16:54:00 +0000338 memcpy(&pingaddr.sin_addr, hostent->h_addr, sizeof(pingaddr.sin_addr));
Erik Andersene49d5ec2000-02-08 19:58:47 +0000339
340 /* enable broadcast pings */
341 sockopt = 1;
342 setsockopt(pingsock, SOL_SOCKET, SO_BROADCAST, (char *) &sockopt,
343 sizeof(sockopt));
344
345 /* set recv buf for broadcast pings */
346 sockopt = 48 * 1024;
347 setsockopt(pingsock, SOL_SOCKET, SO_RCVBUF, (char *) &sockopt,
348 sizeof(sockopt));
349
350 printf("PING %s (%s): %d data bytes\n",
Matt Kraai369da772002-02-01 16:54:00 +0000351 hostent->h_name,
Erik Andersene49d5ec2000-02-08 19:58:47 +0000352 inet_ntoa(*(struct in_addr *) &pingaddr.sin_addr.s_addr),
Pavel Roskin0024abc2000-06-07 20:38:15 +0000353 datalen);
Erik Andersene49d5ec2000-02-08 19:58:47 +0000354
355 signal(SIGINT, pingstats);
356
357 /* start the ping's going ... */
358 sendping(0);
359
360 /* listen for replies */
361 while (1) {
362 struct sockaddr_in from;
Erik Andersen1d1d9502000-04-21 01:26:49 +0000363 socklen_t fromlen = (socklen_t) sizeof(from);
Erik Andersene49d5ec2000-02-08 19:58:47 +0000364 int c;
365
366 if ((c = recvfrom(pingsock, packet, sizeof(packet), 0,
367 (struct sockaddr *) &from, &fromlen)) < 0) {
368 if (errno == EINTR)
369 continue;
Manuel Novoa III cad53642003-03-19 09:13:01 +0000370 bb_perror_msg("recvfrom");
Erik Andersene49d5ec2000-02-08 19:58:47 +0000371 continue;
372 }
373 unpack(packet, c, &from);
374 if (pingcount > 0 && nreceived >= pingcount)
375 break;
376 }
377 pingstats(0);
Eric Andersen485b9551999-12-07 23:14:59 +0000378}
379
380extern int ping_main(int argc, char **argv)
381{
Erik Andersene49d5ec2000-02-08 19:58:47 +0000382 char *thisarg;
Eric Andersen485b9551999-12-07 23:14:59 +0000383
Mark Whitley59ab0252001-01-23 22:30:04 +0000384 datalen = DEFDATALEN; /* initialized here rather than in global scope to work around gcc bug */
385
Erik Andersene49d5ec2000-02-08 19:58:47 +0000386 argc--;
387 argv++;
388 options = 0;
389 /* Parse any options */
Erik Andersen9cf3bfa2000-04-13 18:49:43 +0000390 while (argc >= 1 && **argv == '-') {
Erik Andersene49d5ec2000-02-08 19:58:47 +0000391 thisarg = *argv;
392 thisarg++;
393 switch (*thisarg) {
394 case 'q':
395 options |= O_QUIET;
396 break;
397 case 'c':
Pavel Roskin0024abc2000-06-07 20:38:15 +0000398 if (--argc <= 0)
Manuel Novoa III cad53642003-03-19 09:13:01 +0000399 bb_show_usage();
Erik Andersene49d5ec2000-02-08 19:58:47 +0000400 argv++;
401 pingcount = atoi(*argv);
402 break;
Pavel Roskin0024abc2000-06-07 20:38:15 +0000403 case 's':
404 if (--argc <= 0)
Manuel Novoa III cad53642003-03-19 09:13:01 +0000405 bb_show_usage();
Pavel Roskin0024abc2000-06-07 20:38:15 +0000406 argv++;
407 datalen = atoi(*argv);
408 break;
Erik Andersene49d5ec2000-02-08 19:58:47 +0000409 default:
Manuel Novoa III cad53642003-03-19 09:13:01 +0000410 bb_show_usage();
Erik Andersene49d5ec2000-02-08 19:58:47 +0000411 }
412 argc--;
413 argv++;
414 }
415 if (argc < 1)
Manuel Novoa III cad53642003-03-19 09:13:01 +0000416 bb_show_usage();
Erik Andersene49d5ec2000-02-08 19:58:47 +0000417
418 myid = getpid() & 0xFFFF;
Eric Andersene90e7412002-06-06 11:47:00 +0000419 ping(*argv);
420 return EXIT_SUCCESS;
Eric Andersen485b9551999-12-07 23:14:59 +0000421}
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000422#endif /* ! CONFIG_FEATURE_FANCY_PING */