diff --git a/ChangeLog b/ChangeLog index cd7306c..dff3217 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2006-12-18 Bernhard Walle + + * added code for DragonFly BSD, thanks to Bob Bagwill + (fixed #1456) + * Not reporting errors if the interface has no IP address yet, + thanks to Mathy Vanvoorden (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 diff --git a/panel-plugin/net.c b/panel-plugin/net.c index 703c693..56c2d46 100644 --- a/panel-plugin/net.c +++ b/panel-plugin/net.c @@ -84,6 +84,8 @@ int init_netload(netdata* data, const char* device) data->ip_address[0] = 0; data->ip_update_count = 0; + data->up = FALSE; + data->up_update_count = 0; if (checkinterface(data) != TRUE) { @@ -167,6 +169,43 @@ char* get_name(netdata* data) } +/* ---------------------------------------------------------------------------------------------- */ +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) { @@ -191,8 +230,11 @@ char* get_ip_address(netdata* data) 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); diff --git a/panel-plugin/net.h b/panel-plugin/net.h index 7901be4..7ce4e98 100644 --- a/panel-plugin/net.h +++ b/panel-plugin/net.h @@ -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 @@ typedef struct 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; @@ -114,6 +117,14 @@ void get_current_netload(netdata* data, unsigned long *in, unsigned long *out, u */ char* get_name(netdata* data); +/** + * Check to see if an interface is up. + * @param data object + * @return true if interface is up, false otherwise. + */ +int get_interface_up(netdata* data); + + /** * Returns the IP address of the network interface * @param data object diff --git a/panel-plugin/netload.c b/panel-plugin/netload.c index 1df7259..97cdea9 100644 --- a/panel-plugin/netload.c +++ b/panel-plugin/netload.c @@ -138,6 +138,16 @@ static gboolean update_monitors(t_global_monitor *global) 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]) );