blob: ecfd125ae1a86cb995e3d315f81f073d7119582e [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
Rob Landleybc68cd12006-03-10 19:22:06 +000036enum {
37 DEFDATALEN = 56,
38 MAXIPLEN = 60,
39 MAXICMPLEN = 76,
40 MAXPACKET = 65468,
41 MAX_DUP_CHK = (8 * 128),
42 MAXWAIT = 10,
43 PINGINTERVAL = 1 /* second */
44};
Eric Andersen485b9551999-12-07 23:14:59 +000045
46#define O_QUIET (1 << 0)
47
48#define A(bit) rcvd_tbl[(bit)>>3] /* identify byte in array */
49#define B(bit) (1 << ((bit) & 0x07)) /* identify bit in byte */
50#define SET(bit) (A(bit) |= B(bit))
51#define CLR(bit) (A(bit) &= (~B(bit)))
52#define TST(bit) (A(bit) & B(bit))
53
Eric Andersene90e7412002-06-06 11:47:00 +000054static void ping(const char *host);
Pavel Roskin0024abc2000-06-07 20:38:15 +000055
Eric Andersen19db07b1999-12-11 08:41:28 +000056/* common routines */
Eric Andersen485b9551999-12-07 23:14:59 +000057static int in_cksum(unsigned short *buf, int sz)
58{
Erik Andersene49d5ec2000-02-08 19:58:47 +000059 int nleft = sz;
60 int sum = 0;
61 unsigned short *w = buf;
62 unsigned short ans = 0;
Eric Andersen485b9551999-12-07 23:14:59 +000063
Erik Andersene49d5ec2000-02-08 19:58:47 +000064 while (nleft > 1) {
65 sum += *w++;
66 nleft -= 2;
67 }
Eric Andersen485b9551999-12-07 23:14:59 +000068
Erik Andersene49d5ec2000-02-08 19:58:47 +000069 if (nleft == 1) {
70 *(unsigned char *) (&ans) = *(unsigned char *) w;
71 sum += ans;
72 }
Eric Andersen485b9551999-12-07 23:14:59 +000073
Erik Andersene49d5ec2000-02-08 19:58:47 +000074 sum = (sum >> 16) + (sum & 0xFFFF);
75 sum += (sum >> 16);
76 ans = ~sum;
77 return (ans);
78}
Eric Andersen485b9551999-12-07 23:14:59 +000079
Eric Andersen19db07b1999-12-11 08:41:28 +000080/* simple version */
Eric Andersenbdfd0d72001-10-24 05:00:29 +000081#ifndef CONFIG_FEATURE_FANCY_PING
Eric Andersenb5474c42002-03-20 11:59:28 +000082static char *hostname = NULL;
Eric Andersenb8886822002-03-21 14:04:43 +000083static void noresp(int ign)
Eric Andersenb5474c42002-03-20 11:59:28 +000084{
Eric Andersenb8886822002-03-21 14:04:43 +000085 printf("No response from %s\n", hostname);
Eric Andersen4e486a52003-01-12 06:08:33 +000086 exit(EXIT_FAILURE);
Eric Andersenb5474c42002-03-20 11:59:28 +000087}
Eric Andersen19db07b1999-12-11 08:41:28 +000088
Pavel Roskin0024abc2000-06-07 20:38:15 +000089static void ping(const char *host)
Eric Andersen19db07b1999-12-11 08:41:28 +000090{
Erik Andersene49d5ec2000-02-08 19:58:47 +000091 struct hostent *h;
92 struct sockaddr_in pingaddr;
93 struct icmp *pkt;
94 int pingsock, c;
95 char packet[DEFDATALEN + MAXIPLEN + MAXICMPLEN];
Eric Andersen19db07b1999-12-11 08:41:28 +000096
Matt Kraai06ef1652001-07-13 20:56:27 +000097 pingsock = create_icmp_socket();
Erik Andersene49d5ec2000-02-08 19:58:47 +000098
99 memset(&pingaddr, 0, sizeof(struct sockaddr_in));
100
101 pingaddr.sin_family = AF_INET;
Matt Kraaic55b8d42001-05-16 15:40:51 +0000102 h = xgethostbyname(host);
Erik Andersene49d5ec2000-02-08 19:58:47 +0000103 memcpy(&pingaddr.sin_addr, h->h_addr, sizeof(pingaddr.sin_addr));
Eric Andersenb5474c42002-03-20 11:59:28 +0000104 hostname = h->h_name;
Erik Andersene49d5ec2000-02-08 19:58:47 +0000105
106 pkt = (struct icmp *) packet;
107 memset(pkt, 0, sizeof(packet));
108 pkt->icmp_type = ICMP_ECHO;
109 pkt->icmp_cksum = in_cksum((unsigned short *) pkt, sizeof(packet));
110
111 c = sendto(pingsock, packet, sizeof(packet), 0,
112 (struct sockaddr *) &pingaddr, sizeof(struct sockaddr_in));
113
Matt Kraaia9819b22000-12-22 01:48:07 +0000114 if (c < 0 || c != sizeof(packet))
Manuel Novoa III cad53642003-03-19 09:13:01 +0000115 bb_perror_msg_and_die("sendto");
Erik Andersene49d5ec2000-02-08 19:58:47 +0000116
117 signal(SIGALRM, noresp);
118 alarm(5); /* give the host 5000ms to respond */
119 /* listen for replies */
120 while (1) {
121 struct sockaddr_in from;
Mike Frysinger03e827a2005-07-26 23:00:59 +0000122 socklen_t fromlen = sizeof(from);
Erik Andersene49d5ec2000-02-08 19:58:47 +0000123
124 if ((c = recvfrom(pingsock, packet, sizeof(packet), 0,
125 (struct sockaddr *) &from, &fromlen)) < 0) {
126 if (errno == EINTR)
127 continue;
Manuel Novoa III cad53642003-03-19 09:13:01 +0000128 bb_perror_msg("recvfrom");
Erik Andersene49d5ec2000-02-08 19:58:47 +0000129 continue;
130 }
131 if (c >= 76) { /* ip + icmp */
132 struct iphdr *iphdr = (struct iphdr *) packet;
133
134 pkt = (struct icmp *) (packet + (iphdr->ihl << 2)); /* skip ip hdr */
135 if (pkt->icmp_type == ICMP_ECHOREPLY)
136 break;
137 }
138 }
Eric Andersenb8886822002-03-21 14:04:43 +0000139 printf("%s is alive!\n", hostname);
Pavel Roskin0024abc2000-06-07 20:38:15 +0000140 return;
Eric Andersen19db07b1999-12-11 08:41:28 +0000141}
142
Rob Landleydfba7412006-03-06 20:47:33 +0000143int ping_main(int argc, char **argv)
Eric Andersen19db07b1999-12-11 08:41:28 +0000144{
Erik Andersene49d5ec2000-02-08 19:58:47 +0000145 argc--;
146 argv++;
147 if (argc < 1)
Manuel Novoa III cad53642003-03-19 09:13:01 +0000148 bb_show_usage();
Erik Andersene49d5ec2000-02-08 19:58:47 +0000149 ping(*argv);
Matt Kraai3e856ce2000-12-01 02:55:13 +0000150 return EXIT_SUCCESS;
Eric Andersen19db07b1999-12-11 08:41:28 +0000151}
152
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000153#else /* ! CONFIG_FEATURE_FANCY_PING */
Eric Andersen19db07b1999-12-11 08:41:28 +0000154/* full(er) version */
Eric Andersen19db07b1999-12-11 08:41:28 +0000155static struct sockaddr_in pingaddr;
156static int pingsock = -1;
Mark Whitley59ab0252001-01-23 22:30:04 +0000157static int datalen; /* intentionally uninitialized to work around gcc bug */
Eric Andersen19db07b1999-12-11 08:41:28 +0000158
Matt Kraai369da772002-02-01 16:54:00 +0000159static long ntransmitted, nreceived, nrepeats, pingcount;
160static int myid, options;
161static unsigned long tmin = ULONG_MAX, tmax, tsum;
Eric Andersen19db07b1999-12-11 08:41:28 +0000162static char rcvd_tbl[MAX_DUP_CHK / 8];
163
Eric Andersen14f5c8d2005-04-16 19:39:00 +0000164#ifndef CONFIG_FEATURE_FANCY_PING6
165static
166#endif
167 struct hostent *hostent;
Matt Kraai369da772002-02-01 16:54:00 +0000168
Eric Andersen19db07b1999-12-11 08:41:28 +0000169static void sendping(int);
170static void pingstats(int);
171static void unpack(char *, int, struct sockaddr_in *);
172
Eric Andersen19db07b1999-12-11 08:41:28 +0000173/**************************************************************************/
174
Eric Andersenfad04fd2000-07-14 06:49:52 +0000175static void pingstats(int junk)
Erik Andersene49d5ec2000-02-08 19:58:47 +0000176{
Matt Kraaib938e2f2000-09-20 04:33:30 +0000177 int status;
178
Erik Andersene49d5ec2000-02-08 19:58:47 +0000179 signal(SIGINT, SIG_IGN);
180
Matt Kraai369da772002-02-01 16:54:00 +0000181 printf("\n--- %s ping statistics ---\n", hostent->h_name);
Erik Andersene49d5ec2000-02-08 19:58:47 +0000182 printf("%ld packets transmitted, ", ntransmitted);
183 printf("%ld packets received, ", nreceived);
184 if (nrepeats)
185 printf("%ld duplicates, ", nrepeats);
186 if (ntransmitted)
187 printf("%ld%% packet loss\n",
188 (ntransmitted - nreceived) * 100 / ntransmitted);
189 if (nreceived)
190 printf("round-trip min/avg/max = %lu.%lu/%lu.%lu/%lu.%lu ms\n",
191 tmin / 10, tmin % 10,
192 (tsum / (nreceived + nrepeats)) / 10,
193 (tsum / (nreceived + nrepeats)) % 10, tmax / 10, tmax % 10);
Matt Kraaib938e2f2000-09-20 04:33:30 +0000194 if (nreceived != 0)
195 status = EXIT_SUCCESS;
196 else
197 status = EXIT_FAILURE;
198 exit(status);
Eric Andersen485b9551999-12-07 23:14:59 +0000199}
200
Eric Andersenfad04fd2000-07-14 06:49:52 +0000201static void sendping(int junk)
Eric Andersen485b9551999-12-07 23:14:59 +0000202{
Erik Andersene49d5ec2000-02-08 19:58:47 +0000203 struct icmp *pkt;
204 int i;
Rob Landleybbf4e162006-01-11 03:44:11 +0000205 char packet[datalen + sizeof(struct icmp)];
Eric Andersen485b9551999-12-07 23:14:59 +0000206
Erik Andersene49d5ec2000-02-08 19:58:47 +0000207 pkt = (struct icmp *) packet;
Eric Andersen485b9551999-12-07 23:14:59 +0000208
Erik Andersene49d5ec2000-02-08 19:58:47 +0000209 pkt->icmp_type = ICMP_ECHO;
210 pkt->icmp_code = 0;
211 pkt->icmp_cksum = 0;
Mike Frysinger887a1ad2005-09-15 01:32:48 +0000212 pkt->icmp_seq = htons(ntransmitted++);
Erik Andersene49d5ec2000-02-08 19:58:47 +0000213 pkt->icmp_id = myid;
Mike Frysinger887a1ad2005-09-15 01:32:48 +0000214 CLR(ntohs(pkt->icmp_seq) % MAX_DUP_CHK);
Eric Andersen485b9551999-12-07 23:14:59 +0000215
Rob Landleybbf4e162006-01-11 03:44:11 +0000216 gettimeofday((struct timeval *) &pkt->icmp_dun, NULL);
Erik Andersene49d5ec2000-02-08 19:58:47 +0000217 pkt->icmp_cksum = in_cksum((unsigned short *) pkt, sizeof(packet));
Eric Andersen485b9551999-12-07 23:14:59 +0000218
Erik Andersene49d5ec2000-02-08 19:58:47 +0000219 i = sendto(pingsock, packet, sizeof(packet), 0,
220 (struct sockaddr *) &pingaddr, sizeof(struct sockaddr_in));
221
Pavel Roskin0024abc2000-06-07 20:38:15 +0000222 if (i < 0)
Manuel Novoa III cad53642003-03-19 09:13:01 +0000223 bb_perror_msg_and_die("sendto");
Eric Andersenfad04fd2000-07-14 06:49:52 +0000224 else if ((size_t)i != sizeof(packet))
Manuel Novoa III cad53642003-03-19 09:13:01 +0000225 bb_error_msg_and_die("ping wrote %d chars; %d expected", i,
Pavel Roskin0024abc2000-06-07 20:38:15 +0000226 (int)sizeof(packet));
Erik Andersene49d5ec2000-02-08 19:58:47 +0000227
228 signal(SIGALRM, sendping);
229 if (pingcount == 0 || ntransmitted < pingcount) { /* schedule next in 1s */
230 alarm(PINGINTERVAL);
231 } else { /* done, wait for the last ping to come back */
232 /* todo, don't necessarily need to wait so long... */
233 signal(SIGALRM, pingstats);
234 alarm(MAXWAIT);
235 }
Eric Andersen485b9551999-12-07 23:14:59 +0000236}
Erik Andersene49d5ec2000-02-08 19:58:47 +0000237
Erik Andersen227a59b2000-04-25 23:24:55 +0000238static char *icmp_type_name (int id)
239{
240 switch (id) {
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000241 case ICMP_ECHOREPLY: return "Echo Reply";
242 case ICMP_DEST_UNREACH: return "Destination Unreachable";
243 case ICMP_SOURCE_QUENCH: return "Source Quench";
244 case ICMP_REDIRECT: return "Redirect (change route)";
245 case ICMP_ECHO: return "Echo Request";
246 case ICMP_TIME_EXCEEDED: return "Time Exceeded";
247 case ICMP_PARAMETERPROB: return "Parameter Problem";
248 case ICMP_TIMESTAMP: return "Timestamp Request";
249 case ICMP_TIMESTAMPREPLY: return "Timestamp Reply";
250 case ICMP_INFO_REQUEST: return "Information Request";
251 case ICMP_INFO_REPLY: return "Information Reply";
252 case ICMP_ADDRESS: return "Address Mask Request";
253 case ICMP_ADDRESSREPLY: return "Address Mask Reply";
254 default: return "unknown ICMP type";
Erik Andersen227a59b2000-04-25 23:24:55 +0000255 }
256}
257
Eric Andersen485b9551999-12-07 23:14:59 +0000258static void unpack(char *buf, int sz, struct sockaddr_in *from)
259{
Erik Andersene49d5ec2000-02-08 19:58:47 +0000260 struct icmp *icmppkt;
261 struct iphdr *iphdr;
262 struct timeval tv, *tp;
263 int hlen, dupflag;
264 unsigned long triptime;
Eric Andersen485b9551999-12-07 23:14:59 +0000265
Erik Andersene49d5ec2000-02-08 19:58:47 +0000266 gettimeofday(&tv, NULL);
Eric Andersen485b9551999-12-07 23:14:59 +0000267
Erik Andersene49d5ec2000-02-08 19:58:47 +0000268 /* check IP header */
269 iphdr = (struct iphdr *) buf;
270 hlen = iphdr->ihl << 2;
271 /* discard if too short */
Pavel Roskin0024abc2000-06-07 20:38:15 +0000272 if (sz < (datalen + ICMP_MINLEN))
Erik Andersene49d5ec2000-02-08 19:58:47 +0000273 return;
Eric Andersen485b9551999-12-07 23:14:59 +0000274
Erik Andersene49d5ec2000-02-08 19:58:47 +0000275 sz -= hlen;
276 icmppkt = (struct icmp *) (buf + hlen);
277
Erik Andersen227a59b2000-04-25 23:24:55 +0000278 if (icmppkt->icmp_id != myid)
279 return; /* not our ping */
280
Erik Andersene49d5ec2000-02-08 19:58:47 +0000281 if (icmppkt->icmp_type == ICMP_ECHOREPLY) {
Mike Frysinger887a1ad2005-09-15 01:32:48 +0000282 u_int16_t recv_seq = ntohs(icmppkt->icmp_seq);
Erik Andersen227a59b2000-04-25 23:24:55 +0000283 ++nreceived;
Erik Andersene49d5ec2000-02-08 19:58:47 +0000284 tp = (struct timeval *) icmppkt->icmp_data;
285
286 if ((tv.tv_usec -= tp->tv_usec) < 0) {
287 --tv.tv_sec;
288 tv.tv_usec += 1000000;
289 }
290 tv.tv_sec -= tp->tv_sec;
291
292 triptime = tv.tv_sec * 10000 + (tv.tv_usec / 100);
293 tsum += triptime;
294 if (triptime < tmin)
295 tmin = triptime;
296 if (triptime > tmax)
297 tmax = triptime;
298
Mike Frysinger887a1ad2005-09-15 01:32:48 +0000299 if (TST(recv_seq % MAX_DUP_CHK)) {
Erik Andersene49d5ec2000-02-08 19:58:47 +0000300 ++nrepeats;
301 --nreceived;
302 dupflag = 1;
303 } else {
Mike Frysinger887a1ad2005-09-15 01:32:48 +0000304 SET(recv_seq % MAX_DUP_CHK);
Erik Andersene49d5ec2000-02-08 19:58:47 +0000305 dupflag = 0;
306 }
307
308 if (options & O_QUIET)
309 return;
310
311 printf("%d bytes from %s: icmp_seq=%u", sz,
312 inet_ntoa(*(struct in_addr *) &from->sin_addr.s_addr),
Mike Frysinger887a1ad2005-09-15 01:32:48 +0000313 recv_seq);
Erik Andersene49d5ec2000-02-08 19:58:47 +0000314 printf(" ttl=%d", iphdr->ttl);
315 printf(" time=%lu.%lu ms", triptime / 10, triptime % 10);
316 if (dupflag)
317 printf(" (DUP!)");
318 printf("\n");
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000319 } else
Erik Andersen227a59b2000-04-25 23:24:55 +0000320 if (icmppkt->icmp_type != ICMP_ECHO)
Manuel Novoa III cad53642003-03-19 09:13:01 +0000321 bb_error_msg("Warning: Got ICMP %d (%s)",
Erik Andersen227a59b2000-04-25 23:24:55 +0000322 icmppkt->icmp_type, icmp_type_name (icmppkt->icmp_type));
Rob Landley42eddba2005-12-15 08:04:17 +0000323 fflush(stdout);
Eric Andersen485b9551999-12-07 23:14:59 +0000324}
325
Eric Andersene90e7412002-06-06 11:47:00 +0000326static void ping(const char *host)
Eric Andersen485b9551999-12-07 23:14:59 +0000327{
Pavel Roskin0024abc2000-06-07 20:38:15 +0000328 char packet[datalen + MAXIPLEN + MAXICMPLEN];
Erik Andersene49d5ec2000-02-08 19:58:47 +0000329 int sockopt;
330
Matt Kraai06ef1652001-07-13 20:56:27 +0000331 pingsock = create_icmp_socket();
Eric Andersen485b9551999-12-07 23:14:59 +0000332
Erik Andersene49d5ec2000-02-08 19:58:47 +0000333 memset(&pingaddr, 0, sizeof(struct sockaddr_in));
Eric Andersen19db07b1999-12-11 08:41:28 +0000334
Erik Andersene49d5ec2000-02-08 19:58:47 +0000335 pingaddr.sin_family = AF_INET;
Matt Kraai369da772002-02-01 16:54:00 +0000336 hostent = xgethostbyname(host);
337 if (hostent->h_addrtype != AF_INET)
Manuel Novoa III cad53642003-03-19 09:13:01 +0000338 bb_error_msg_and_die("unknown address type; only AF_INET is currently supported.");
Erik Andersene49d5ec2000-02-08 19:58:47 +0000339
Matt Kraai369da772002-02-01 16:54:00 +0000340 memcpy(&pingaddr.sin_addr, hostent->h_addr, sizeof(pingaddr.sin_addr));
Erik Andersene49d5ec2000-02-08 19:58:47 +0000341
342 /* enable broadcast pings */
343 sockopt = 1;
344 setsockopt(pingsock, SOL_SOCKET, SO_BROADCAST, (char *) &sockopt,
345 sizeof(sockopt));
346
347 /* set recv buf for broadcast pings */
348 sockopt = 48 * 1024;
349 setsockopt(pingsock, SOL_SOCKET, SO_RCVBUF, (char *) &sockopt,
350 sizeof(sockopt));
351
352 printf("PING %s (%s): %d data bytes\n",
Matt Kraai369da772002-02-01 16:54:00 +0000353 hostent->h_name,
Erik Andersene49d5ec2000-02-08 19:58:47 +0000354 inet_ntoa(*(struct in_addr *) &pingaddr.sin_addr.s_addr),
Pavel Roskin0024abc2000-06-07 20:38:15 +0000355 datalen);
Erik Andersene49d5ec2000-02-08 19:58:47 +0000356
357 signal(SIGINT, pingstats);
358
359 /* start the ping's going ... */
360 sendping(0);
361
362 /* listen for replies */
363 while (1) {
364 struct sockaddr_in from;
Erik Andersen1d1d9502000-04-21 01:26:49 +0000365 socklen_t fromlen = (socklen_t) sizeof(from);
Erik Andersene49d5ec2000-02-08 19:58:47 +0000366 int c;
367
368 if ((c = recvfrom(pingsock, packet, sizeof(packet), 0,
369 (struct sockaddr *) &from, &fromlen)) < 0) {
370 if (errno == EINTR)
371 continue;
Manuel Novoa III cad53642003-03-19 09:13:01 +0000372 bb_perror_msg("recvfrom");
Erik Andersene49d5ec2000-02-08 19:58:47 +0000373 continue;
374 }
375 unpack(packet, c, &from);
376 if (pingcount > 0 && nreceived >= pingcount)
377 break;
378 }
379 pingstats(0);
Eric Andersen485b9551999-12-07 23:14:59 +0000380}
381
Rob Landleydfba7412006-03-06 20:47:33 +0000382int ping_main(int argc, char **argv)
Eric Andersen485b9551999-12-07 23:14:59 +0000383{
Erik Andersene49d5ec2000-02-08 19:58:47 +0000384 char *thisarg;
Eric Andersen485b9551999-12-07 23:14:59 +0000385
Mark Whitley59ab0252001-01-23 22:30:04 +0000386 datalen = DEFDATALEN; /* initialized here rather than in global scope to work around gcc bug */
387
Erik Andersene49d5ec2000-02-08 19:58:47 +0000388 argc--;
389 argv++;
390 options = 0;
391 /* Parse any options */
Erik Andersen9cf3bfa2000-04-13 18:49:43 +0000392 while (argc >= 1 && **argv == '-') {
Erik Andersene49d5ec2000-02-08 19:58:47 +0000393 thisarg = *argv;
394 thisarg++;
395 switch (*thisarg) {
396 case 'q':
397 options |= O_QUIET;
398 break;
399 case 'c':
Pavel Roskin0024abc2000-06-07 20:38:15 +0000400 if (--argc <= 0)
Manuel Novoa III cad53642003-03-19 09:13:01 +0000401 bb_show_usage();
Erik Andersene49d5ec2000-02-08 19:58:47 +0000402 argv++;
403 pingcount = atoi(*argv);
404 break;
Pavel Roskin0024abc2000-06-07 20:38:15 +0000405 case 's':
406 if (--argc <= 0)
Manuel Novoa III cad53642003-03-19 09:13:01 +0000407 bb_show_usage();
Pavel Roskin0024abc2000-06-07 20:38:15 +0000408 argv++;
409 datalen = atoi(*argv);
410 break;
Erik Andersene49d5ec2000-02-08 19:58:47 +0000411 default:
Manuel Novoa III cad53642003-03-19 09:13:01 +0000412 bb_show_usage();
Erik Andersene49d5ec2000-02-08 19:58:47 +0000413 }
414 argc--;
415 argv++;
416 }
417 if (argc < 1)
Manuel Novoa III cad53642003-03-19 09:13:01 +0000418 bb_show_usage();
Erik Andersene49d5ec2000-02-08 19:58:47 +0000419
420 myid = getpid() & 0xFFFF;
Eric Andersene90e7412002-06-06 11:47:00 +0000421 ping(*argv);
422 return EXIT_SUCCESS;
Eric Andersen485b9551999-12-07 23:14:59 +0000423}
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000424#endif /* ! CONFIG_FEATURE_FANCY_PING */