--- panel-plugin/net.c.old 2005-09-19 00:22:41.378774360 +0200 +++ panel-plugin/net.c 2005-09-19 01:23:45.791698920 +0200 @@ -82,6 +82,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) + { + perror("Error in socket"); + return FALSE; + } + + snprintf(ifr.ifr_name, IF_NAMESIZE, data->ifdata.if_name); + if (ioctl(sockfd, SIOCGIFFLAGS, &ifr) != 0) + { + close(sockfd); + perror("Error in ioctl(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; @@ -192,7 +231,7 @@ if (ioctl(sockfd, SIOCGIFADDR, &ifr) != 0) { close(sockfd); - perror("Error in ictl(sockfd)"); + perror("Error in ioctl(sockfd)"); return NULL; } close(sockfd); --- panel-plugin/net.h.old 2005-09-19 00:52:28.108150208 +0200 +++ panel-plugin/net.h 2005-09-19 01:07:51.793728656 +0200 @@ -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 true if interface is up, false 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. --- panel-plugin/netload.c.old 2005-09-19 00:58:37.320021472 +0200 +++ panel-plugin/netload.c 2005-09-19 01:25:06.671403336 +0200 @@ -143,6 +143,18 @@ XFCE_PANEL_LOCK(); + 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->monitor->ebox), caption, NULL); + + XFCE_PANEL_UNLOCK(); + + return TRUE; + } + get_current_netload( &(global->monitor->data), &(net[IN]), &(net[OUT]), &(net[TOT]) );