[Goodies-commits] r2249 - in xfce4-netload-plugin/trunk: . panel-plugin

Bernhard Walle bwalle at xfce.org
Sun Dec 17 22:11:54 CET 2006


Author: bwalle
Date: 2006-12-17 21:11:54 +0000 (Sun, 17 Dec 2006)
New Revision: 2249

Modified:
   xfce4-netload-plugin/trunk/ChangeLog
   xfce4-netload-plugin/trunk/panel-plugin/net.c
   xfce4-netload-plugin/trunk/panel-plugin/net.h
   xfce4-netload-plugin/trunk/panel-plugin/netload.c
Log:
ChangeLog, panel-plugin/net.{c,h}, panel-plugin/netload.c:
  - Not reporting errors if the interface has no IP address yet, thanks to
    Mathy Vanvoorden <matje at lanzone.be> (fixed #1158)



Modified: xfce4-netload-plugin/trunk/ChangeLog
===================================================================
--- xfce4-netload-plugin/trunk/ChangeLog	2006-12-17 19:49:36 UTC (rev 2248)
+++ xfce4-netload-plugin/trunk/ChangeLog	2006-12-17 21:11:54 UTC (rev 2249)
@@ -1,3 +1,10 @@
+2006-12-18 Bernhard Walle
+
+	* added code for DragonFly BSD, thanks to Bob Bagwill <bob at bagwill.com>
+	  (fixed #1456)
+	* Not reporting errors if the interface has no IP address yet,
+	  thanks to Mathy Vanvoorden <matje at lanzone.be> (fixed #1158)
+
 2005-08-21 Bernhard Walle
 	* Fixed memory leak (thanks to Brian J. Tarricone)
 	* Custom bar colors now also work with special Gtk theme engine where

Modified: xfce4-netload-plugin/trunk/panel-plugin/net.c
===================================================================
--- xfce4-netload-plugin/trunk/panel-plugin/net.c	2006-12-17 19:49:36 UTC (rev 2248)
+++ xfce4-netload-plugin/trunk/panel-plugin/net.c	2006-12-17 21:11:54 UTC (rev 2249)
@@ -84,6 +84,8 @@
     
     data->ip_address[0] = 0;
     data->ip_update_count = 0;
+    data->up = FALSE;
+    data->up_update_count = 0;
     
     if (checkinterface(data) != TRUE)
 	{
@@ -168,6 +170,43 @@
 
 
 /* ---------------------------------------------------------------------------------------------- */
+int get_interface_up(netdata* data)
+{
+    int sockfd;
+    struct ifreq ifr;
+    struct sockaddr_in *p_sa;
+        
+    /* if the update count is non-zero */ 
+    if (data->up_update_count > 0)
+    {
+        data->up_update_count--;
+        return data->up;
+    }
+
+    /* get the value from the operating system */
+    if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1)
+    {
+        PRINT_DBG("Error in socket: %s", strerror(errno));
+        return FALSE;
+    }
+    
+    snprintf(ifr.ifr_name, IF_NAMESIZE, data->ifdata.if_name);
+    if (ioctl(sockfd, SIOCGIFFLAGS, &ifr) != 0)
+    {
+        PRINT_DBG("Error in ioctl(sockfd): %s", strerror(errno));
+        close(sockfd);
+        return FALSE;
+    }
+    close(sockfd);
+
+    data->up = ((ifr.ifr_flags & IFF_UP) == IFF_UP) ? TRUE : FALSE;
+    data->up_update_count = UP_UPDATE_INTERVAL;
+
+    return data->up;
+}
+
+
+/* ---------------------------------------------------------------------------------------------- */
 char* get_ip_address(netdata* data)
 {
     int sockfd;
@@ -191,8 +230,11 @@
     snprintf(ifr.ifr_name, IF_NAMESIZE, data->ifdata.if_name);
     if (ioctl(sockfd, SIOCGIFADDR, &ifr) != 0)
     {
+	    if (errno != EADDRNOTAVAIL)
+        {
+            PRINT_DBG("Error in ioctl(sockfd): %s", strerror(errno));
+        }
         close(sockfd);
-        PRINT_DBG("Error in ictl(sockfd): %s", strerror(errno));
         return NULL;
     }
     close(sockfd);

Modified: xfce4-netload-plugin/trunk/panel-plugin/net.h
===================================================================
--- xfce4-netload-plugin/trunk/panel-plugin/net.h	2006-12-17 19:49:36 UTC (rev 2248)
+++ xfce4-netload-plugin/trunk/panel-plugin/net.h	2006-12-17 21:11:54 UTC (rev 2249)
@@ -22,6 +22,7 @@
 #include "slurm.h"
 
 #define MSGSIZE 1024
+#define UP_UPDATE_INTERVAL 20
 #define IP_UPDATE_INTERVAL 20
 #define IP_ADDRESS_LENGTH 64
 #define INTERFACE_NAME_LENGTH 9
@@ -59,6 +60,8 @@
     char            ip_address[IP_ADDRESS_LENGTH];
     int             ip_update_count;
     DataStats       stats;
+    int             up;
+    int             up_update_count;
 #ifdef __HPUX__
     int             wait_pcks_counter;
     nmapi_logstat*  if_ptr;
@@ -115,6 +118,14 @@
 char* get_name(netdata* data);
 
 /**
+ * Check to see if an interface is up.
+ * @param data      object
+ * @return  <code>true</code> if interface is up, <code>false</code> otherwise.
+ */
+int get_interface_up(netdata* data);
+
+
+/**
  * Returns the IP address of the network interface
  * @param data     object
  * @return the IP address as string, NULL on error.

Modified: xfce4-netload-plugin/trunk/panel-plugin/netload.c
===================================================================
--- xfce4-netload-plugin/trunk/panel-plugin/netload.c	2006-12-17 19:49:36 UTC (rev 2248)
+++ xfce4-netload-plugin/trunk/panel-plugin/netload.c	2006-12-17 21:11:54 UTC (rev 2249)
@@ -138,6 +138,16 @@
     double temp;
     gint i, j;
 
+    if (!get_interface_up(&(global->monitor->data)))
+    {
+        g_snprintf(caption, sizeof(caption), 
+                _("<< %s >> (Interface down)"),
+                    get_name(&(global->monitor->data)));
+        gtk_tooltips_set_tip(tooltips, GTK_WIDGET(global->ebox), caption, NULL);
+
+        return TRUE;
+    }
+
     get_current_netload( &(global->monitor->data), &(net[IN]), &(net[OUT]), &(net[TOT]) );
     
 




More information about the Goodies-commits mailing list