A regression is caused by the original patch in this thread.
Please check very carefully that I have managed to handle Git
correctly now, when mending this matter.

söndag den 31 oktober 2010 klockan 16:03 skrev Alfred M. Szmidt detta:
> Applied!
> 
> 2010-10-31  Mats Erik Andersson  <[email protected]>
> 
>       traceroute: Pass integer values to IP_TTL option.
> 
>       * src/traceroute.c (trace_init): Renamed TTLP to TTL, and changed
>       type to `int'.
>       (trace_inc_ttl): Likewise.

The problem is that the intermediary hosts are no longer
put on display. The original code used a pointer TTLP
and updated the target of that pointer. The changes
introduced in the previous patch did not observe this.

The optimal solution is simply to transform the old
element `ttl' in `struct trace' from

    unsigned char ttl

to 

    int ttl

and hence change later uses of

    const unsigned char *ttlp

to

    const int *ttlp

For better maintainability all three calls to setsockopt(3) now
use `sizeof (*ttlp)' instead of the semi-obscure `sizeof (t->ttl)'.


Regards,

Mats
From 14c9ff4d93af833a6d81db6c7d4e3ef673f38daf Mon Sep 17 00:00:00 2001
From: Mats Erik Andersson <[email protected]>
Date: Thu, 4 Nov 2010 00:52:06 +0100
Subject: [PATCH] src/traceroute: Revert and correct previous change.

---
 ChangeLog        |   10 ++++++++++
 src/traceroute.c |   18 +++++++++---------
 2 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index f757a82..18510d4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2010-11-04  Mats Erik Andersson <[email protected]>
+
+	Regression caused by fe539ae9...797d881c
+
+	* src/traceroute.c: Revert change from 2010-10-31.
+	Change element `ttl' in `struct trace' to be plain `int'.
+	(trace_init): Change type of TTLP to be `const int *'.
+	Use `sizeof (*ttlp)' in both calls to setsockopt.
+	(trace_inc_ttl): Likewise.
+
 2010-10-31  Mats Erik Andersson <[email protected]>
 
 	* ifconfig/if_index.c (if_nametoindex, if_freenameindex)
diff --git a/src/traceroute.c b/src/traceroute.c
index f79e747..432e6e1 100644
--- a/src/traceroute.c
+++ b/src/traceroute.c
@@ -64,7 +64,7 @@ typedef struct trace
   int icmpfd, udpfd;
   enum trace_type type;
   struct sockaddr_in to, from;
-  unsigned char ttl;
+  int ttl;
   struct timeval tsent;
 } trace_t;
 
@@ -311,9 +311,9 @@ void
 trace_init (trace_t * t, const struct sockaddr_in to,
 	    const enum trace_type type)
 {
-  int ttl;
+  const int *ttlp;
   assert (t);
-  ttl = t->ttl;
+  ttlp = &t->ttl;
 
   t->type = type;
   t->to = to;
@@ -325,8 +325,8 @@ trace_init (trace_t * t, const struct sockaddr_in to,
       if (t->udpfd < 0)
         error (EXIT_FAILURE, errno, "socket");
 
-      if (setsockopt (t->udpfd, IPPROTO_IP, IP_TTL, &ttl,
-		      sizeof (ttl)) < 0)
+      if (setsockopt (t->udpfd, IPPROTO_IP, IP_TTL, ttlp,
+		      sizeof (*ttlp)) < 0)
         error (EXIT_FAILURE, errno, "setsockopt");
     }
 
@@ -340,7 +340,7 @@ trace_init (trace_t * t, const struct sockaddr_in to,
             error (EXIT_FAILURE, errno, "socket");
 
 	  if (setsockopt (t->icmpfd, IPPROTO_IP, IP_TTL,
-			  &ttl, sizeof (ttl)) < 0)
+			  ttlp, sizeof (*ttlp)) < 0)
             error (EXIT_FAILURE, errno, "setsockopt");
 	}
       else
@@ -520,14 +520,14 @@ void
 trace_inc_ttl (trace_t * t)
 {
   int fd;
-  int ttl;
+  const int *ttlp;
 
   assert (t);
 
-  ttl = t->ttl;
+  ttlp = &t->ttl;
   t->ttl++;
   fd = (t->type == TRACE_UDP ? t->udpfd : t->icmpfd);
-  if (setsockopt (fd, IPPROTO_IP, IP_TTL, &ttl, sizeof (ttl)) < 0)
+  if (setsockopt (fd, IPPROTO_IP, IP_TTL, ttlp, sizeof (*ttlp)) < 0)
     error (EXIT_FAILURE, errno, "setsockopt");
 }
 
-- 
1.7.1

Attachment: signature.asc
Description: Digital signature

Reply via email to