patches/gnome-netstatus-01-kstat-solaris.diff
author Jon Tibble <meths@btinternet.com>
Sat, 06 Oct 2012 16:11:50 +0100
branchs11express-2010-11
changeset 22109 db10202d5f6d
parent 16660 bf94a2c88b7c
permissions -rw-r--r--
Added tag oi_151a_prestable7 for changeset 25dee50cecca

--- gnome-netstatus-2.26.0/configure.in.orig	2009-03-08 05:44:58.000000000 +0000
+++ gnome-netstatus-2.26.0/configure.in	2009-03-18 10:17:17.098639534 +0000
@@ -79,6 +79,24 @@ else
 fi
 AC_SUBST(NETSTATUS_DEBUG_CFLAGS)
 
+case $host in
+*-*-solaris*)
+       ostype=solaris
+       AC_CHECK_LIB(kstat, kstat_open, [
+              AC_CHECK_HEADER(kstat.h, [
+                      AC_DEFINE(HAVE_KSTAT, 1, [Define to 1 if you have the <kstat.h> header file.])
+                      KSTAT_LIBS=-lkstat
+                      AC_SUBST(KSTAT_LIBS)
+              ])
+       ], AC_MSG_ERROR([*** libkstat is required]))
+       AC_DEFINE_UNQUOTED(HAVE_SOLARIS, 1, Define to 1)
+       ;;
+*-*-linux*)
+       ostype=linux
+       AC_DEFINE_UNQUOTED(HAVE_LINUX, 1, Define to 1)
+       ;;
+esac
+
 dnl
 dnl     whether or not to run glib-mkenums etc.
 dnl

--- gnome-netstatus-2.7.1/src/Makefile.am	2004-07-22 17:02:37.778210000 +0600
+++ gnome-netstatus-2.7.1-new/src/Makefile.am	2004-07-22 17:01:38.429334000 +0600
@@ -14,7 +14,7 @@ INCLUDES = \
 
 libexec_PROGRAMS = gnome-netstatus-applet
 
-gnome_netstatus_applet_LDADD = $(NETSTATUS_LIBS)
+gnome_netstatus_applet_LDADD = $(NETSTATUS_LIBS) $(KSTAT_LIBS)
 
 gnome_netstatus_applet_SOURCES = \
 	netstatus-applet.c \
--- gnome-netstatus-2.26.0/src/netstatus-sysdeps.c.ori	2009-03-13 11:52:01.363555674 +0000
+++ gnome-netstatus-2.26.0/src/netstatus-sysdeps.c	2009-03-13 11:53:18.108631785 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2003 Sun Microsystems, Inc.
+ * Copyright (C) 2003-2009 Sun Microsystems, Inc.
  * Copyright (C) 2004 Red Hat Inc.
  *
  * This program is free software; you can redistribute it and/or
@@ -35,6 +35,11 @@
 #include <glib.h>
 #include <glib/gi18n.h>
 
+#ifdef HAVE_SOLARIS
+#include <kstat.h>
+#include <stdlib.h>
+#endif
+
 #ifdef __FreeBSD__
 #include <sys/types.h>
 #include <sys/socket.h>
@@ -78,7 +82,7 @@
   return TRUE;
 }
 
-#if !defined (__FreeBSD__)
+#if !defined (__FreeBSD__) && !defined (__sun)
 
 static inline char *
 parse_iface_name (const char *buf)
@@ -357,6 +361,103 @@
   return error_message;
 }
 
+#elif defined (__sun)
+
+char *
+netstatus_sysdeps_read_iface_statistics (const char  *iface,
+					  gulong      *in_packets,
+					  gulong      *out_packets,
+					  gulong      *in_bytes,
+					  gulong      *out_bytes)
+{
+  char *error_message = NULL;
+  static kstat_ctl_t *kc = NULL;
+  kstat_t *ksp;
+  kstat_named_t *kn;
+
+  /*
+   * The linux-specific code uses -1 as the default value.  But if we return -1
+   * (see comment below), then it gets interpreted as (unsigned long)-1, which
+   * looks stupid and is definitely more wrong than just showing 0.
+   */
+
+  *in_packets = 0;
+  *out_packets = 0;
+  *in_bytes = 0;
+  *out_bytes = 0;
+
+  if (kc == NULL)
+    {
+      if ((kc = kstat_open ()) == NULL)
+	return g_strdup_printf (_("Cannot open /dev/kstat: %s"),
+		g_strerror (errno));
+    }
+  else
+    {
+      if (kstat_chain_update (kc) < 0)
+	{
+	  int e = errno;
+	  kstat_close (kc);
+	  kc = NULL;
+	  return g_strdup_printf (_("Cannot update kstats: %s"),
+		  g_strerror (e));
+	}
+    }
+
+  if ((ksp = kstat_lookup (kc, NULL, -1, iface)) == NULL)
+    {
+      kstat_close (kc);
+      kc = NULL;
+      return g_strdup_printf (_("Cannot find information on interface '%s'"),
+	iface);
+    }
+
+  if (kstat_read (kc, ksp, NULL) < 0)
+    {
+      kstat_close (kc);
+      kc = NULL;
+      return g_strdup_printf (_("Cannot read kstat"));
+    }
+
+  if ((kn = kstat_data_lookup (ksp, "ipackets")) != NULL)
+    *in_packets = kn->value.ui32;
+
+  if ((kn = kstat_data_lookup (ksp, "opackets")) != NULL)
+    *out_packets = kn->value.ui32;
+
+  if ((kn = kstat_data_lookup (ksp, "rbytes")) != NULL)
+    *in_bytes = kn->value.ui32;
+
+  if ((kn = kstat_data_lookup (ksp, "obytes")) != NULL)
+    *out_bytes = kn->value.ui32;
+
+  /*
+   * On Solaris, loopback doesn't report bytes, just packets.  The behavior of
+   * the linux-specific code reports an error if all the data is not present,
+   * and that shuts the applet down.  So perhaps it's best to simply return
+   * success if we can access the data at all.
+   */
+
+  return NULL;
+}
+
+char *
+netstatus_sysdeps_read_iface_wireless_details (const char *iface,
+					       gboolean   *is_wireless,
+					       int        *signal_strength)
+{
+  g_return_val_if_fail (iface != NULL, NULL);
+  g_return_val_if_fail (is_wireless != NULL, NULL);
+  g_return_val_if_fail (signal_strength != NULL, NULL);
+                                                                                
+  if (is_wireless)
+    *is_wireless = FALSE;
+  if (signal_strength)
+    *signal_strength = 0;
+                                                                                
+  return NULL;
+}
+
 #else /* defined(__FreeBSD__) */
 
 static inline void