[Iftop-users] Portability to GNU/kFreeBSD and OpenSolaris

Mats Erik Andersson debian at gisladisker.se
Mon, 24 Oct 2011 00:11:13 +0200


Clearly no-one listened to my portability suggestions in [1].
Let me therefore point out changes mandatory to 1.0pre2,
should you desire to support the OpenSolaris variant known
as NexentaCore. Two changes are also relevant for GNU/kFreeBSD.

First off, renew the four files

     {,config/}config.{guess,sub}

The present versions are six years old. They are incapable
of working with GNU/kFreeBSD.

These are necessary changes (variations present also in [1]):

  * The correct conditionals in "addrs_ioctl.c" is

       defined __GLIBC__ & ! defined __linux__

    in order to catch GNU/kFreeBSD and to avoid NexentaCore.
    This MUST be changed, whether or not you decide to ignore
    OpenSolaris.

  * OpenSolaris does _not_ contain any "<sys/sysctl.h>"
    Exclude it"!

  * OpenSolaris _must_ test HAVE_SYS_SOCKIO_H and then
    include "<sys/sockio.h>".

  * You can not declare sigalrm() as non-static, and then
    define sigalrm() as static. That leads to compiler error,
    unless you ignore sanity checking.

  * OpenSolaris can not rely on "<curses.h>", since the 32-bit
    calls are only present in "<ncurses.h>". I demonstrated in [1]
    a functional technique to let the configuration script adapt
    to whatever Curses compatible library happens to be available
    in five different operating systems. Implement that method,
    or use the shortcut shown below.

Make your choice, I have given the options.

  Mats Erik Andersson


[1] http://lists.beasts.org/pipermail/iftop-users/2011-August/000344.html


diff -Naur iftop-1.0pre2.orig/addrs_ioctl.c iftop-1.0pre2/addrs_ioctl.c
--- iftop-1.0pre2.orig/addrs_ioctl.c	2011-10-02 23:11:30.000000000 +0200
+++ iftop-1.0pre2/addrs_ioctl.c	2011-10-23 23:33:41.777439591 +0200
@@ -19,12 +19,18 @@
 #include <netinet/in.h>
 
 #if defined __FreeBSD__ || defined __OpenBSD__ || defined __APPLE__ \
-      || ( defined __GNUC__ && ! defined __linux__ )
+      || ( defined __GLIBC__ && ! defined __linux__ )
 #include <sys/param.h>
+# if !__sun__
 #include <sys/sysctl.h>
+# endif
 #include <net/if_dl.h>
 #endif
 
+#if HAVE_SYS_SOCKIO_H
+# include <sys/sockio.h>
+#endif
+
 #ifdef USE_GETIFADDRS
 #include <ifaddrs.h>
 #endif
@@ -81,7 +87,7 @@
   }
 #else
 #if defined __FreeBSD__ || defined __OpenBSD__ || defined __APPLE__ \
-      || ( defined __GNUC__ && ! defined __linux__ )
+      || ( defined __GLIBC__ && ! defined __linux__ )
   {
     int sysctlparam[6] = {CTL_NET, PF_ROUTE, 0, 0, NET_RT_IFLIST, 0};
     size_t needed = 0;
diff -Naur iftop-1.0pre2.orig/dlcommon.c iftop-1.0pre2/dlcommon.c
--- iftop-1.0pre2.orig/dlcommon.c	2003-06-07 00:42:34.000000000 +0200
+++ iftop-1.0pre2/dlcommon.c	2011-10-23 23:19:48.803230766 +0200
@@ -462,7 +462,7 @@
 		err("dlphysaddrack:  short response ctl.len:  %d", ctl.len);
 }
 
-static void
+void
 sigalrm()
 {
 	(void) err("sigalrm:  TIMEOUT");
diff -Naur iftop-1.0pre2.orig/options.c iftop-1.0pre2/options.c
--- iftop-1.0pre2.orig/options.c	2011-10-04 22:39:42.000000000 +0200
+++ iftop-1.0pre2/options.c	2011-10-23 23:07:20.794488198 +0200
@@ -19,6 +19,10 @@
 #include <arpa/inet.h>
 #include <net/if.h>
 
+#if HAVE_SYS_SOCKIO_H
+#  include <sys/sockio.h>
+#endif
+
 #include "iftop.h"
 #include "options.h"
 #include "cfgfile.h"
diff -Naur iftop-1.0pre2.orig/ui.c iftop-1.0pre2/ui.c
--- iftop-1.0pre2.orig/ui.c	2011-10-03 22:30:03.000000000 +0200
+++ iftop-1.0pre2/ui.c	2011-10-23 23:21:11.527269307 +0200
@@ -6,7 +6,11 @@
 #include <sys/types.h>
 
 #include <ctype.h>
-#include <curses.h>
+#ifdef __sun__
+#  include <ncurses.h>
+#else
+#  include <curses.h>
+#endif
 #include <errno.h>
 #include <string.h>
 #include <math.h>