commit-inetutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[SCM] GNU Inetutils branch, master, updated. inetutils-1_9_1-92-gd5298c


From: Mats Erik Andersson
Subject: [SCM] GNU Inetutils branch, master, updated. inetutils-1_9_1-92-gd5298c7
Date: Sat, 12 May 2012 13:40:37 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU Inetutils ".

The branch, master has been updated
       via  d5298c7cf092f160f135d206dece09040e2c2410 (commit)
      from  5893d2ec601754a03e8cd5e5fa059966c769224a (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://git.savannah.gnu.org/cgit/inetutils.git/commit/?id=d5298c7cf092f160f135d206dece09040e2c2410


commit d5298c7cf092f160f135d206dece09040e2c2410
Author: Mats Erik Andersson <address@hidden>
Date:   Sat May 12 15:05:13 2012 +0200

    ping: Support IP option Timestamp.

diff --git a/ChangeLog b/ChangeLog
index 969822b..f2562e9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,21 @@
+2012-05-12  Mats Erik Andersson  <address@hidden>
+
+       ping: Support IP option Timestamp.
+
+       * doc/inetutils.texi (ping invocation): Update.
+       * ping/ping.c (suboptions): New variable.
+       (decode_ip_timestamp): New function.
+       (ARG_IPTIMESTAMP): New enumeration value.
+       (argp_options): Add long option `ip-timestamp'.
+       (parse_opt) <ARG_IPTIMESTAMP>: New case.
+       * ping/ping_common.h (OPT_IPTIMESTAMP, SOPT_TSONLY)
+       (SOPT_TSADDR, SOPT_TSPRESPEC): New macros.
+       * ping/ping_echo.c (ping_echo) [options & OPT_IPTIMESTAMP]:
+       New setup case.
+       (print_ip_opt): New variable K.
+       <IPOPT_TS>: New printout case.
+       * ping/ping_impl.h [!USE_IPV6] (suboptions): New external.
+
 2012-05-11  Mats Erik Andersson  <address@hidden>
 
        traceroute: Dynamic identity and sequence numbers.
diff --git a/doc/inetutils.texi b/doc/inetutils.texi
index 08cba61..cc2506b 100644
--- a/doc/inetutils.texi
+++ b/doc/inetutils.texi
@@ -560,10 +560,12 @@ transmitting packets.  Acceptable values are 1 to 255, 
inclusive.
 
 @c Options valid for --echo requests:
 @c   -f, --flood                Flood ping (root only)
address@hidden       --ip-timestamp=FLAG    Timestamp IP option of types tsonly,
+@                               tsaddr, or (not yet implemented) prespec.
 @c   -l, --preload=NUMBER       Send NUMBER packets as fast as possible before
 @c                              falling into normal mode of behavior (root 
only)
 @c   -p, --pattern=PATTERN      Fill ICMP packet with given pattern (hex)
address@hidden   -R, --route                Record route
address@hidden   -R, --route                Record route IP option
 @c   -s, --size=NUMBER          Send NUMBER data octets
 @table @option
 @item -f
@@ -577,6 +579,13 @@ backspace is printed.  This provides a rapid display of 
how many
 packets are being dropped.  Only the super-user may use this option.
 This can be very hard on a network and should be used with caution.
 
address@hidden address@hidden
address@hidden --ip-timestamp
+Include IP option Timestamp in transmitted packets.  The value
address@hidden is either of @samp{tsonly}, which only records up to nine
+time stamps, and @samp{tsaddr}, which records IP addresses as well
+as time stamps for at most four hosts.
+
 @item -l @var{n}
 @itemx address@hidden
 @opindex -l
diff --git a/ping/ping.c b/ping/ping.c
index 740f8fd..6b3f2e7 100644
--- a/ping/ping.c
+++ b/ping/ping.c
@@ -63,6 +63,7 @@ size_t count = DEFAULT_PING_COUNT;
 size_t interval;
 size_t data_length = PING_DATALEN;
 unsigned options;
+unsigned int suboptions;
 unsigned long preload = 0;
 int ttl = 0;
 int timeout = -1;
@@ -70,6 +71,7 @@ int linger = MAXWAIT;
 int (*ping_type) (char *hostname) = ping_echo;
 
 int (*decode_type (const char *arg)) (char *hostname);
+static int decode_ip_timestamp (char *arg);
 static int send_echo (PING * ping);
 
 #define MIN_USER_INTERVAL (200000/PING_PRECISION)
@@ -90,6 +92,7 @@ enum {
   ARG_TIMESTAMP,
   ARG_ROUTERDISCOVERY,
   ARG_TTL,
+  ARG_IPTIMESTAMP,
 };
 
 static struct argp_option argp_options[] = {
@@ -128,6 +131,8 @@ static struct argp_option argp_options[] = {
    GRP+1},
   {"quiet", 'q', NULL, 0, "quiet output", GRP+1},
   {"route", 'R', NULL, 0, "record route", GRP+1},
+  {"ip-timestamp", ARG_IPTIMESTAMP, "FLAG", 0, "IP timestamp of type FLAG, "
+   "which is one of \"tsonly\" and \"tsaddr\"", GRP+1},
   {"size", 's', "NUMBER", 0, "send NUMBER data octets", GRP+1},
 #undef GRP
   {NULL}
@@ -231,6 +236,11 @@ parse_opt (int key, char *arg, struct argp_state *state)
       ttl = ping_cvt_number (arg, 255, 0);
       break;
 
+    case ARG_IPTIMESTAMP:
+      options |= OPT_IPTIMESTAMP;
+      suboptions |= decode_ip_timestamp (arg);
+      break;
+
     case ARGP_KEY_NO_ARGS:
       argp_error (state, "missing host operand");
 
@@ -321,6 +331,25 @@ int (*decode_type (const char *arg)) (char *hostname)
  return ping_type;
 }
 
+int
+decode_ip_timestamp (char *arg)
+{
+  int sopt = 0;
+
+  if (strcasecmp (arg, "tsonly") == 0)
+    sopt = SOPT_TSONLY;
+  else if (strcasecmp (arg, "tsaddr") == 0)
+    sopt = SOPT_TSADDR;
+#if 0  /* Not yet implemented.  */
+  else if (strcasecmp (arg, "prespec") == 0)
+    sopt = SOPT_TSPRESPEC;
+#endif
+  else
+    error (EXIT_FAILURE, 0, "unsupported timestamp type: %s", arg);
+
+  return sopt;
+}
+
 int volatile stop = 0;
 
 void
diff --git a/ping/ping_common.h b/ping/ping_common.h
index fcda0be..68f477c 100644
--- a/ping/ping_common.h
+++ b/ping/ping_common.h
@@ -35,6 +35,11 @@
 #define OPT_QUIET       0x008
 #define OPT_RROUTE      0x010
 #define OPT_VERBOSE     0x020
+#define OPT_IPTIMESTAMP 0x040
+
+#define SOPT_TSONLY     0x001
+#define SOPT_TSADDR     0x002
+#define SOPT_TSPRESPEC  0x004
 
 struct ping_stat
 {
diff --git a/ping/ping_echo.c b/ping/ping_echo.c
index cc3445a..9eac495 100644
--- a/ping/ping_echo.c
+++ b/ping/ping_echo.c
@@ -100,6 +100,43 @@ ping_echo (char *hostname)
              "implementation.");
 #endif /* IP_OPTIONS */
     }
+  else if (options & OPT_IPTIMESTAMP)
+    {
+      int type;
+
+      if (suboptions & SOPT_TSPRESPEC)
+#ifdef IPOPT_TS_PRESPEC_RFC791
+       type = IPOPT_TS_PRESPEC_RFC791;
+#else
+       type = IPOPT_TS_PRESPEC;
+#endif
+      else if (suboptions & SOPT_TSADDR)
+       type = IPOPT_TS_TSANDADDR;
+      else
+        type = IPOPT_TS_TSONLY;
+
+#ifdef IP_OPTIONS
+      memset (rspace, 0, sizeof (rspace));
+      rspace[IPOPT_OPTVAL] = IPOPT_TS;
+      rspace[IPOPT_OLEN] = sizeof (rspace);
+      if (type != IPOPT_TS_TSONLY)
+       rspace[IPOPT_OLEN] -= sizeof (n_time);  /* Exsessive part.  */
+      rspace[IPOPT_OFFSET] = IPOPT_MINOFF + 1;
+
+# ifdef IPOPT_POS_OV_FLG
+      rspace[IPOPT_POS_OV_FLG] = type;
+# else
+      rspace[3] = type;
+# endif /* !IPOPT_POS_OV_FLG */
+
+      if (setsockopt (ping->ping_fd, IPPROTO_IP,
+                     IP_OPTIONS, rspace, rspace[IPOPT_OLEN]) < 0)
+        error (EXIT_FAILURE, errno, "setsockopt");
+#else /* !IP_OPTIONS */
+      error (EXIT_FAILURE, 0, "IP timestamp not available in this "
+             "implementation.");
+#endif /* IP_OPTIONS */
+    }
 
   printf ("PING %s (%s): %d data bytes",
          ping->ping_hostname,
@@ -397,7 +434,7 @@ void
 print_ip_opt (struct ip *ip, int hlen)
 {
   unsigned char *cp;
-  int i, j, l;
+  int i, j, k, l;
   static int old_rrlen;
   static char old_rr[MAX_IPOPTLEN];
 
@@ -508,6 +545,62 @@ print_ip_opt (struct ip *ip, int hlen)
          }
        break;
 
+      case IPOPT_TS:
+       j = *++cp;      /* len */
+       i = *++cp;      /* ptr */
+       hlen -= 2;
+       if (i > j)
+         i = j;
+
+       k = *++cp;      /* OV, FL */
+       ++cp;           /* Points at first content.  */
+       hlen -= 2;
+
+       printf ("\nTS:");
+       j = 5;          /* First possible slot.  */
+       for (;;)
+         {
+           char timestr[16];
+
+           if ((k & 0x0f) != IPOPT_TS_TSONLY
+               && ((j / 4) % 2 == 1))  /* find 5, 13, 21, 29 */
+             {
+               /* IP addresses */
+               struct in_addr ina;
+               char *s;
+
+               ina.s_addr = *((in_addr_t *) cp);
+               printf ("\t%s", s = sinaddr2str (ina));
+               free (s);
+
+               hlen -= sizeof (in_addr_t);
+               cp += sizeof (in_addr_t);
+               j += sizeof (in_addr_t);
+             }
+           else
+             {
+               /* Timestamps */
+               printf ("\t%s ms",
+                       ping_cvt_time (timestr, sizeof (timestr),
+                                       ntohl (*(n_time *) cp)));
+               if (options & OPT_VERBOSE)
+                 printf (" = 0x%08x", ntohl (*(n_time *) cp));
+
+               hlen -= sizeof (n_time);
+               cp += sizeof (n_time);
+               j += sizeof (n_time);
+
+               putchar ('\n');
+             }
+
+           if (j >= i)
+             break;
+         }
+
+       if (k & 0xf0)
+         printf ("\t(%u overflowing hosts)", k >> 4);
+       break;
+
       case IPOPT_NOP:
        printf ("\nNOP");
        break;
diff --git a/ping/ping_impl.h b/ping/ping_impl.h
index a8ebc36..91b8b87 100644
--- a/ping/ping_impl.h
+++ b/ping/ping_impl.h
@@ -20,6 +20,9 @@
 #define PING_MAX_DATALEN (65535 - MAXIPLEN - MAXICMPLEN)
 
 extern unsigned options;
+#if !USE_IPV6
+extern unsigned int suboptions;
+#endif
 extern PING *ping;
 extern unsigned char *data_buffer;
 extern size_t data_length;

-----------------------------------------------------------------------

Summary of changes:
 ChangeLog          |   18 ++++++++++
 doc/inetutils.texi |   11 +++++-
 ping/ping.c        |   29 ++++++++++++++++
 ping/ping_common.h |    5 +++
 ping/ping_echo.c   |   95 +++++++++++++++++++++++++++++++++++++++++++++++++++-
 ping/ping_impl.h   |    3 ++
 6 files changed, 159 insertions(+), 2 deletions(-)


hooks/post-receive
-- 
GNU Inetutils 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]