Minor patch for porting to Solaris 10

Bug #1273486 reported by Doke Scott
18
This bug affects 3 people
Affects Status Importance Assigned to Milestone
Mtr
New
Undecided
Unassigned
Nexenta Operating System
New
Undecided
Unassigned

Bug Description

I had some trouble getting mtr to compile on Solaris 10. Solaris needs an extra header, and it's picky about the bind and connect calls. This patch seems to have solved my problems. It seems to work on both sparc and i86pc. It does not seem to break linux.

diff --git a/configure.ac b/configure.ac
index d50c253..57a096d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -17,7 +17,7 @@ AC_CHECK_SIZEOF(unsigned short, 2)
 AC_CHECK_SIZEOF(unsigned int, 4)
 AC_CHECK_SIZEOF(unsigned long, 4)

-AC_CHECK_HEADERS(ncurses.h ncurses/curses.h curses.h cursesX.h sys/types.h fcntl.h)
+AC_CHECK_HEADERS(ncurses.h ncurses/curses.h curses.h cursesX.h sys/types.h fcntl.h sys/filio.h)
 AC_CHECK_HEADERS(socket.h sys/socket.h sys/xti.h arpa/nameser_compat.h)

 # We don't refer to any symbols in termcap, but -lcurses on SunOS does.
diff --git a/net.c b/net.c
index d648804..caf57fe 100644
--- a/net.c
+++ b/net.c
@@ -33,6 +33,9 @@
 #ifdef HAVE_FCNTL_H
 #include <fcntl.h>
 #endif
+#ifdef HAVE_SYS_FILIO_H
+#include <sys/filio.h>
+#endif
 #include <stdio.h>
 #include <stdlib.h>
 #include <math.h>
@@ -337,10 +340,23 @@ void net_send_tcp(int index)
 #endif
   }

- if (bind(s, (struct sockaddr *) &local, sizeof (local))) {
- display_clear();
- perror("bind()");
- exit(EXIT_FAILURE);
+ switch (af) {
+ case AF_INET:
+ if (bind(s, (struct sockaddr *) local4, sizeof (struct sockaddr_in))) {
+ display_clear();
+ perror("bind()");
+ exit(EXIT_FAILURE);
+ }
+ break;
+#ifdef ENABLE_IPV6
+ case AF_INET6:
+ if (bind(s, (struct sockaddr *) local6, sizeof (struct sockaddr_in6))) {
+ display_clear();
+ perror("bind()");
+ exit(EXIT_FAILURE);
+ }
+ break;
+#endif
   }

   len = sizeof (local);
@@ -400,7 +416,17 @@ void net_send_tcp(int index)
   gettimeofday(&sequence[port].time, NULL);
   sequence[port].socket = s;

- connect(s, (struct sockaddr *) &remote, sizeof (remote));
+ switch (af) {
+ case AF_INET:
+ connect(s, (struct sockaddr *) remote4, sizeof (struct sockaddr_in));
+ break;
+#ifdef ENABLE_IPV6
+ case AF_INET6:
+ connect(s, (struct sockaddr *) remote6, sizeof (struct sockaddr_in6));
+ break;
+#endif
+ }
+
 }

 /* Attempt to find the host at a particular number of hops away */

Revision history for this message
Thomas Uhle (uhle) wrote :

Nexenta OS builds on top of OpenSolaris kernel and is affected by the same problem.

Revision history for this message
Thomas Uhle (uhle) wrote :

This is the patch submitted by Doke Scott. I can confirm that it is working well on SPARC (32 bit) and also SPARCv9 (64 bit). It is necessary on Solaris 11 too.

Revision history for this message
Thomas Uhle (uhle) wrote :

In addition to Doke Scott's patch, I did also patch getopt.c and getopt1.c because getopt.h of Solaris' libc already contains everything that is needed, which means it has GNU-like getopt_long() and getopt_long_only(). I am not sure whether this is the correct way of getting rid of the "internal getopt compilation", at least it does its job.

Revision history for this message
yvs (lrou2014) wrote :
Revision history for this message
Thomas Uhle (uhle) wrote :
Revision history for this message
Thomas Uhle (uhle) wrote :
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.