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@lanzone.be> (fixed #1158) (Old svn revision: 2249)master
parent
9cfe22a4f5
commit
31403e75d8
|
@ -1,3 +1,10 @@
|
|||
2006-12-18 Bernhard Walle
|
||||
|
||||
* added code for DragonFly BSD, thanks to Bob Bagwill <bob@bagwill.com>
|
||||
(fixed #1456)
|
||||
* Not reporting errors if the interface has no IP address yet,
|
||||
thanks to Mathy Vanvoorden <matje@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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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 <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
|
||||
|
|
|
@ -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]) );
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue