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-86-g24f0cb


From: Mats Erik Andersson
Subject: [SCM] GNU Inetutils branch, master, updated. inetutils-1_9_1-86-g24f0cb0
Date: Tue, 08 May 2012 17:32:49 +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  24f0cb0538cef541153a999aee72867794abba14 (commit)
       via  b1410c18b8f692c1d1aeff0b305c6ebc466c5ccc (commit)
       via  cd091aa41b1de362e074a58a638636454c6a0f34 (commit)
       via  1dc2e02ed08308ab0eb48460dcfc98fdfcc64d4e (commit)
      from  153434103dc0b365bd1d187a2c72d2e4a62a27a8 (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=24f0cb0538cef541153a999aee72867794abba14


commit 24f0cb0538cef541153a999aee72867794abba14
Author: Mats Erik Andersson <address@hidden>
Date:   Tue May 8 18:56:38 2012 +0200

    ping, ping6: Critical sizing errors.

diff --git a/ChangeLog b/ChangeLog
index bc672df..739dfb7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,22 @@
 2012-05-08  Mats Erik Andersson  <address@hidden>
 
+       Critical package errors in size and allocation.
+
+       * ping/ping.c (send_echo): Replace macro PING_HEADER_LEN by
+       calculated value OFF, i.e., the number of consumed bytes.
+       * ping/ping6.c (send_echo): Likewise.
+       (ping_init): Initialise `p->ping_datalen' as the size of
+       `struct timeval', a possible payload.
+       * ping/ping_common.h (PING_HEADER_LEN): Use correct size as
+       `sizeof(struct icmp6_hdr)' and ICMP_MINLEN, respectively.
+       (PING_TIMING): Compare with `sizeof(struct timeval)'.
+       (_PING_BUFLEN) <IPv4 case>: Add contribution MAXIPLEN, and
+       increase ICMP contribution to ICMP_TSLEN, the maximal length.
+       * ping/ping_echo.c (ping_echo) [options & OPT_RROUTE && IP_OPTIONS]:
+       Remove call (a recent regression) to ping_set_packetsize().
+
+2012-05-08  Mats Erik Andersson  <address@hidden>
+
        Incomplete endianness conversions.
 
        * libicmp/icmp_echo.c (icmp_generic_encode): Apply htons() to
diff --git a/ping/ping.c b/ping/ping.c
index a9b2ad6..b82f557 100644
--- a/ping/ping.c
+++ b/ping/ping.c
@@ -443,8 +443,8 @@ send_echo (PING * ping)
     }
   if (data_buffer)
     ping_set_data (ping, data_buffer, off,
-                  data_length > PING_HEADER_LEN ?
-                  data_length - PING_HEADER_LEN : data_length, USE_IPV6);
+                  data_length > off ? data_length - off : data_length,
+                  USE_IPV6);
   return ping_xmit (ping);
 }
 
diff --git a/ping/ping6.c b/ping/ping6.c
index 54aaac9..4f7d041 100644
--- a/ping/ping6.c
+++ b/ping/ping6.c
@@ -400,8 +400,8 @@ send_echo (PING * ping)
     }
   if (data_buffer)
     ping_set_data (ping, data_buffer, off,
-                  data_length > PING_HEADER_LEN ?
-                  data_length - PING_HEADER_LEN : data_length, USE_IPV6);
+                  data_length > off ? data_length - off : data_length,
+                  USE_IPV6);
   return ping_xmit (ping);
 }
 
@@ -761,7 +761,7 @@ ping_init (int type, int ident)
   p->ping_fd = fd;
   p->ping_count = DEFAULT_PING_COUNT;
   p->ping_interval = PING_DEFAULT_INTERVAL;
-  p->ping_datalen = sizeof (struct icmp6_hdr);
+  p->ping_datalen = sizeof (struct timeval);
   /* Make sure we use only 16 bits in this field, id for icmp is a unsigned 
short.  */
   p->ping_ident = ident & 0xFFFF;
   p->ping_cktab_size = PING_CKTABSIZE;
diff --git a/ping/ping_common.h b/ping/ping_common.h
index 6bb7d15..2c8c796 100644
--- a/ping/ping_common.h
+++ b/ping/ping_common.h
@@ -54,8 +54,8 @@ struct ping_stat
    want to follow the traditional behaviour of ping.  */
 #define DEFAULT_PING_COUNT 0
 
-#define PING_TIMING(s) (s >= PING_HEADER_LEN)
-#define PING_HEADER_LEN sizeof (struct timeval)
+#define PING_HEADER_LEN (USE_IPV6 ? sizeof (struct icmp6_hdr) : ICMP_MINLEN)
+#define PING_TIMING(s)  ((s) >= sizeof (struct timeval))
 #define PING_DATALEN    (64 - PING_HEADER_LEN)  /* default data length */
 
 #define PING_DEFAULT_INTERVAL 1000      /* Milliseconds */
@@ -66,9 +66,9 @@ struct ping_stat
   (t).tv_usec = ((i)%PING_PRECISION)*(1000000/PING_PRECISION) ;\
 } while (0)
 
-/* Not sure about this step*/
+/* FIXME: Adjust IPv6 case for options and their consumption.  */
 #define _PING_BUFLEN(p, USE_IPV6) ((USE_IPV6)? ((p)->ping_datalen + sizeof 
(struct icmp6_hdr)) : \
-                                  ((p)->ping_datalen + sizeof (icmphdr_t)))
+                                  (MAXIPLEN + (p)->ping_datalen + ICMP_TSLEN))
 
 typedef int (*ping_efp6) (int code, void *closure, struct sockaddr_in6 * dest,
                          struct sockaddr_in6 * from, struct icmp6_hdr * icmp,
diff --git a/ping/ping_echo.c b/ping/ping_echo.c
index b218e35..870d685 100644
--- a/ping/ping_echo.c
+++ b/ping/ping_echo.c
@@ -95,8 +95,6 @@ ping_echo (char *hostname)
       if (setsockopt (ping->ping_fd, IPPROTO_IP,
                      IP_OPTIONS, rspace, sizeof (rspace)) < 0)
         error (EXIT_FAILURE, errno, "setsockopt");
-      /* The encapsulating IP header is now augmented with options.  */
-      ping_set_packetsize (ping, data_length + sizeof (rspace));
 #else
       error (EXIT_FAILURE, 0, "record route not available in this "
              "implementation.");

http://git.savannah.gnu.org/cgit/inetutils.git/commit/?id=b1410c18b8f692c1d1aeff0b305c6ebc466c5ccc


commit b1410c18b8f692c1d1aeff0b305c6ebc466c5ccc
Author: Mats Erik Andersson <address@hidden>
Date:   Tue May 8 18:54:08 2012 +0200

    libicmp, ping, ping6: Endianness conversions.

diff --git a/ChangeLog b/ChangeLog
index 5851215..bc672df 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,22 @@
 2012-05-08  Mats Erik Andersson  <address@hidden>
 
+       Incomplete endianness conversions.
+
+       * libicmp/icmp_echo.c (icmp_generic_encode): Apply htons() to
+       SEQNO and IDENT.
+       * ping/libping.c (my_echo_reply, ping_recv): Apply ntohs() to
+       `orig_icmp->icmp_id' and `orig->icmp_seq'.
+       * ping/ping6.c (print_echo): Likwise for `icmp6->icmp6_seq'.
+       * ping/ping_address.c (print_address): Apply ntohs() to
+       `icmp->icmp_seq'.
+       * ping/ping_echo.c (print_echo): Likewise.
+       (print_ip_header): Apply ntohs() to `ip->ip_len', `ip->ip_id',
+       `ip->ip_off', and to `ip->ip_sum'.
+       * ping/ping_timestamp.c (print_timestamp): Apply ntohs() to
+       `icmp->icmp_seq'.
+
+2012-05-08  Mats Erik Andersson  <address@hidden>
+
        Use symbolic size names in all harmless cases.
 
        * libicmp/icmp.h (ICMP_TSLEN): Use size of `n_time'.
diff --git a/libicmp/icmp_echo.c b/libicmp/icmp_echo.c
index 30f8c5d..5eb3230 100644
--- a/libicmp/icmp_echo.c
+++ b/libicmp/icmp_echo.c
@@ -42,8 +42,8 @@ icmp_generic_encode (unsigned char * buffer, size_t bufsize, 
int type, int ident
   icmp->icmp_type = type;
   icmp->icmp_code = 0;
   icmp->icmp_cksum = 0;
-  icmp->icmp_seq = seqno;
-  icmp->icmp_id = ident;
+  icmp->icmp_seq = htons (seqno);
+  icmp->icmp_id = htons (ident);
 
   icmp->icmp_cksum = icmp_cksum (buffer, bufsize);
   return 0;
diff --git a/ping/libping.c b/ping/libping.c
index 80c85fa..b847958 100644
--- a/ping/libping.c
+++ b/ping/libping.c
@@ -169,7 +169,7 @@ my_echo_reply (PING * p, icmphdr_t * icmp)
   return (orig_ip->ip_dst.s_addr == p->ping_dest.ping_sockaddr.sin_addr.s_addr
          && orig_ip->ip_p == IPPROTO_ICMP
          && orig_icmp->icmp_type == ICMP_ECHO
-         && orig_icmp->icmp_id == p->ping_ident);
+         && ntohs (orig_icmp->icmp_id) == p->ping_ident);
 }
 
 int
@@ -203,7 +203,7 @@ ping_recv (PING * p)
     case ICMP_ADDRESSREPLY:
       /*    case ICMP_ROUTERADV: */
 
-      if (icmp->icmp_id != p->ping_ident)
+      if (ntohs (icmp->icmp_id) != p->ping_ident)
        return -1;
 
       if (rc)
@@ -211,7 +211,7 @@ ping_recv (PING * p)
                 inet_ntoa (p->ping_from.ping_sockaddr.sin_addr));
 
       p->ping_num_recv++;
-      if (_PING_TST (p, icmp->icmp_seq))
+      if (_PING_TST (p, ntohs (icmp->icmp_seq)))
        {
          p->ping_num_rept++;
          p->ping_num_recv--;
@@ -219,7 +219,7 @@ ping_recv (PING * p)
        }
       else
        {
-         _PING_SET (p, icmp->icmp_seq);
+         _PING_SET (p, ntohs (icmp->icmp_seq));
          dupflag = 0;
        }
 
diff --git a/ping/ping6.c b/ping/ping6.c
index 3fa2e28..54aaac9 100644
--- a/ping/ping6.c
+++ b/ping/ping6.c
@@ -548,7 +548,7 @@ print_echo (int dupflag, int hops, struct ping_stat 
*ping_stat,
     }
 
   printf ("%d bytes from %s: icmp_seq=%u", datalen, buf,
-         htons (icmp6->icmp6_seq));
+         ntohs (icmp6->icmp6_seq));
   if (hops >= 0)
     printf (" ttl=%d", hops);
   if (timing)
@@ -792,7 +792,8 @@ ping_xmit (PING * p)
   icmp6->icmp6_seq = htons (p->ping_num_xmit);
 
   i = sendto (p->ping_fd, (char *) p->ping_buffer, buflen, 0,
-             (struct sockaddr *) &p->ping_dest.ping_sockaddr6, sizeof 
(p->ping_dest.ping_sockaddr6));
+             (struct sockaddr *) &p->ping_dest.ping_sockaddr6,
+             sizeof (p->ping_dest.ping_sockaddr6));
   if (i < 0)
     perror ("ping: sendto");
   else
diff --git a/ping/ping_address.c b/ping/ping_address.c
index e9914f2..fcc0c60 100644
--- a/ping/ping_address.c
+++ b/ping/ping_address.c
@@ -97,7 +97,7 @@ print_address (int dupflag, void *closure,
 
   printf ("%d bytes from %s: icmp_seq=%u", datalen,
          inet_ntoa (*(struct in_addr *) &from->sin_addr.s_addr),
-         icmp->icmp_seq);
+         ntohs (icmp->icmp_seq));
   if (dupflag)
     printf (" (DUP!)");
   printf ("\n");
diff --git a/ping/ping_echo.c b/ping/ping_echo.c
index 5671335..b218e35 100644
--- a/ping/ping_echo.c
+++ b/ping/ping_echo.c
@@ -181,7 +181,7 @@ print_echo (int dupflag, struct ping_stat *ping_stat,
 
   printf ("%d bytes from %s: icmp_seq=%u", datalen,
          inet_ntoa (*(struct in_addr *) &from->sin_addr.s_addr),
-         icmp->icmp_seq);
+         ntohs (icmp->icmp_seq));
   printf (" ttl=%d", ip->ip_ttl);
   if (timing)
     printf (" time=%.3f ms", triptime);
@@ -296,10 +296,10 @@ print_ip_header (struct ip *ip)
   printf
     ("Vr HL TOS  Len   ID Flg  off TTL Pro  cks      Src\tDst\tData\n");
   printf (" %1x  %1x  %02x %04x %04x", ip->ip_v, ip->ip_hl, ip->ip_tos,
-         ip->ip_len, ip->ip_id);
-  printf ("   %1x %04x", ((ip->ip_off) & 0xe000) >> 13,
-         (ip->ip_off) & 0x1fff);
-  printf ("  %02x  %02x %04x", ip->ip_ttl, ip->ip_p, ip->ip_sum);
+         ntohs (ip->ip_len), ntohs (ip->ip_id));
+  printf ("   %1x %04x", (ntohs (ip->ip_off) & 0xe000) >> 13,
+         ntohs (ip->ip_off) & 0x1fff);
+  printf ("  %02x  %02x %04x", ip->ip_ttl, ip->ip_p, ntohs (ip->ip_sum));
   printf (" %s ", inet_ntoa (*((struct in_addr *) &ip->ip_src)));
   printf (" %s ", inet_ntoa (*((struct in_addr *) &ip->ip_dst)));
   while (hlen-- > sizeof (*ip))
diff --git a/ping/ping_timestamp.c b/ping/ping_timestamp.c
index 555d13a..2c50192 100644
--- a/ping/ping_timestamp.c
+++ b/ping/ping_timestamp.c
@@ -95,7 +95,7 @@ print_timestamp (int dupflag, void *closure,
 {
   printf ("%d bytes from %s: icmp_seq=%u", datalen,
          inet_ntoa (*(struct in_addr *) &from->sin_addr.s_addr),
-         icmp->icmp_seq);
+         ntohs (icmp->icmp_seq));
   if (dupflag)
     printf (" (DUP!)");
   printf ("\n");

http://git.savannah.gnu.org/cgit/inetutils.git/commit/?id=cd091aa41b1de362e074a58a638636454c6a0f34


commit cd091aa41b1de362e074a58a638636454c6a0f34
Author: Mats Erik Andersson <address@hidden>
Date:   Tue May 8 18:51:35 2012 +0200

    libicmp, ping: Symbolic sizes. Better diagnostics.

diff --git a/ChangeLog b/ChangeLog
index 32c7712..5851215 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,39 @@
+2012-05-08  Mats Erik Andersson  <address@hidden>
+
+       Use symbolic size names in all harmless cases.
+
+       * libicmp/icmp.h (ICMP_TSLEN): Use size of `n_time'.
+       * libicmp/icmp_address.c (icmp_address_encode): Use ICMP_MASKLEN.
+       * libicmp/icmp_echo.c (icmp_generic_encode): Use ICMP_MINLEN.
+       * libicmp/icmp_timestamp.c (icmp_timestamp_encode): Use ICMP_TSLEN.
+       * ping/libping.c (_ping_packetsize): Use ICMP_TSLEN.  Add cases
+       for ICMP_ADDRESS and ICMP_ADDRESSREPLY.  Use PING_HEADER_LEN in
+       default case.
+       (ping_set_dest) [HAVE_STRUCT_SOCKADDR_SA_LEN]: Set `s_in->sin_len'.
+       * ping/ping_address.c (ping_address): Use ICMP_MASKLEN.
+       * ping/ping_common.h (_ping_setbuf, ping_set_data): Use `use_ipv6'
+       as parameter, not the macro name USE_IPV6.
+       * ping/ping_echo.c (print_echo): Use PING_HEADER_LEN.
+       (print_ip_header): Use `sizeof(*ip)' for IP header size.
+       Use tabs at end of printed header.
+       (print_ip_data): Use IPPROTO_TCP and IPPROTO_UDP.  Add case
+       for IPPROTO_ICMP.
+       * ping/ping_timestamp.c (ping_timestamp): Use ICMP_TSLEN.
+
+       Determine correct and relevant diagnostic messages.
+
+       * ping/ping_echo.c (struct icmp_code_descr): Add field `int type'.
+       (icmp_code_descr): Prepend every member with a type value for
+       correct discrimination.
+       (print_icmp_code): New signature `(int, int, char *)'.  Test `type'
+       as well as `code' when matching.
+       (print_icmp): Update call to print_icmp_code().
+       (icmp_diag): New members ICMP_ROUTERADV and ICMP_ROUTERDISCOVERY.
+       New members ICMP_INFO_REPLY and ICMP_ADDRESS.  Replace incorrect
+       ICMP_MASKREPLY with ICMP_ADDRESSREPLY.
+       (print_ip_opt) <IPOPT_SSRR>: New case.  Code shared with IPOPT_LSRR.
+       <IPOPT_LSRR, IPOPT_RR>: Replace call to ntohl() by correct htonl().
+
 2012-05-07  Mats Erik Andersson  <address@hidden>
 
        Portability issue for setting timeval manually.
diff --git a/libicmp/icmp.h b/libicmp/icmp.h
index 83a1e70..67ce1f0 100644
--- a/libicmp/icmp.h
+++ b/libicmp/icmp.h
@@ -67,7 +67,7 @@ struct icmp_header
 
   union
   {
-    struct id_ts               /* ICMP_TIMESTAMP, ICMP_TIMESTAMP_REPLY */
+    struct id_ts               /* ICMP_TIMESTAMP, ICMP_TIMESTAMPREPLY */
     {
       n_time its_otime;                /* Originate timestamp */
       n_time its_rtime;                /* Recieve timestamp */
@@ -140,7 +140,7 @@ struct icmp_header
 #define MAXIPLEN       60
 #define MAXICMPLEN     76
 #define ICMP_MINLEN    8       /* abs minimum */
-#define ICMP_TSLEN     (8 + 3 * sizeof (unsigned long))        /* timestamp */
+#define ICMP_TSLEN     (8 + 3 * sizeof (n_time))       /* timestamp */
 #define ICMP_MASKLEN   12      /* address mask */
 #define ICMP_ADVLENMIN (8 + sizeof (struct ip) + 8)    /* min */
 #define ICMP_ADVLEN(p) (8 + ((p)->icmp_ip.ip_hl << 2) + 8)
diff --git a/libicmp/icmp_address.c b/libicmp/icmp_address.c
index b02ad15..ef19490 100644
--- a/libicmp/icmp_address.c
+++ b/libicmp/icmp_address.c
@@ -35,7 +35,7 @@ icmp_address_encode (unsigned char * buffer, size_t bufsize, 
int ident, int seqn
 {
   icmphdr_t *icmp;
 
-  if (bufsize < 12)
+  if (bufsize < ICMP_MASKLEN)
     return -1;
 
   icmp = (icmphdr_t *) buffer;
diff --git a/libicmp/icmp_echo.c b/libicmp/icmp_echo.c
index 3a0f108..30f8c5d 100644
--- a/libicmp/icmp_echo.c
+++ b/libicmp/icmp_echo.c
@@ -36,7 +36,7 @@ icmp_generic_encode (unsigned char * buffer, size_t bufsize, 
int type, int ident
 {
   icmphdr_t *icmp;
 
-  if (bufsize < 8)
+  if (bufsize < ICMP_MINLEN)
     return -1;
   icmp = (icmphdr_t *) buffer;
   icmp->icmp_type = type;
diff --git a/libicmp/icmp_timestamp.c b/libicmp/icmp_timestamp.c
index 1857252..caa71fb 100644
--- a/libicmp/icmp_timestamp.c
+++ b/libicmp/icmp_timestamp.c
@@ -39,7 +39,7 @@ icmp_timestamp_encode (unsigned char * buffer, size_t 
bufsize, int ident, int se
   struct timeval tv;
   unsigned long v;
 
-  if (bufsize < 20)
+  if (bufsize < ICMP_TSLEN)
     return -1;
 
   gettimeofday (&tv, NULL);
diff --git a/ping/libping.c b/ping/libping.c
index fcb9e22..80c85fa 100644
--- a/ping/libping.c
+++ b/ping/libping.c
@@ -42,8 +42,12 @@ size_t
 _ping_packetsize (PING * p)
 {
   if (p->ping_type == ICMP_TIMESTAMP || p->ping_type == ICMP_TIMESTAMPREPLY)
-    return 20;
-  return 8 + p->ping_datalen;
+    return ICMP_TSLEN;
+
+  if (p->ping_type == ICMP_ADDRESS || p->ping_type == ICMP_ADDRESSREPLY)
+    return ICMP_MASKLEN;
+
+  return PING_HEADER_LEN + p->ping_datalen;
 }
 
 PING *
@@ -262,6 +266,9 @@ ping_set_dest (PING * ping, char *host)
 {
   struct sockaddr_in *s_in = &ping->ping_dest.ping_sockaddr;
   s_in->sin_family = AF_INET;
+#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
+  s_in->sin_len = sizeof (*s_in);
+#endif
   if (inet_aton (host, &s_in->sin_addr))
     ping->ping_hostname = strdup (host);
   else
diff --git a/ping/ping_address.c b/ping/ping_address.c
index fedc82f..e9914f2 100644
--- a/ping/ping_address.c
+++ b/ping/ping_address.c
@@ -57,7 +57,7 @@ ping_address (char *hostname)
 {
   ping_set_type (ping, ICMP_ADDRESS);
   ping_set_event_handler (ping, recv_address, NULL);
-  ping_set_packetsize (ping, 12);      /* FIXME: constant */
+  ping_set_packetsize (ping, ICMP_MASKLEN);
   ping_set_count (ping, 1);
 
   if (ping_set_dest (ping, hostname))
diff --git a/ping/ping_common.h b/ping/ping_common.h
index 136c2f1..6bb7d15 100644
--- a/ping/ping_common.h
+++ b/ping/ping_common.h
@@ -151,8 +151,8 @@ void init_data_buffer (unsigned char *pat, int len);
 
 void decode_pattern (const char *text, int *pattern_len,
                     unsigned char *pattern_data);
-int _ping_setbuf (PING * p, bool USE_IPV6);
-int ping_set_data (PING *p, void *data, size_t off, size_t len, bool USE_IPV6);
+int _ping_setbuf (PING * p, bool use_ipv6);
+int ping_set_data (PING *p, void *data, size_t off, size_t len, bool use_ipv6);
 void ping_set_count (PING * ping, size_t count);
 void ping_set_sockopt (PING * ping, int opt, void *val, int valsize);
 void ping_set_interval (PING * ping, size_t interval);
diff --git a/ping/ping_echo.c b/ping/ping_echo.c
index f62582b..5671335 100644
--- a/ping/ping_echo.c
+++ b/ping/ping_echo.c
@@ -150,7 +150,7 @@ print_echo (int dupflag, struct ping_stat *ping_stat,
   datalen -= hlen;
 
   /* Do timing */
-  if (PING_TIMING (datalen - 8))
+  if (PING_TIMING (datalen - PING_HEADER_LEN))
     {
       struct timeval tv1, *tp;
 
@@ -235,46 +235,47 @@ struct icmp_diag
 
 struct icmp_code_descr
 {
+  int type;
   int code;
   char *diag;
 } icmp_code_descr[] =
   {
-    {ICMP_NET_UNREACH, "Destination Net Unreachable"},
-    {ICMP_HOST_UNREACH, "Destination Host Unreachable"},
-    {ICMP_PROT_UNREACH, "Destination Protocol Unreachable"},
-    {ICMP_PORT_UNREACH, "Destination Port Unreachable"},
-    {ICMP_FRAG_NEEDED, "Fragmentation needed and DF set"},
-    {ICMP_SR_FAILED, "Source Route Failed"},
-    {ICMP_NET_UNKNOWN, "Network Unknown"},
-    {ICMP_HOST_UNKNOWN, "Host Unknown"},
-    {ICMP_HOST_ISOLATED, "Host Isolated"},
-    {ICMP_NET_UNR_TOS, "Destination Network Unreachable At This TOS"},
-    {ICMP_HOST_UNR_TOS, "Destination Host Unreachable At This TOS"},
+    {ICMP_DEST_UNREACH, ICMP_NET_UNREACH, "Destination Net Unreachable"},
+    {ICMP_DEST_UNREACH, ICMP_HOST_UNREACH, "Destination Host Unreachable"},
+    {ICMP_DEST_UNREACH, ICMP_PROT_UNREACH, "Destination Protocol Unreachable"},
+    {ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, "Destination Port Unreachable"},
+    {ICMP_DEST_UNREACH, ICMP_FRAG_NEEDED, "Fragmentation needed and DF set"},
+    {ICMP_DEST_UNREACH, ICMP_SR_FAILED, "Source Route Failed"},
+    {ICMP_DEST_UNREACH, ICMP_NET_UNKNOWN, "Network Unknown"},
+    {ICMP_DEST_UNREACH, ICMP_HOST_UNKNOWN, "Host Unknown"},
+    {ICMP_DEST_UNREACH, ICMP_HOST_ISOLATED, "Host Isolated"},
+    {ICMP_DEST_UNREACH, ICMP_NET_UNR_TOS, "Destination Network Unreachable At 
This TOS"},
+    {ICMP_DEST_UNREACH, ICMP_HOST_UNR_TOS, "Destination Host Unreachable At 
This TOS"},
 #ifdef ICMP_PKT_FILTERED
-    {ICMP_PKT_FILTERED, "Packet Filtered"},
+    {ICMP_DEST_UNREACH, ICMP_PKT_FILTERED, "Packet Filtered"},
 #endif
 #ifdef ICMP_PREC_VIOLATION
-    {ICMP_PREC_VIOLATION, "Precedence Violation"},
+    {ICMP_DEST_UNREACH, ICMP_PREC_VIOLATION, "Precedence Violation"},
 #endif
 #ifdef ICMP_PREC_CUTOFF
-    {ICMP_PREC_CUTOFF, "Precedence Cutoff"},
+    {ICMP_DEST_UNREACH, ICMP_PREC_CUTOFF, "Precedence Cutoff"},
 #endif
-    {ICMP_REDIR_NET, "Redirect Network"},
-    {ICMP_REDIR_HOST, "Redirect Host"},
-    {ICMP_REDIR_NETTOS, "Redirect Type of Service and Network"},
-    {ICMP_REDIR_HOSTTOS, "Redirect Type of Service and Host"},
-    {ICMP_EXC_TTL, "Time to live exceeded"},
-    {ICMP_EXC_FRAGTIME, "Frag reassembly time exceeded"}
+    {ICMP_REDIRECT, ICMP_REDIR_NET, "Redirect Network"},
+    {ICMP_REDIRECT, ICMP_REDIR_HOST, "Redirect Host"},
+    {ICMP_REDIRECT, ICMP_REDIR_NETTOS, "Redirect Type of Service and Network"},
+    {ICMP_REDIRECT, ICMP_REDIR_HOSTTOS, "Redirect Type of Service and Host"},
+    {ICMP_TIME_EXCEEDED, ICMP_EXC_TTL, "Time to live exceeded"},
+    {ICMP_TIME_EXCEEDED, ICMP_EXC_FRAGTIME, "Frag reassembly time exceeded"}
   };
 
 static void
-print_icmp_code (int code, char *prefix)
+print_icmp_code (int type, int code, char *prefix)
 {
   struct icmp_code_descr *p;
 
   for (p = icmp_code_descr; p < icmp_code_descr + NITEMS (icmp_code_descr);
        p++)
-    if (p->code == code)
+    if (p->type == type && p->code == code)
       {
        printf ("%s\n", p->diag);
        return;
@@ -290,10 +291,10 @@ print_ip_header (struct ip *ip)
   unsigned char *cp;
 
   hlen = ip->ip_hl << 2;
-  cp = (unsigned char *) ip + 20;      /* point to options */
+  cp = (unsigned char *) ip + sizeof (*ip);    /* point to options */
 
   printf
-    ("Vr HL TOS  Len   ID Flg  off TTL Pro  cks      Src      Dst Data\n");
+    ("Vr HL TOS  Len   ID Flg  off TTL Pro  cks      Src\tDst\tData\n");
   printf (" %1x  %1x  %02x %04x %04x", ip->ip_v, ip->ip_hl, ip->ip_tos,
          ip->ip_len, ip->ip_id);
   printf ("   %1x %04x", ((ip->ip_off) & 0xe000) >> 13,
@@ -301,7 +302,7 @@ print_ip_header (struct ip *ip)
   printf ("  %02x  %02x %04x", ip->ip_ttl, ip->ip_p, ip->ip_sum);
   printf (" %s ", inet_ntoa (*((struct in_addr *) &ip->ip_src)));
   printf (" %s ", inet_ntoa (*((struct in_addr *) &ip->ip_dst)));
-  while (hlen-- > 20)
+  while (hlen-- > sizeof (*ip))
     printf ("%02x", *cp++);
 
   printf ("\n");
@@ -319,19 +320,30 @@ print_ip_data (icmphdr_t * icmp, void *data)
   hlen = ip->ip_hl << 2;
   cp = (unsigned char *) ip + hlen;
 
-  if (ip->ip_p == 6)
+  if (ip->ip_p == IPPROTO_TCP)
     printf ("TCP: from port %u, to port %u (decimal)\n",
            (*cp * 256 + *(cp + 1)), (*(cp + 2) * 256 + *(cp + 3)));
-  else if (ip->ip_p == 17)
+  else if (ip->ip_p == IPPROTO_UDP)
     printf ("UDP: from port %u, to port %u (decimal)\n",
            (*cp * 256 + *(cp + 1)), (*(cp + 2) * 256 + *(cp + 3)));
-
+  else if (ip->ip_p == IPPROTO_ICMP)
+    {
+      int type = *cp;
+      int code = *(cp + 1);
+
+      printf ("ICMP: type %u, code %u, size %u", type, code,
+             ntohs (ip->ip_len) - hlen);
+      if (type == ICMP_ECHOREPLY || type == ICMP_ECHO)
+       printf (", id 0x%04x, seq 0x%04x", *(cp + 4) * 256 + *(cp + 5),
+               *(cp + 6) * 256 + *(cp + 7));
+      printf ("\n");
+    }
 }
 
 static void
 print_icmp (icmphdr_t * icmp, void *data)
 {
-  print_icmp_code (icmp->icmp_code, data);
+  print_icmp_code (icmp->icmp_type, icmp->icmp_code, data);
   print_ip_data (icmp, NULL);
 }
 
@@ -349,14 +361,16 @@ struct icmp_diag icmp_diag[] = {
   {ICMP_SOURCE_QUENCH, "Source Quench", print_ip_data},
   {ICMP_REDIRECT, NULL, print_icmp, "Redirect"},
   {ICMP_ECHO, "Echo Request", NULL},
+  {ICMP_ROUTERADV, "Router Advertisment", NULL},
+  {ICMP_ROUTERDISCOVERY, "Router Discovery", NULL},
   {ICMP_TIME_EXCEEDED, NULL, print_icmp, "Time exceeded"},
   {ICMP_PARAMETERPROB, NULL, print_parameterprob},
   {ICMP_TIMESTAMP, "Timestamp", NULL},
   {ICMP_TIMESTAMPREPLY, "Timestamp Reply", NULL},
   {ICMP_INFO_REQUEST, "Information Request", NULL},
-#ifdef ICMP_MASKREQ
-  {ICMP_MASKREPLY, "Address Mask Reply", NULL},
-#endif
+  {ICMP_INFO_REPLY, "Information Reply", NULL},
+  {ICMP_ADDRESS, "Address Mask Request", NULL},
+  {ICMP_ADDRESSREPLY, "Address Mask Reply", NULL},
 };
 
 void
@@ -412,13 +426,15 @@ print_ip_opt (struct ip *ip, int hlen)
        break;
 
       case IPOPT_LSRR:
-       printf ("\nLSRR: ");
+      case IPOPT_SSRR:
+       printf ("\n%cSRR: ", (*cp == IPOPT_LSRR) ? 'L' : 'S');
        hlen -= 2;
        j = *++cp;
        ++cp;
        if (j > IPOPT_MINOFF)
          for (;;)
            {
+             /* Fetch in network byte order, calculate as host.  */
              l = *++cp;
              l = (l << 8) + *++cp;
              l = (l << 8) + *++cp;
@@ -432,7 +448,7 @@ print_ip_opt (struct ip *ip, int hlen)
                  struct in_addr ina;
                  char *s;
 
-                 ina.s_addr = ntohl (l);
+                 ina.s_addr = htonl (l);
                  printf ("\t%s", s = ipaddr2str (ina));
                  free (s);
                }
@@ -475,6 +491,7 @@ print_ip_opt (struct ip *ip, int hlen)
        j = 0;
        for (;;)
          {
+           /* Fetch in network byte order, calculate as host.  */
            l = *++cp;
            l = (l << 8) + *++cp;
            l = (l << 8) + *++cp;
@@ -488,7 +505,7 @@ print_ip_opt (struct ip *ip, int hlen)
                struct in_addr ina;
                char *s;
 
-               ina.s_addr = ntohl (l);
+               ina.s_addr = htonl (l);
                printf ("\t%s", s = ipaddr2str (ina));
                free (s);
              }
diff --git a/ping/ping_timestamp.c b/ping/ping_timestamp.c
index 7793840..555d13a 100644
--- a/ping/ping_timestamp.c
+++ b/ping/ping_timestamp.c
@@ -57,7 +57,7 @@ ping_timestamp (char *hostname)
 {
   ping_set_type (ping, ICMP_TIMESTAMP);
   ping_set_event_handler (ping, recv_timestamp, NULL);
-  ping_set_packetsize (ping, 20);
+  ping_set_packetsize (ping, ICMP_TSLEN);
 
   if (ping_set_dest (ping, hostname))
     error (EXIT_FAILURE, 0, "unknown host");

http://git.savannah.gnu.org/cgit/inetutils.git/commit/?id=1dc2e02ed08308ab0eb48460dcfc98fdfcc64d4e


commit 1dc2e02ed08308ab0eb48460dcfc98fdfcc64d4e
Author: Mats Erik Andersson <address@hidden>
Date:   Tue May 8 18:48:29 2012 +0200

    ping, ping6, traceroute: Portability and regression.

diff --git a/ChangeLog b/ChangeLog
index c9c12dd..32c7712 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+2012-05-07  Mats Erik Andersson  <address@hidden>
+
+       Portability issue for setting timeval manually.
+
+       * ping/ping.c (ping_run): Erase RESP_TIME, INTVL, and NOW
+       before first use.
+       * ping/ping6.c (ping_run): Likewise.  Do not erase RESP_TIME
+       inside loop.
+
+       Regression in calculating response timing.
+
+       * src/traceroute.c (do_try): Use format string ` %2d ' with HOP.
+       New variable SAVE_ERRNO.  Call select() before gettimeofday(),
+       but save `errno' in SAVE_ERRNO.  Take care of microsecond
+       underflow when calculating time difference.
+       (trace_read): Replace numerical size by `sizeof (data)'.
+
 2012-04-27  Mats Erik Andersson  <address@hidden>
 
        * ping/ping_address.c (print_address): Remove duplicate
diff --git a/ping/ping.c b/ping/ping.c
index 462cc22..a9b2ad6 100644
--- a/ping/ping.c
+++ b/ping/ping.c
@@ -330,6 +330,14 @@ ping_run (PING * ping, int (*finish) ())
 
   fdmax = ping->ping_fd + 1;
 
+  /* Some systems use `struct timeval' of size 16.  As these are
+   * not initialising `timeval' properly by assignment alone, let
+   * us play safely here.  gettimeofday() is always sufficient.
+   */
+  memset (&resp_time, 0, sizeof (resp_time));
+  memset (&intvl, 0, sizeof (intvl));
+  memset (&now, 0, sizeof (now));
+
   for (i = 0; i < preload; i++)
     send_echo (ping);
 
diff --git a/ping/ping6.c b/ping/ping6.c
index 445ced8..3fa2e28 100644
--- a/ping/ping6.c
+++ b/ping/ping6.c
@@ -284,6 +284,14 @@ ping_run (PING * ping, int (*finish) ())
 
   fdmax = ping->ping_fd + 1;
 
+  /* Some systems use `struct timeval' of size 16.  As these are
+   * not initialising `timeval' properly by assignment alone, let
+   * us play safely here.  gettimeofday() is always sufficient.
+   */
+  memset (&resp_time, 0, sizeof (resp_time));
+  memset (&intvl, 0, sizeof (intvl));
+  memset (&now, 0, sizeof (now));
+
   for (i = 0; i < preload; i++)
     send_echo (ping);
 
@@ -304,8 +312,8 @@ ping_run (PING * ping, int (*finish) ())
 
       FD_ZERO (&fdset);
       FD_SET (ping->ping_fd, &fdset);
+
       gettimeofday (&now, NULL);
-      memset (&resp_time, 0, sizeof (resp_time));      /* 64-bit issue */
       resp_time.tv_sec = last.tv_sec + intvl.tv_sec - now.tv_sec;
       resp_time.tv_usec = last.tv_usec + intvl.tv_usec - now.tv_usec;
 
diff --git a/src/traceroute.c b/src/traceroute.c
index df17661..44128b9 100644
--- a/src/traceroute.c
+++ b/src/traceroute.c
@@ -236,10 +236,11 @@ do_try (trace_t * trace, const int hop,
   double triptime = 0.0;
   uint32_t prev_addr = 0;
 
-  printf (" %d  ", hop);
+  printf (" %2d  ", hop);
 
   for (tries = 0; tries < max_tries; tries++)
     {
+      int save_errno;
       int fd = trace_icmp_sock (trace);
 
       FD_ZERO (&readset);
@@ -252,17 +253,23 @@ do_try (trace_t * trace, const int hop,
       if (!readonly)
        trace_write (trace);
 
+      errno = 0;
+      ret = select (fd + 1, &readset, NULL, NULL, &time);
+      save_errno = errno;
+
       gettimeofday (&now, NULL);
 
       now.tv_usec -= trace->tsent.tv_usec;
       now.tv_sec -= trace->tsent.tv_sec;
-
-      errno = 0;
-      ret = select (fd + 1, &readset, NULL, NULL, &time);
+      if (now.tv_usec < 0)
+       {
+         --now.tv_sec;
+         now.tv_usec += 1000000;
+       }
 
       if (ret < 0)
        {
-         switch (errno)
+         switch (save_errno)
            {
            case EINTR:
              /* was interrupted */
@@ -398,12 +405,12 @@ trace_read (trace_t * t)
 
   siz = sizeof (t->from);
 
-  len = recvfrom (t->icmpfd, (char *) data, 56, 0,
+  len = recvfrom (t->icmpfd, (char *) data, sizeof (data), 0,
                  (struct sockaddr *) &t->from, &siz);
   if (len < 0)
     error (EXIT_FAILURE, errno, "recvfrom");
 
-  icmp_generic_decode (data, 56, &ip, &ic);
+  icmp_generic_decode (data, sizeof (data), &ip, &ic);
 
   switch (t->type)
     {

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

Summary of changes:
 ChangeLog                |   87 +++++++++++++++++++++++++++++++++++++++
 libicmp/icmp.h           |    4 +-
 libicmp/icmp_address.c   |    2 +-
 libicmp/icmp_echo.c      |    6 +-
 libicmp/icmp_timestamp.c |    2 +-
 ping/libping.c           |   19 ++++++---
 ping/ping.c              |   12 +++++-
 ping/ping6.c             |   21 +++++++---
 ping/ping_address.c      |    4 +-
 ping/ping_common.h       |   12 +++---
 ping/ping_echo.c         |  101 ++++++++++++++++++++++++++-------------------
 ping/ping_timestamp.c    |    4 +-
 src/traceroute.c         |   21 ++++++---
 13 files changed, 214 insertions(+), 81 deletions(-)


hooks/post-receive
-- 
GNU Inetutils 



reply via email to

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