[BusyBox] [PATCH] ping -w argument
Ronny Arild
ronnya at acm.org
Tue Feb 18 08:16:03 UTC 2003
This patch implements "-w DEADLINE" for the FANCY_PING configuration
option. From ping(8) on a normal Linux system:
-w deadline
Specify a timeout, in seconds, before ping exits
regardless of how many packets have been sent or
received.
The patch is against busybox-stable (which is what I'm using).
--
Ronny H Arild - <ronnya at acm.org>
-------------- next part --------------
Index: ping.c
===================================================================
RCS file: /var/cvs/busybox.stable/ping.c,v
retrieving revision 1.47
diff -b -w -u -r1.47 ping.c
--- ping.c 17 Sep 2002 07:56:26 -0000 1.47
+++ ping.c 6 Feb 2003 16:23:06 -0000
@@ -136,7 +136,7 @@
static const int MAXICMPLEN = 76;
static const int MAXPACKET = 65468;
#define MAX_DUP_CHK (8 * 128)
-static const int MAXWAIT = 10;
+static const int MAXWAIT = 10; /* todo, don't necessarily need to wait so long... */
static const int PINGINTERVAL = 1; /* second */
#define O_QUIET (1 << 0)
@@ -254,6 +254,9 @@
static int pingsock = -1;
static int datalen; /* intentionally uninitialized to work around gcc bug */
+static int maxflag = FALSE;
+static int maxwait; /* as with datalen */
+
static long ntransmitted = 0, nreceived = 0, nrepeats = 0, pingcount = 0;
static int myid = 0, options = 0;
static unsigned long tmin = ULONG_MAX, tmax = 0, tsum = 0;
@@ -318,13 +321,18 @@
error_msg_and_die("ping wrote %d chars; %d expected", i,
(int)sizeof(packet));
+ if (maxwait > 0 && (pingcount == 0 || ntransmitted < pingcount)) { /* schedule next in 1s */
+ if (maxflag)
+ maxwait -= PINGINTERVAL;
signal(SIGALRM, sendping);
- if (pingcount == 0 || ntransmitted < pingcount) { /* schedule next in 1s */
alarm(PINGINTERVAL);
} else { /* done, wait for the last ping to come back */
- /* todo, don't necessarily need to wait so long... */
+ if (maxwait <= 0)
+ pingstats(0);
+ else {
signal(SIGALRM, pingstats);
- alarm(MAXWAIT);
+ alarm(maxwait);
+ }
}
}
@@ -479,6 +487,7 @@
char *thisarg;
datalen = DEFDATALEN; /* initialized here rather than in global scope to work around gcc bug */
+ maxwait = MAXWAIT; /* as with datalen */
argc--;
argv++;
@@ -502,6 +511,13 @@
show_usage();
argv++;
datalen = atoi(*argv);
+ break;
+ case 'w':
+ if (--argc <= 0)
+ show_usage();
+ argv++;
+ maxwait = atoi(*argv);
+ maxflag = TRUE;
break;
default:
show_usage();
-------------- next part --------------
Index: usage.h
===================================================================
RCS file: /var/cvs/busybox.stable/usage.h,v
retrieving revision 1.84
diff -b -w -u -r1.84 usage.h
--- usage.h 7 Nov 2002 02:26:59 -0000 1.84
+++ usage.h 6 Feb 2003 16:07:03 -0000
@@ -1308,6 +1308,7 @@
"Options:\n" \
"\t-c COUNT\tSend only COUNT pings.\n" \
"\t-s SIZE\t\tSend SIZE data bytes in packets (default=56).\n" \
+ "\t-w DEADLINE\tSpecify, in seconds, before ping exits.\n" \
"\t-q\t\tQuiet mode, only displays output at start\n" \
"\t\t\tand when finished."
#endif
More information about the busybox
mailing list