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-91-g5893d2


From: Mats Erik Andersson
Subject: [SCM] GNU Inetutils branch, master, updated. inetutils-1_9_1-91-g5893d2e
Date: Fri, 11 May 2012 15:39:10 +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  5893d2ec601754a03e8cd5e5fa059966c769224a (commit)
      from  8aebed791231ca1e2fb20588f929d97f6b894fdc (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=5893d2ec601754a03e8cd5e5fa059966c769224a


commit 5893d2ec601754a03e8cd5e5fa059966c769224a
Author: Mats Erik Andersson <address@hidden>
Date:   Fri May 11 17:37:14 2012 +0200

    traceroute: Identity and sequence.
    
    Set dynamic identity and use running sequence number
    for every sent packet.  This improves reliability.

diff --git a/ChangeLog b/ChangeLog
index 0ad7cb9..969822b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2012-05-11  Mats Erik Andersson  <address@hidden>
+
+       traceroute: Dynamic identity and sequence numbers.
+
+       * src/traceroute.c (seqno): New variable.
+       (main): Assign getpid() to `pid'.  Initialise `seqno'.
+       (trace_read) <TRACE_UDP>: Replace numerical offset `11'.
+       (trace_read) <TRACE_ICMP && ICMP_ECHOREPLY>: Apply ntohs()
+       to `ic->icmp_seq' and to `ic->icmp_id'.
+       <TRACE_ICMP && ICMP_TIME_EXCEEDED>: Complete code rewrite.
+       (trace_write): Activate dynamic `pid' and `seqno' in call to
+       icmp_echo_encode().
+
 2012-05-10  Mats Erik Andersson  <address@hidden>
 
        Refactor address-to-string conversion as common code.
diff --git a/src/traceroute.c b/src/traceroute.c
index 44128b9..cc9abb5 100644
--- a/src/traceroute.c
+++ b/src/traceroute.c
@@ -88,7 +88,8 @@ void do_try (trace_t * trace, const int hop,
 char *get_hostname (struct in_addr *addr);
 
 int stop = 0;
-int pid = 0;
+int pid;
+int seqno;     /* Most recent sequence number.  */
 static char *hostname = NULL;
 char addrstr[INET6_ADDRSTRLEN];
 struct sockaddr_in dest;
@@ -181,11 +182,14 @@ static struct argp argp = {argp_options, parse_opt, 
args_doc, doc};
 int
 main (int argc, char **argv)
 {
+  int hop;
   struct addrinfo hints, *res;
   trace_t trace;
 
   set_program_name (argv[0]);
 
+  pid = getpid();
+
   /* Parse command line */
   iu_argp_init ("traceroute", program_authors);
   argp_parse (&argp, argc, argv, 0, NULL, NULL);
@@ -212,7 +216,9 @@ main (int argc, char **argv)
 
   trace_init (&trace, dest, opt_type);
 
-  int hop = 1;
+  hop = 1;
+  seqno = -1;  /* One less than first usable packet number 0.  */
+
   while (!stop)
     {
       if (hop > opt_max_hops)
@@ -424,8 +430,9 @@ trace_read (trace_t * t)
          return -1;
 
        /* check whether it's for us */
-        port = (unsigned short *) &ic->icmp_ip + 11;
-       if (*port != t->to.sin_port)
+        port = (unsigned short *) ((void *) &ic->icmp_ip +
+                       sizeof (struct ip) + sizeof (in_port_t));
+       if (*port != t->to.sin_port)    /* Network byte order!  */
          return -1;
 
        if (ic->icmp_code == ICMP_PORT_UNREACH)
@@ -440,13 +447,21 @@ trace_read (trace_t * t)
        return -1;
 
       if (ic->icmp_type == ICMP_ECHOREPLY
-         && (ic->icmp_seq != pid || ic->icmp_id != pid))
+         && (ntohs (ic->icmp_seq) != seqno
+             || ntohs (ic->icmp_id) != pid))
        return -1;
       else if (ic->icmp_type == ICMP_TIME_EXCEEDED)
        {
-         unsigned short *seq = (unsigned short *) &ic->icmp_ip + 12;
-         unsigned short *ident = (unsigned short *) &ic->icmp_ip + 13;
-         if (*seq != pid || *ident != pid)
+         unsigned short seq, ident;
+         struct ip *old_ip;
+         icmphdr_t *old_icmp;
+
+         old_ip = (struct ip *) &ic->icmp_ip;
+         old_icmp = (icmphdr_t *) ((void *) old_ip + sizeof (struct ip));
+         seq = ntohs (old_icmp->icmp_seq);
+         ident = ntohs (old_icmp->icmp_id);
+
+         if (seq != seqno || ident != pid)
            return -1;
        }
 
@@ -497,8 +512,10 @@ trace_write (trace_t * t)
     case TRACE_ICMP:
       {
        icmphdr_t hdr;
-       /* FIXME: We could use the pid as the icmp seqno/ident. */
-       if (icmp_echo_encode ((unsigned char *) &hdr, sizeof (hdr), pid, pid))
+
+       /* The sequence number is updated to a valid value!  */
+       if (icmp_echo_encode ((unsigned char *) &hdr, sizeof (hdr),
+                             pid, ++seqno))
          return -1;
 
        len = sendto (t->icmpfd, (char *) &hdr, sizeof (hdr),

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

Summary of changes:
 ChangeLog        |   13 +++++++++++++
 src/traceroute.c |   37 +++++++++++++++++++++++++++----------
 2 files changed, 40 insertions(+), 10 deletions(-)


hooks/post-receive
-- 
GNU Inetutils 



reply via email to

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