From: "Ole Bjørn Hessen" <obh@telenor.net>
To: netdev@vger.kernel.org
Subject: patch for iputils ping & ping6: print gettimeofday timestamp, print no reply
Date: 26 Jun 2009 23:46:34 +0200 [thread overview]
Message-ID: <v5prcqvfb9.fsf@shell1.nsc.no> (raw)
Hi,
sometimes I need to ping an IP address for a long time to get to know
how stable a connection is. It'd be nice if output from ping could be
configured to be more grep'ble and time stamped.
This small patch adds some functionality to print timestamp before
printfs (option -D) and also to print out "no reply yet" (option -N) if
no packet was received before next packet is sent.
I sent the patch original to Noah Meyerhans at debian, but he suggested
to send the patch to YOSHIFUJI Hideaki) via the netdev@vger.kernel.org
mailinglist instead.
Kind regards,
Ole Bjørn Hessen
Telenor
diff -r -u ../iputils_20071127.orig/doc/ping.sgml ./doc/ping.sgml
--- ../iputils_20071127.orig/doc/ping.sgml 2007-04-11 04:49:11.000000000 +0200
+++ ./doc/ping.sgml 2009-06-26 23:26:18.412415000 +0200
@@ -160,6 +160,19 @@
</para></listitem>
</varlistentry>
<varlistentry>
+ <term><option/-D/</term>
+ <listitem><para>
+Print timestamp (unix time + microseconds as in gettimeofday) before
+each line.
+ </para></listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><option/-N/</term>
+ <listitem><para>
+Print no reply yet if no packet was received before sending next packet.
+ </para></listitem>
+ </varlistentry>
+ <varlistentry>
<term><option>-Q <replaceable/tos/</option></term>
<listitem><para>
Set Quality of Service -related bits in ICMP datagrams.
diff -r -u ../iputils_20071127.orig/ping6.c ./ping6.c
--- ../iputils_20071127.orig/ping6.c 2007-12-10 04:56:22.000000000 +0100
+++ ./ping6.c 2009-06-26 23:30:44.303253000 +0200
@@ -672,6 +672,11 @@
if (options & F_FLOOD) {
write(STDOUT_FILENO, "\bE", 2);
} else {
+ if (options & F_PTIMEOFDAY) {
+ struct timeval recv_time;
+ gettimeofday(&recv_time, NULL);
+ printf("%lu.%06lu ", (unsigned long)recv_time.tv_sec, (unsigned long)recv_time.tv_usec);
+ }
printf("From %s icmp_seq=%u ", pr_addr(&sin6->sin6_addr), ntohs(icmph.icmp6_seq));
pr_icmph(e->ee_type, e->ee_code, e->ee_info);
putchar('\n');
@@ -821,11 +826,21 @@
write(STDOUT_FILENO, "\bE", 2);
return 0;
}
+ if (options & F_PTIMEOFDAY) {
+ struct timeval recv_time;
+ gettimeofday(&recv_time, NULL);
+ printf("%lu.%06lu ", (unsigned long)recv_time.tv_sec, (unsigned long)recv_time.tv_usec);
+ }
printf("From %s: icmp_seq=%u ", pr_addr(&from->sin6_addr), ntohs(icmph1->icmp6_seq));
} else {
/* We've got something other than an ECHOREPLY */
if (!(options & F_VERBOSE) || uid)
return 1;
+ if (options & F_PTIMEOFDAY) {
+ struct timeval recv_time;
+ gettimeofday(&recv_time, NULL);
+ printf("%lu.%06lu ", (unsigned long)recv_time.tv_sec, (unsigned long)recv_time.tv_usec);
+ }
printf("From %s: ", pr_addr(&from->sin6_addr));
}
pr_icmph(icmph->icmp6_type, icmph->icmp6_code, ntohl(icmph->icmp6_mtu));
@@ -971,7 +986,7 @@
void usage(void)
{
fprintf(stderr,
-"Usage: ping6 [-LUdfnqrvVaA] [-c count] [-i interval] [-w deadline]\n"
+"Usage: ping6 [-LUdfnqrvVaADN] [-c count] [-i interval] [-w deadline]\n"
" [-p pattern] [-s packetsize] [-t ttl] [-I interface]\n"
" [-M mtu discovery hint] [-S sndbuf]\n"
" [-F flow label] [-Q traffic class] [hop1 ...] destination\n");
diff -r -u ../iputils_20071127.orig/ping.c ./ping.c
--- ../iputils_20071127.orig/ping.c 2007-12-10 04:56:22.000000000 +0100
+++ ./ping.c 2009-06-26 23:30:31.202369000 +0200
@@ -595,6 +595,11 @@
if (options & F_FLOOD) {
write(STDOUT_FILENO, "\bE", 2);
} else {
+ if (options & F_PTIMEOFDAY) {
+ struct timeval recv_time;
+ gettimeofday(&recv_time, NULL);
+ printf("%lu.%06lu ", (unsigned long)recv_time.tv_sec, (unsigned long)recv_time.tv_usec);
+ }
printf("From %s icmp_seq=%u ", pr_addr(sin->sin_addr.s_addr), ntohs(icmph.un.echo.sequence));
pr_icmph(e->ee_type, e->ee_code, e->ee_info, NULL);
fflush(stdout);
@@ -761,6 +766,11 @@
write(STDOUT_FILENO, "\bE", 2);
return !error_pkt;
}
+ if (options & F_PTIMEOFDAY) {
+ struct timeval recv_time;
+ gettimeofday(&recv_time, NULL);
+ printf("%lu.%06lu ", (unsigned long)recv_time.tv_sec, (unsigned long)recv_time.tv_usec);
+ }
printf("From %s: icmp_seq=%u ",
pr_addr(from->sin_addr.s_addr),
ntohs(icp1->un.echo.sequence));
@@ -782,6 +792,11 @@
}
if (!(options & F_VERBOSE) || uid)
return 0;
+ if (options & F_PTIMEOFDAY) {
+ struct timeval recv_time;
+ gettimeofday(&recv_time, NULL);
+ printf("%lu.%06lu ", (unsigned long)recv_time.tv_sec, (unsigned long)recv_time.tv_usec);
+ }
printf("From %s: ", pr_addr(from->sin_addr.s_addr));
if (csfailed) {
printf("(BAD CHECKSUM)\n");
@@ -1214,7 +1229,7 @@
void usage(void)
{
fprintf(stderr,
-"Usage: ping [-LRUbdfnqrvVaA] [-c count] [-i interval] [-w deadline]\n"
+"Usage: ping [-LRUbdfnqrvVaADN] [-c count] [-i interval] [-w deadline]\n"
" [-p pattern] [-s packetsize] [-t ttl] [-I interface or address]\n"
" [-M mtu discovery hint] [-S sndbuf]\n"
" [ -T timestamp option ] [ -Q tos ] [hop1 ...] destination\n");
diff -r -u ../iputils_20071127.orig/ping_common.c ./ping_common.c
--- ../iputils_20071127.orig/ping_common.c 2009-06-26 19:53:06.361587000 +0200
+++ ./ping_common.c 2009-06-26 23:23:18.839167000 +0200
@@ -114,6 +114,9 @@
case 'd':
options |= F_SO_DEBUG;
break;
+ case 'D':
+ options |= F_PTIMEOFDAY;
+ break;
case 'f':
options |= F_FLOOD;
setbuf(stdout, (char *)NULL);
@@ -171,6 +174,9 @@
case 'n':
options |= F_NUMERIC;
break;
+ case 'N':
+ options |= F_NOREPLY;
+ break;
case 'p': /* fill buffer with user pattern */
options |= F_PINGFILLED;
fill(optarg);
@@ -316,6 +322,18 @@
tokens = ntokens - interval;
}
+ if (options & F_NOREPLY) {
+ if (ntransmitted > 0 && !TST(ntransmitted % mx_dup_ck)) {
+ if (options & F_PTIMEOFDAY) {
+ struct timeval recv_time;
+ gettimeofday(&recv_time, NULL);
+ printf("%lu.%06lu ", (unsigned long)recv_time.tv_sec, (unsigned long)recv_time.tv_usec);
+ }
+ printf("no answer yet for icmp_seq=%lu\n", (ntransmitted % mx_dup_ck));
+ fflush(stdout);
+ }
+ }
+
resend:
i = send_probe();
@@ -714,6 +732,11 @@
} else {
int i;
__u8 *cp, *dp;
+ if (options & F_PTIMEOFDAY) {
+ struct timeval recv_time;
+ gettimeofday(&recv_time, NULL);
+ printf("%lu.%06lu ", (unsigned long)recv_time.tv_sec, (unsigned long)recv_time.tv_usec);
+ }
printf("%d bytes from %s: icmp_seq=%u", cc, from, seq);
if (hops >= 0)
diff -r -u ../iputils_20071127.orig/ping_common.h ./ping_common.h
--- ../iputils_20071127.orig/ping_common.h 2007-12-10 04:56:22.000000000 +0100
+++ ./ping_common.h 2009-06-26 23:24:00.656302000 +0200
@@ -60,6 +60,8 @@
#define F_STRICTSOURCE 0x8000
#define F_NOLOOP 0x10000
#define F_TTL 0x20000
+#define F_PTIMEOFDAY 0x40000
+#define F_NOREPLY 0x80000
/*
* MAX_DUP_CHK is the number of bits in received table, i.e. the maximum
@@ -118,9 +120,10 @@
case 'f': case 'i': case 'w': case 'l': \
case 'S': case 'n': case 'p': case 'q': \
case 'r': case 's': case 'v': case 'L': \
-case 't': case 'A': case 'W': case 'B':
+case 't': case 'A': case 'W': case 'B': \
+case 'D': case 'N':
-#define COMMON_OPTSTR "h?VQ:I:M:aUc:dfi:w:l:S:np:qrs:vLt:AW:B"
+#define COMMON_OPTSTR "h?VQ:I:M:aUc:dfi:w:l:S:np:qrs:vLt:AW:BDN"
/*
reply other threads:[~2009-06-26 22:17 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=v5prcqvfb9.fsf@shell1.nsc.no \
--to=obh@telenor.net \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.