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-90-g8aebed


From: Mats Erik Andersson
Subject: [SCM] GNU Inetutils branch, master, updated. inetutils-1_9_1-90-g8aebed7
Date: Thu, 10 May 2012 21:38:27 +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  8aebed791231ca1e2fb20588f929d97f6b894fdc (commit)
       via  dd74888217cc86866ba4f14a9d7415d305f0c44b (commit)
      from  d2474314ec95d196af43aae5484e4a2c6073308d (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=8aebed791231ca1e2fb20588f929d97f6b894fdc


commit 8aebed791231ca1e2fb20588f929d97f6b894fdc
Author: Mats Erik Andersson <address@hidden>
Date:   Thu May 10 23:33:06 2012 +0200

    ping, ping6: Refactor common resolver.

diff --git a/ChangeLog b/ChangeLog
index 6aa0834..0ad7cb9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,21 @@
 2012-05-10  Mats Erik Andersson  <address@hidden>
 
+       Refactor address-to-string conversion as common code.
+
+       * ping/ping6.c (options): Remove qualifier `static'.
+       (ipaddr2str): Removed function.
+       (print_icmp_error): Call ipaddr2str() with new signature.
+       * ping/ping_common.c: Include <errno.h>, <netinet/in.h>,
+       <arpa/inet.h>, and <netdb.h>.
+       (options): New external variable.
+       (ipaddr2str, sinaddr2str): New functions.
+       * ping/ping_common.h (ipaddr2str, sinaddr2str): New prototypes.
+       * ping/ping_echo.c (ipaddr2str): Removed function.
+       (print_icmp_header): Call ipaddr2str() with new signature.
+       (print_ip_opt): Replace ipaddr2str() with sinaddr2str().
+
+2012-05-10  Mats Erik Andersson  <address@hidden>
+
        * ping/ping6.c (argp_options): New option `verbose'.
        (parse_opt) <v>: New case.
        (ping_echo): Print identity in verbose mode.
diff --git a/ping/ping6.c b/ping/ping6.c
index 1848e2a..d432af4 100644
--- a/ping/ping6.c
+++ b/ping/ping6.c
@@ -58,7 +58,7 @@ size_t interval;
 int socket_type;
 int timeout = -1;
 int hoplimit = 0;
-static unsigned int options;
+unsigned int options;
 static unsigned long preload = 0;
 
 static int ping_echo (char *hostname);
@@ -242,44 +242,6 @@ main (int argc, char **argv)
   return status;
 }
 
-static char *
-ipaddr2str (struct sockaddr_in6 *from)
-{
-  int err;
-  size_t len;
-  char *buf, ipstr[256], hoststr[256];
-
-  err = getnameinfo ((struct sockaddr *) from, sizeof (*from), ipstr,
-                    sizeof (ipstr), NULL, 0, NI_NUMERICHOST);
-  if (err)
-    {
-      const char *errmsg;
-
-      if (err == EAI_SYSTEM)
-       errmsg = strerror (errno);
-      else
-       errmsg = gai_strerror (err);
-
-      fprintf (stderr, "ping: getnameinfo: %s\n", errmsg);
-      return xstrdup ("unknown");
-    }
-
-  if (options & OPT_NUMERIC)
-    return xstrdup (ipstr);
-
-  err = getnameinfo ((struct sockaddr *) from, sizeof (*from), hoststr,
-                    sizeof (hoststr), NULL, 0, NI_NAMEREQD);
-  if (err)
-    return xstrdup (ipstr);
-
-  len = strlen (ipstr) + strlen (hoststr) + 4; /* Pair of parentheses, a space
-                                                  and a NUL. */
-  buf = xmalloc (len);
-  sprintf (buf, "%s (%s)", hoststr, ipstr);
-
-  return buf;
-}
-
 static volatile int stop = 0;
 
 static void
@@ -692,7 +654,7 @@ print_icmp_error (struct sockaddr_in6 *from, struct 
icmp6_hdr *icmp6, int len)
   char *s;
   struct icmp_diag *p;
 
-  s = ipaddr2str (from);
+  s = ipaddr2str ((struct sockaddr *) from, sizeof (*from));
   printf ("%d bytes from %s: ", len, s);
   free (s);
 
diff --git a/ping/ping_common.c b/ping/ping_common.c
index 58bb22f..8f2fcf9 100644
--- a/ping/ping_common.c
+++ b/ping/ping_common.c
@@ -25,6 +25,10 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
+#include <errno.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <netdb.h>
 #include <xalloc.h>
 
 #include "ping_common.h"
@@ -33,6 +37,7 @@ extern unsigned char *data_buffer;
 extern size_t data_length;
 
 static void _ping_freebuf (PING * p);
+extern unsigned int options;
 
 size_t
 ping_cvt_number (const char *optarg, size_t maxval, int allow_zero)
@@ -248,3 +253,72 @@ ping_timeout_p (struct timeval *start_time, int timeout)
     }
   return 0;
 }
+
+char *
+ipaddr2str (struct sockaddr *from, socklen_t fromlen)
+{
+  int err;
+  size_t len;
+  char *buf, ipstr[INET6_ADDRSTRLEN], hoststr[256];
+
+  err = getnameinfo (from, fromlen, ipstr, sizeof (ipstr),
+                    NULL, 0, NI_NUMERICHOST);
+  if (err)
+    {
+      const char *errmsg;
+
+      if (err == EAI_SYSTEM)
+       errmsg = strerror (errno);
+      else
+       errmsg = gai_strerror (err);
+
+      fprintf (stderr, "ping: getnameinfo: %s\n", errmsg);
+      return xstrdup ("unknown");
+    }
+
+  if (options & OPT_NUMERIC)
+    return xstrdup (ipstr);
+
+  err = getnameinfo (from, fromlen, hoststr, sizeof (hoststr),
+                    NULL, 0, NI_NAMEREQD);
+  if (err)
+    return xstrdup (ipstr);
+
+  len = strlen (ipstr) + strlen (hoststr) + 4; /* Pair of parentheses, a space
+                                                  and a NUL. */
+  buf = xmalloc (len);
+  snprintf (buf, len, "%s (%s)", hoststr, ipstr);
+
+  return buf;
+}
+
+char *
+sinaddr2str (struct in_addr ina)
+{
+  struct hostent *hp;
+
+  if (options & OPT_NUMERIC)
+    return xstrdup (inet_ntoa (ina));
+
+  hp = gethostbyaddr ((char *) &ina, sizeof (ina), AF_INET);
+  if (hp == NULL)
+    return xstrdup (inet_ntoa (ina));
+  else
+    {
+      char *buf, *ipstr;
+      int len;
+
+      ipstr = inet_ntoa (ina);
+      len = strlen (ipstr) + 1;
+
+      if (hp->h_name)
+       len += strlen (hp->h_name) + 4; /* parentheses, space, and NUL */
+
+      buf = xmalloc (len);
+      if (hp->h_name)
+       snprintf (buf, len, "%s (%s)", hp->h_name, ipstr);
+      else
+       snprintf (buf, len, "%s", ipstr);
+      return buf;
+    }
+}
diff --git a/ping/ping_common.h b/ping/ping_common.h
index ee86a00..fcda0be 100644
--- a/ping/ping_common.h
+++ b/ping/ping_common.h
@@ -160,3 +160,6 @@ void ping_set_sockopt (PING * ping, int opt, void *val, int 
valsize);
 void ping_set_interval (PING * ping, size_t interval);
 void ping_unset_data (PING * p);
 int ping_timeout_p (struct timeval *start_time, int timeout);
+
+char * ipaddr2str (struct sockaddr *from, socklen_t fromlen);
+char * sinaddr2str (struct in_addr ina);
diff --git a/ping/ping_echo.c b/ping/ping_echo.c
index a401820..cc3445a 100644
--- a/ping/ping_echo.c
+++ b/ping/ping_echo.c
@@ -196,35 +196,6 @@ print_echo (int dupflag, struct ping_stat *ping_stat,
   return 0;
 }
 
-char *
-ipaddr2str (struct in_addr ina)
-{
-  struct hostent *hp;
-
-  if (options & OPT_NUMERIC)
-    return xstrdup (inet_ntoa (ina));
-
-  hp = gethostbyaddr ((char *) &ina, sizeof (ina), AF_INET);
-  if (hp == NULL)
-    return xstrdup (inet_ntoa (ina));
-  else
-    {
-      char *ipstr = inet_ntoa (ina);
-      int len = strlen (ipstr) + 1;
-      char *buf;
-
-      if (hp->h_name)
-       len += strlen (hp->h_name) + 3; /* a pair of parentheses and a space */
-
-      buf = xmalloc (len);
-      if (hp->h_name)
-       snprintf (buf, len, "%s (%s)", hp->h_name, ipstr);
-      else
-       snprintf (buf, len, "%s", ipstr);
-      return buf;
-    }
-}
-
 #define NITEMS(a) sizeof(a)/sizeof((a)[0])
 
 struct icmp_diag
@@ -404,7 +375,8 @@ print_icmp_header (struct sockaddr_in *from,
        || orig_ip->ip_dst.s_addr == 
ping->ping_dest.ping_sockaddr.sin_addr.s_addr))
     return;
 
-  printf ("%d bytes from %s: ", len - hlen, s = ipaddr2str (from->sin_addr));
+  s = ipaddr2str ((struct sockaddr *) from, sizeof (*from));
+  printf ("%d bytes from %s: ", len - hlen, s);
   free (s);
 
   for (p = icmp_diag; p < icmp_diag + NITEMS (icmp_diag); p++)
@@ -462,7 +434,7 @@ print_ip_opt (struct ip *ip, int hlen)
                  char *s;
 
                  ina.s_addr = htonl (l);
-                 printf ("\t%s", s = ipaddr2str (ina));
+                 printf ("\t%s", s = sinaddr2str (ina));
                  free (s);
                }
              hlen -= 4;
@@ -519,7 +491,7 @@ print_ip_opt (struct ip *ip, int hlen)
                char *s;
 
                ina.s_addr = htonl (l);
-               printf ("\t%s", s = ipaddr2str (ina));
+               printf ("\t%s", s = sinaddr2str (ina));
                free (s);
              }
            hlen -= 4;

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


commit dd74888217cc86866ba4f14a9d7415d305f0c44b
Author: Mats Erik Andersson <address@hidden>
Date:   Thu May 10 23:30:31 2012 +0200

    ping, ping6: Additional verbosity.

diff --git a/ChangeLog b/ChangeLog
index ec999ff..6aa0834 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2012-05-10  Mats Erik Andersson  <address@hidden>
+
+       * ping/ping6.c (argp_options): New option `verbose'.
+       (parse_opt) <v>: New case.
+       (ping_echo): Print identity in verbose mode.
+       * ping/ping_echo.c (ping_echo): Likewise.
+       (print_ip_header): Print IP header dump in verbose mode.
+
 2012-05-09  Mats Erik Andersson  <address@hidden>
 
        ping: Options `--mask' and `--ttl'.
diff --git a/ping/ping6.c b/ping/ping6.c
index 8358e7b..1848e2a 100644
--- a/ping/ping6.c
+++ b/ping/ping6.c
@@ -90,6 +90,7 @@ static struct argp_option argp_options[] = {
   {"ignore-routing", 'r', NULL, 0, "send directly to a host on an attached "
    "network", GRP+1},
   {"timeout", 'w', "N", 0, "stop after N seconds", GRP+1},
+  {"verbose", 'v', NULL, 0, "verbose output", GRP+1},
 #undef GRP
 #define GRP 10
   {NULL, 0, NULL, 0, "Options valid for --echo requests:", GRP},
@@ -160,14 +161,18 @@ parse_opt (int key, char *arg, struct argp_state *state)
       socket_type |= SO_DONTROUTE;
       break;
 
-    case 'w':
-      timeout = ping_cvt_number (arg, INT_MAX, 0);
-      break;
-
     case 's':
       data_length = ping_cvt_number (arg, PING_MAX_DATALEN, 1);
       break;
 
+    case 'v':
+      options |= OPT_VERBOSE;
+      break;
+
+    case 'w':
+      timeout = ping_cvt_number (arg, INT_MAX, 0);
+      break;
+
     case ARG_HOPLIMIT:
       hoplimit = ping_cvt_number (arg, 255, 0);
       break;
@@ -486,8 +491,12 @@ ping_echo (char *hostname)
       error (EXIT_FAILURE, 0, "getnameinfo: %s", errmsg);
     }
 
-  printf ("PING %s (%s): %d data bytes\n",
+  printf ("PING %s (%s): %d data bytes",
          ping->ping_hostname, buffer, data_length);
+  if (options & OPT_VERBOSE)
+    printf (", id 0x%04x = %u", ping->ping_ident, ping->ping_ident);
+
+  printf ("\n");
 
   status = ping_run (ping, echo_finish);
   free (ping->ping_hostname);
@@ -670,16 +679,12 @@ static struct icmp_diag
 {
   int type;
   void (*func) (struct icmp6_hdr *);
-} icmp_diag[] =
-{
-  {
-  ICMP6_DST_UNREACH, print_dst_unreach},
-  {
-  ICMP6_PACKET_TOO_BIG, print_packet_too_big},
-  {
-  ICMP6_TIME_EXCEEDED, print_time_exceeded},
-  {
-ICMP6_PARAM_PROB, print_param_prob},};
+} icmp_diag[] = {
+  {ICMP6_DST_UNREACH, print_dst_unreach},
+  {ICMP6_PACKET_TOO_BIG, print_packet_too_big},
+  {ICMP6_TIME_EXCEEDED, print_time_exceeded},
+  {ICMP6_PARAM_PROB, print_param_prob},
+};
 
 static void
 print_icmp_error (struct sockaddr_in6 *from, struct icmp6_hdr *icmp6, int len)
diff --git a/ping/ping_echo.c b/ping/ping_echo.c
index 870d685..a401820 100644
--- a/ping/ping_echo.c
+++ b/ping/ping_echo.c
@@ -101,9 +101,13 @@ ping_echo (char *hostname)
 #endif /* IP_OPTIONS */
     }
 
-  printf ("PING %s (%s): %d data bytes\n",
+  printf ("PING %s (%s): %d data bytes",
          ping->ping_hostname,
          inet_ntoa (ping->ping_dest.ping_sockaddr.sin_addr), data_length);
+  if (options & OPT_VERBOSE)
+    printf (", id 0x%04x = %u", ping->ping_ident, ping->ping_ident);
+
+  printf ("\n");
 
   status = ping_run (ping, echo_finish);
   free (ping->ping_hostname);
@@ -291,6 +295,17 @@ print_ip_header (struct ip *ip)
   hlen = ip->ip_hl << 2;
   cp = (unsigned char *) ip + sizeof (*ip);    /* point to options */
 
+  if (options & OPT_VERBOSE)
+    {
+      int j;
+
+      printf ("IP Hdr Dump:\n ");
+      for (j = 0; j < sizeof (*ip); ++j)
+       printf ("%02x%s", *((unsigned char *) ip + j),
+               (j % 2) ? " " : "");    /* Group bytes two by two.  */
+      printf ("\n");
+    }
+
   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,

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

Summary of changes:
 ChangeLog          |   24 ++++++++++++++++
 ping/ping6.c       |   77 +++++++++++++++-------------------------------------
 ping/ping_common.c |   74 +++++++++++++++++++++++++++++++++++++++++++++++++
 ping/ping_common.h |    3 ++
 ping/ping_echo.c   |   53 +++++++++++++----------------------
 5 files changed, 143 insertions(+), 88 deletions(-)


hooks/post-receive
-- 
GNU Inetutils 



reply via email to

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