Package: netkit-ping
Version: 0.10-10.3
Severity: normal
Tags: patch
This patch allows for -i to specify ping intervals of less than one
second. I have configured it to allow 1/2 second intervals for non root
users and 1/100 second -i 0.01 for root users.
(those values are arbitrary, but the lower bound would appear to be
one tick).
patch below...
-- System Information:
Debian Release: testing/unstable
APT prefers testing
APT policy: (990, 'testing'), (500, 'unstable'), (500, 'stable'), (1,
'experimental')
Architecture: i386 (i686)
Shell: /bin/sh linked to /UNIONFS/bin/bash
Kernel: Linux 2.6.15
Locale: LANG=C, LC_CTYPE=C (charmap=ANSI_X3.4-1968) (ignored: LC_ALL set to C)
Versions of packages netkit-ping depends on:
ii libc6 2.3.5-13 GNU C Library: Shared libraries an
netkit-ping recommends no packages.
-- no debconf information
-- Patch:
--- ping/ping.c 1997/06/08 19:39:47 1.22
+++ ping/ping.c 2006/03/31 19:26:23
@@ -40,7 +40,7 @@
/*
* From: @(#)ping.c 5.9 (Berkeley) 5/12/91
*/
-char rcsid[] = "$Id: ping.c,v 1.22 1997/06/08 19:39:47 dholland Exp $";
+char rcsid[] = "$Id: ping.c,v 1.23 2006/03/31 19:21:39 samuel Exp $";
char pkg[] = "netkit-base-0.10";
/*
@@ -80,6 +80,7 @@
#include <stdio.h>
#include <ctype.h>
#include <errno.h>
+#include <limits.h>
/*
* Note: on some systems dropping root makes the process dumpable or
* traceable. In that case if you enable dropping root and someone
@@ -188,7 +189,8 @@
static long nreceived; /* # of packets we got back */
static long nrepeats; /* number of duplicates */
static long ntransmitted; /* sequence # for outbound packets = #sent */
-static int interval = 1; /* interval between packets */
+static double interval = 1.0; /* interval between packets */
+static int interticks; /* interval between packets */
static int floodok = 1; /* okay to send next flood ping? */
/* timing */
@@ -232,6 +234,7 @@
static char *null = NULL;
__environ = &null;
am_i_root = (getuid()==0);
+ interticks= CLK_TCK; /* interval between packets */
/*
* Pull this stuff up front so we can drop root if desired.
@@ -277,12 +280,19 @@
setbuf(stdout, NULL);
break;
case 'i': /* wait between sending packets */
- interval = atoi(optarg);
- if (interval <= 0) {
+ interval = atof(optarg);
+ if (interval < 0.01) {
(void)fprintf(stderr,
"ping: bad timing interval.\n");
exit(2);
+ };
+ if (interval<0.5 && !am_i_root) {
+ (void)fprintf(stderr,
+ "ping: %s\n", strerror(EPERM));
+ exit(2);
}
+ interticks = interval*CLK_TCK; /* interval between
packets */
+ if( interticks<2){ interticks= 2 ; };
options |= F_INTERVAL;
break;
case 'l':
@@ -535,6 +545,58 @@
}
/*
+ * timeval_to_d --
+ * d_to_timeval --
+ * convert between the double-long timeval struct and a double floating point
+ * ( I think this should have existed a long time ago)
+ */
+static double timeval_to_d( const struct timeval * tv ){
+ return tv->tv_sec+(((double)tv->tv_usec) / 1000000);
+};
+static void d_to_timeval(double dsec, struct timeval *tv){
+ if(dsec < (double)LONG_MAX && dsec > (double)LONG_MIN){
+ tv->tv_sec= dsec;
+ tv->tv_usec = (dsec - tv->tv_sec)*1000000;
+ return;
+ }else if(dsec>0){
+ tv->tv_sec=LONG_MAX;
+ }else{
+ tv->tv_sec=LONG_MIN;
+ };
+};
+
+
+/*
+ * dalarm --
+ * Does the same thing as alarm(2) does,
+ * except that it accepts a double floating point value for
+ * the length of time to wait.
+ */
+
+static double dalarm(const double altime){
+ struct itimerval old, new;
+ double dsec;
+ int res;
+
+ /* getitimer(ITIMER_REAL, &new ); */
+ new.it_interval.tv_sec=0;
+ new.it_interval.tv_usec=0;
+
+ d_to_timeval(altime,&(new.it_value));
+ /* printf("alarm:%5.2f,",timeval_to_d(&new.it_value)); */
+
+ if( (res= setitimer(ITIMER_REAL,&new,&old)) != 0 ){
+ perror("setitimer call failed");
+ exit(res);
+ };
+ /* assert(res==0); */
+ dsec=timeval_to_d(&(old.it_value));
+ /* printf("-> %5.2f,%5.2f:
",timeval_to_d(&(old.it_value)),timeval_to_d(&(old.it_interval))); */
+ return( dsec) ;
+};
+
+
+/*
* catcher --
* This routine causes another PING to be transmitted, and then
* schedules another SIGALRM for 1 second from now.
@@ -554,7 +616,7 @@
if (signum) {
current = times(&buf);
- if (current - last >= CLK_TCK - 1 || current < last) {
+ if (current - last >= interticks - 1 || current < last) {
last = current;
pinger();
}
@@ -563,7 +625,7 @@
(void)signal(SIGALRM, catcher);
if (!npackets || ntransmitted < npackets)
- alarm((u_int)interval);
+ dalarm((double)interval);
else {
if (nreceived) {
waittime = 2 * tmax / 1000;
--- ping/ping.8 1997/02/01 23:08:04 1.4
+++ ping/ping.8 2006/03/31 19:34:05
@@ -30,7 +30,7 @@
.\" SUCH DAMAGE.
.\"
.\" from: @(#)ping.8 6.7 (Berkeley) 3/16/91
-.\" $Id: ping.8,v 1.4 1997/02/01 23:08:04 dholland Exp $
+.\" $Id: ping.8,v 1.5 2006/03/31 19:33:53 samuel Exp samuel $
.\"
.Dd August 30, 1996
.Dt PING 8
@@ -96,6 +96,7 @@
.Ar wait
seconds
.Em between sending each packet .
+Shortest interval allowed is 0.5 seconds for non-root users 0.01 for root.
The default is to wait for one second between each packet.
This option is incompatible with the
.Fl f
--
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]