Hello all,

in OpenBSD the setsockopt(2) call with IPPROTO_IP and IP_TTL
will fail for any passed variable, except `int'.

The present code passes `unsigned char'. Thus is fails
on OpenBSD at execution time. The patch corrects all three
instances in the code. As a result GNU/Linux and OpenBSD
can now perform route tracing, using UDP as well as ICMP.


Best regards,

Mats
From 2561b96f368ec572e7e1d47c8224e8490bd53c4f Mon Sep 17 00:00:00 2001
From: Mats Erik Andersson <[email protected]>
Date: Sat, 30 Oct 2010 23:26:06 +0200
Subject: [PATCH] src/traceroute.c: Pass integer values to IP_TTL option.

---
 ChangeLog        |    5 +++++
 src/traceroute.c |   16 ++++++++--------
 2 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index da358cb..11e79f0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2010-10-30  Mats Erik Andersson <[email protected]>
+
+	* src/traceroute.c (trace_init): Change type of TTLP to `int'.
+	(trace_inc_ttl): Likewise.
+
 2010-10-27  Mats Erik Andersson <[email protected]>
 	    Simon Josefsson  <[email protected]>
 
diff --git a/src/traceroute.c b/src/traceroute.c
index 0b02fa3..fc477c2 100644
--- a/src/traceroute.c
+++ b/src/traceroute.c
@@ -311,9 +311,9 @@ void
 trace_init (trace_t * t, const struct sockaddr_in to,
 	    const enum trace_type type)
 {
-  const unsigned char *ttlp;
+  int ttlp;
   assert (t);
-  ttlp = &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, ttlp,
-		      sizeof (t->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,
-			  ttlp, sizeof (t->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;
-  const unsigned char *ttlp;
+  int ttlp;
 
   assert (t);
 
-  ttlp = &t->ttl;
+  ttlp = t->ttl;
   t->ttl++;
   fd = (t->type == TRACE_UDP ? t->udpfd : t->icmpfd);
-  if (setsockopt (fd, IPPROTO_IP, IP_TTL, ttlp, sizeof (t->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