New version 0.2.0pre2

Support more than one instance of the plugin


(Old svn revision: 298)
master
Bernhard Walle 2003-08-25 21:08:58 +00:00
parent fbca674e03
commit bf777a0384
28 changed files with 482 additions and 366 deletions

View File

@ -1,3 +1,8 @@
2003-08-25 Bernhard Walle
* Changed all static variables to a structure which is given the function
as a parameter. This makes more than one instance of the plugin possible.
* Released 0.2.0pre2 which is the next test version for 0.2.0.
2003-08-24 Bernhard Walle 2003-08-24 Bernhard Walle
* Using the last four measures in history so it's easier to read. * Using the last four measures in history so it's easier to read.
* Automatic maximum now really works. * Automatic maximum now really works.

63
configure vendored
View File

@ -1748,7 +1748,7 @@ fi
# Define the identity of the package. # Define the identity of the package.
PACKAGE=xfce4-netload-plugin PACKAGE=xfce4-netload-plugin
VERSION=0.2.0pre1 VERSION=0.2.0pre2
cat >>confdefs.h <<_ACEOF cat >>confdefs.h <<_ACEOF
@ -20703,67 +20703,6 @@ fi
echo "$as_me:$LINENO: checking for vanilla_coke in -lfridge" >&5
echo $ECHO_N "checking for vanilla_coke in -lfridge... $ECHO_C" >&6
if test "${ac_cv_lib_fridge_vanilla_coke+set}" = set; then
echo $ECHO_N "(cached) $ECHO_C" >&6
else
ac_check_lib_save_LIBS=$LIBS
LIBS="-lfridge $LIBS"
cat >conftest.$ac_ext <<_ACEOF
#line $LINENO "configure"
/* confdefs.h. */
_ACEOF
cat confdefs.h >>conftest.$ac_ext
cat >>conftest.$ac_ext <<_ACEOF
/* end confdefs.h. */
/* Override any gcc2 internal prototype to avoid an error. */
#ifdef __cplusplus
extern "C"
#endif
/* We use char because int might match the return type of a gcc2
builtin and then its argument prototype would still apply. */
char vanilla_coke ();
int
main ()
{
vanilla_coke ();
;
return 0;
}
_ACEOF
rm -f conftest.$ac_objext conftest$ac_exeext
if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
(eval $ac_link) 2>&5
ac_status=$?
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); } &&
{ ac_try='test -s conftest$ac_exeext'
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
(eval $ac_try) 2>&5
ac_status=$?
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); }; }; then
ac_cv_lib_fridge_vanilla_coke=yes
else
echo "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5
ac_cv_lib_fridge_vanilla_coke=no
fi
rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS
fi
echo "$as_me:$LINENO: result: $ac_cv_lib_fridge_vanilla_coke" >&5
echo "${ECHO_T}$ac_cv_lib_fridge_vanilla_coke" >&6
if test $ac_cv_lib_fridge_vanilla_coke = yes; then
echo "WTF?!"
else
echo "Warning: No vanilla coke found in fridge.";echo "We highly suggest that you rectify this situation immediatly."
fi
GETTEXT_PACKAGE=xfce4-netload GETTEXT_PACKAGE=xfce4-netload

View File

@ -9,7 +9,7 @@ AC_INIT([panel-plugin/netload.c])
AM_CONFIG_HEADER([config.h]) AM_CONFIG_HEADER([config.h])
AM_INIT_AUTOMAKE([xfce4-netload-plugin], [0.2.0pre1]) AM_INIT_AUTOMAKE([xfce4-netload-plugin], [0.2.0pre2])
AM_MAINTAINER_MODE AM_MAINTAINER_MODE
@ -46,9 +46,6 @@ AC_TYPE_SIZE_T
AC_CHECK_LIB(kstat, kstat_open, SOLLIBS="-lkstat -lsocket", SOLLIBS="") AC_CHECK_LIB(kstat, kstat_open, SOLLIBS="-lkstat -lsocket", SOLLIBS="")
AC_SUBST(SOLLIBS) AC_SUBST(SOLLIBS)
AC_CHECK_LIB(fridge, vanilla_coke, echo "WTF?!",
echo "Warning: No vanilla coke found in fridge.";echo "We highly suggest that you rectify this situation immediatly.")
dnl Check for i18n support dnl Check for i18n support
BM_I18N([xfce4-netload], [de lt ca]) BM_I18N([xfce4-netload], [de lt ca])

View File

@ -1,7 +1,7 @@
/* XFce 4 - Netload Plugin /* XFce 4 - Netload Plugin
* Copyright (c) 2003 Bernhard Walle <bernhard.walle@gmx.de> * Copyright (c) 2003 Bernhard Walle <bernhard.walle@gmx.de>
* *
* Id: $Id: net.c,v 1.1 2003/08/24 20:02:29 bwalle Exp $ * Id: $Id: net.c,v 1.2 2003/08/25 21:08:58 bwalle Exp $
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -36,6 +36,7 @@
#endif #endif
/* From Wormulon */ /* From Wormulon */
#include "net.h"
#include "os.h" #include "os.h"
#include "wormulon.h" #include "wormulon.h"
#include "slurm.h" /* slurm structs */ #include "slurm.h" /* slurm structs */
@ -65,39 +66,25 @@
#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
#define TRUE 1
#endif
static double backup_in, backup_out; void init_netload(netdata* data, const char* device)
static double cur_in, cur_out;
static char dim_in[4], dim_out[4];
static struct timeval prev_time;
int correct_interface;
void init_netload(const char* device)
{ {
strncpy( ifdata.if_name, device, 9 ); memset( data, 0, sizeof(netdata) );
ifdata.if_name[9] = '\0'; strncpy( data->ifdata.if_name, device, 9 );
data->ifdata.if_name[9] = '\0';
if (checkinterface() != TRUE) if (checkinterface(data) != TRUE)
{ {
correct_interface = FALSE; data->correct_interface = FALSE;
return; return;
} }
/* init in a sane state */ /* init in a sane state */
get_stat(); get_stat(data);
backup_in = stats.rx_bytes; data->backup_in = data->stats.rx_bytes;
backup_out = stats.tx_bytes; data->backup_out = data->stats.tx_bytes;
memset(dim_in, 0, sizeof(dim_in));
memset(dim_out, 0, sizeof(dim_out));
correct_interface = TRUE; data->correct_interface = TRUE;
} }
@ -107,12 +94,12 @@ void init_netload(const char* device)
* @param out Will be filled with the "out"-load. * @param out Will be filled with the "out"-load.
* @param tot Will be filled with the "total"-load. * @param tot Will be filled with the "total"-load.
*/ */
void get_current_netload(unsigned long *in, unsigned long *out, unsigned long *tot) void get_current_netload(netdata* data, unsigned long *in, unsigned long *out, unsigned long *tot)
{ {
struct timeval curr_time; struct timeval curr_time;
double delta_t; double delta_t;
if( !correct_interface ) if( ! data->correct_interface )
{ {
if( in != NULL && out != NULL && tot != NULL ) if( in != NULL && out != NULL && tot != NULL )
{ {
@ -122,46 +109,46 @@ void get_current_netload(unsigned long *in, unsigned long *out, unsigned long *t
gettimeofday(&curr_time, NULL); gettimeofday(&curr_time, NULL);
delta_t = (double) ((curr_time.tv_sec - prev_time.tv_sec) * 1000000L delta_t = (double) ((curr_time.tv_sec - data->prev_time.tv_sec) * 1000000L
+ (curr_time.tv_usec - prev_time.tv_usec)) / 1000000.0; + (curr_time.tv_usec - data->prev_time.tv_usec)) / 1000000.0;
/* update */ /* update */
get_stat(); get_stat(data);
if (backup_in > stats.rx_bytes) if (data->backup_in > data->stats.rx_bytes)
{ {
cur_in = (int) stats.rx_bytes / delta_t; data->cur_in = (int) data->stats.rx_bytes / delta_t;
} }
else else
{ {
cur_in = (int) (stats.rx_bytes - backup_in) / delta_t; data->cur_in = (int) (data->stats.rx_bytes - data->backup_in) / delta_t;
} }
if (backup_out > stats.tx_bytes) if (data->backup_out > data->stats.tx_bytes)
{ {
cur_out = (int) stats.tx_bytes / delta_t; data->cur_out = (int) data->stats.tx_bytes / delta_t;
} }
else else
{ {
cur_out = (int) (stats.tx_bytes - backup_out) / delta_t; data->cur_out = (int) (data->stats.tx_bytes - data->backup_out) / delta_t;
} }
if( in != NULL && out != NULL && tot != NULL ) if( in != NULL && out != NULL && tot != NULL )
{ {
*in = cur_in; *in = data->cur_in;
*out = cur_out; *out = data->cur_out;
*tot = *in + *out; *tot = *in + *out;
} }
/* save 'new old' values */ /* save 'new old' values */
backup_in = stats.rx_bytes; data->backup_in = data->stats.rx_bytes;
backup_out = stats.tx_bytes; data->backup_out = data->stats.tx_bytes;
/* do the same with time */ /* do the same with time */
prev_time.tv_sec = curr_time.tv_sec; data->prev_time.tv_sec = curr_time.tv_sec;
prev_time.tv_usec = curr_time.tv_usec; data->prev_time.tv_usec = curr_time.tv_usec;
} }
void close_netload() void close_netload(netdata* data)
{ {
/* We need not code here */ /* We need not code here */
} }

View File

@ -1,7 +1,7 @@
/* XFce 4 - Netload Plugin /* XFce 4 - Netload Plugin
* Copyright (c) 2003 Bernhard Walle <bernhard.walle@gmx.de> * Copyright (c) 2003 Bernhard Walle <bernhard.walle@gmx.de>
* *
* Id: $Id: net.h,v 1.3 2003/08/24 20:02:29 bwalle Exp $ * Id: $Id: net.h,v 1.4 2003/08/25 21:08:58 bwalle Exp $
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -22,12 +22,70 @@
#ifndef NET_H #ifndef NET_H
#define NET_H #define NET_H
/* ----------------------- Some defines here ------------------------------- */
#if defined (__sun__)
#define __Solaris__ 1
#endif
#include "os.h"
#include "slurm.h"
/*
* We need this because we cannot use static variables. Using of static variables allows
* us not to use several instances of the plugin.
* I know that this change makes it a bit incompatible with wormulon, but that's the
* price to pay ...
*/
typedef struct
{
double backup_in;
double backup_out;
double cur_in;
double cur_out;
struct timeval prev_time;
int correct_interface; /* treated as boolean */
IfData ifdata;
DataStats stats;
#ifdef __HPUX__
int wait_pcks_counter;
nmapi_logstat* if_ptr;
#elif __FreeBSD__
int watchif;
int dev_opened;
#elif __NetBSD__
int mib_name1[6];
int mib_name2[6];
char* buf1;
char* buf2;
int alloc1;
int alloc2;
#elif __OpenBSD__ || __MicroBSD__
int mib_name1[6];
int mib_name2[6];
char* buf1;
char* buf2;
int alloc1;
int alloc2;
#elif __linux__
FILE* proc_net_dev;
#elif __Solaris__
#else
#error "OS not supported"
#endif
} netdata;
/** /**
* Initializes the netload plugin. Used to set up inital values. This function must * Initializes the netload plugin. Used to set up inital values. This function must
* be called after each change of the network interface. * be called after each change of the network interface.
* @param device The network device, e.g. <code>ippp0</code> for ISDN on Linux. * @param device The network device, e.g. <code>ippp0</code> for ISDN on Linux.
*/ */
void init_netload(const char* device); void init_netload(netdata* data, const char* device);
/** /**
* Gets the current netload. You must call init_netload() once before you use this function! * Gets the current netload. You must call init_netload() once before you use this function!
@ -35,11 +93,11 @@ void init_netload(const char* device);
* @param out Output load in byte/s. * @param out Output load in byte/s.
* @param tot Total load in byte/s. * @param tot Total load in byte/s.
*/ */
void get_current_netload(unsigned long *in, unsigned long *out, unsigned long *tot); void get_current_netload(netdata* data, unsigned long *in, unsigned long *out, unsigned long *tot);
/** /**
* Should be called to do cleanup work. * Should be called to do cleanup work.
*/ */
void close_netload(); void close_netload(netdata* data);
#endif /* NET_H */ #endif /* NET_H */

View File

@ -1,7 +1,7 @@
/* XFce 4 - Netload Plugin /* XFce 4 - Netload Plugin
* Copyright (c) 2003 Bernhard Walle <bernhard.walle@gmx.de> * Copyright (c) 2003 Bernhard Walle <bernhard.walle@gmx.de>
* *
* Id: $Id: netload.c,v 1.3 2003/08/24 20:05:10 bwalle Exp $ * Id: $Id: netload.c,v 1.4 2003/08/25 21:08:58 bwalle Exp $
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -22,6 +22,9 @@
#include <config.h> #include <config.h>
#endif #endif
#include "net.h"
#include "utils.h"
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <libxfce4util/i18n.h> #include <libxfce4util/i18n.h>
@ -29,8 +32,6 @@
#include <panel/plugins.h> #include <panel/plugins.h>
#include <panel/xfce.h> #include <panel/xfce.h>
#include "net.h"
#include "utils.h"
/* for xml: */ /* for xml: */
#define MONITOR_ROOT "Netload" #define MONITOR_ROOT "Netload"
@ -77,6 +78,9 @@ typedef struct
gulong net_max[SUM]; gulong net_max[SUM];
t_monitor_options options; t_monitor_options options;
/* for the network part */
netdata data;
/* Displayed text */ /* Displayed text */
GtkBox *opt_vbox; GtkBox *opt_vbox;
@ -120,7 +124,7 @@ static gint update_monitors(t_global_monitor *global)
double temp; double temp;
gint i; gint i;
get_current_netload( &(net[IN]), &(net[OUT]), &(net[TOT]) ); get_current_netload( &(global->monitor->data), &(net[IN]), &(net[OUT]), &(net[TOT]) );
for (i = 0; i < SUM; i++) for (i = 0; i < SUM; i++)
@ -397,7 +401,7 @@ static void monitor_free(Control *ctrl)
} }
g_free(global); g_free(global);
close_netload(); close_netload( &(global->monitor->data) );
} }
static void setup_monitor(t_global_monitor *global) static void setup_monitor(t_global_monitor *global)
@ -443,7 +447,7 @@ static void setup_monitor(t_global_monitor *global)
gtk_widget_show(global->monitor->label); gtk_widget_show(global->monitor->label);
} }
init_netload(global->monitor->options.network_device); init_netload( &(global->monitor->data), global->monitor->options.network_device);
} }

View File

@ -9,6 +9,8 @@
*****************************************************************************/ *****************************************************************************/
#ifndef _OS_H #ifndef _OS_H
#define _OS_H
#if defined (__sun__) #if defined (__sun__)
#define __Solaris__ 1 #define __Solaris__ 1
#endif #endif

View File

@ -7,6 +7,7 @@
*****************************************************************************/ *****************************************************************************/
#ifndef _SLURM_H_ #ifndef _SLURM_H_
#define _SLURM_H_
typedef struct IfData{ typedef struct IfData{
char if_name[10]; /* The device name given as start parameter*/ char if_name[10]; /* The device name given as start parameter*/
@ -17,7 +18,7 @@ typedef struct IfData{
int if_valid; /* 1 = selected interface exists int if_valid; /* 1 = selected interface exists
* 0 = interfaces does not exists */ * 0 = interfaces does not exists */
} IfData; } IfData;
IfData ifdata;
/* This structure stays the INFO variables */ /* This structure stays the INFO variables */
typedef struct DataStats { typedef struct DataStats {
@ -51,6 +52,5 @@ typedef struct DataStats {
double rx_bytes_comp_off; double rx_bytes_comp_off;
double tx_bytes_comp_off; double tx_bytes_comp_off;
} DataStats; } DataStats;
DataStats stats;
#endif #endif

View File

@ -5,7 +5,7 @@
* application specific defines. You should never need to tune anything here * application specific defines. You should never need to tune anything here
* *
****************************************************************************** ******************************************************************************
* $Id: wormulon.h,v 1.1 2003/08/24 20:02:29 bwalle Exp $ * $Id: wormulon.h,v 1.2 2003/08/25 21:08:58 bwalle Exp $
*****************************************************************************/ *****************************************************************************/
#ifndef _WORMULON_H #ifndef _WORMULON_H
@ -17,11 +17,8 @@
#define FALSE 0 #define FALSE 0
#endif #endif
#define SAMPLE_TIME 1 /* one second default sample time */
#ifdef __linux__ #ifdef __linux__
#define PATH_NET_DEV "/proc/net/dev" #define PATH_NET_DEV "/proc/net/dev"
static FILE *proc_net_dev;
#endif #endif
/* define possible options */ /* define possible options */

View File

@ -1,4 +1,19 @@
/* $Id: freebsd.c,v 1.1 2003/08/24 20:01:48 bwalle Exp $ */ /* $Id: freebsd.c,v 1.2 2003/08/25 21:08:58 bwalle Exp $ */
/*****************************************************************************
*
* init_osspecific()
*
* Init function
*
****************************************************************************/
void init_osspecific(netdata* data)
{
data->watchif = -1;
}
/***************************************************************************** /*****************************************************************************
* *
@ -9,7 +24,7 @@
* *
****************************************************************************/ ****************************************************************************/
int checkinterface(void) int checkinterface(netdata* data)
{ {
int validinterface = FALSE; int validinterface = FALSE;
@ -31,7 +46,7 @@ int checkinterface(void)
len = sizeof(ifmd); len = sizeof(ifmd);
sysctl(name, 6, &ifmd, &len, NULL, 0); sysctl(name, 6, &ifmd, &len, NULL, 0);
if (strcmp(ifmd.ifmd_name, (char *)ifdata.if_name) == 0) if (strcmp(ifmd.ifmd_name, (char *)data->ifdata.if_name) == 0)
{ {
/* /*
* now we have an interface and just have to see if it's up * now we have an interface and just have to see if it's up
@ -56,22 +71,20 @@ int checkinterface(void)
* *
****************************************************************************/ ****************************************************************************/
int get_stat(void) int get_stat(netdata* data)
{ {
/* /*
* use sysctl() to get the right interface number if !dev_opened * use sysctl() to get the right interface number if !dev_opened
* then read the data directly from the ifmd_data struct * then read the data directly from the ifmd_data struct
*/ */
static int watchif = -1;
int i, num_iface; int i, num_iface;
size_t len; size_t len;
int name[6]; int name[6];
struct ifmibdata ifmd; struct ifmibdata ifmd;
static int dev_opened = 0;
unsigned long rx_o, tx_o; unsigned long rx_o, tx_o;
if (!dev_opened) if (!data->dev_opened)
{ {
len = sizeof(num_iface); len = sizeof(num_iface);
sysctlbyname("net.link.generic.system.ifcount", &num_iface, &len, sysctlbyname("net.link.generic.system.ifcount", &num_iface, &len,
@ -87,11 +100,11 @@ int get_stat(void)
len = sizeof(ifmd); len = sizeof(ifmd);
sysctl(name, 6, &ifmd, &len, NULL, 0); sysctl(name, 6, &ifmd, &len, NULL, 0);
if (strcmp(ifmd.ifmd_name, (char *)ifdata.if_name) == 0) if (strcmp(ifmd.ifmd_name, (char *)data->ifdata.if_name) == 0)
{ {
/* got the right interface */ /* got the right interface */
watchif = i; data->watchif = i;
dev_opened++; data->dev_opened++;
} }
} }
} }
@ -100,25 +113,25 @@ int get_stat(void)
name[1] = PF_LINK; name[1] = PF_LINK;
name[2] = NETLINK_GENERIC; name[2] = NETLINK_GENERIC;
name[3] = IFMIB_IFDATA; name[3] = IFMIB_IFDATA;
name[4] = watchif; name[4] = data->watchif;
name[5] = IFDATA_GENERAL; name[5] = IFDATA_GENERAL;
len = sizeof(ifmd); len = sizeof(ifmd);
sysctl(name, 6, &ifmd, &len, NULL, 0); sysctl(name, 6, &ifmd, &len, NULL, 0);
rx_o = stats.rx_bytes; tx_o = stats.tx_bytes; rx_o = data->stats.rx_bytes; tx_o = data->stats.tx_bytes;
stats.tx_packets = ifmd.ifmd_data.ifi_opackets; data->stats.tx_packets = ifmd.ifmd_data.ifi_opackets;
stats.rx_packets = ifmd.ifmd_data.ifi_ipackets; data->stats.rx_packets = ifmd.ifmd_data.ifi_ipackets;
stats.rx_bytes = ifmd.ifmd_data.ifi_ibytes; data->stats.rx_bytes = ifmd.ifmd_data.ifi_ibytes;
stats.tx_bytes = ifmd.ifmd_data.ifi_obytes; data->stats.tx_bytes = ifmd.ifmd_data.ifi_obytes;
stats.rx_errors = ifmd.ifmd_data.ifi_ierrors; data->stats.rx_errors = ifmd.ifmd_data.ifi_ierrors;
stats.tx_errors = ifmd.ifmd_data.ifi_oerrors; data->stats.tx_errors = ifmd.ifmd_data.ifi_oerrors;
if (rx_o > stats.rx_bytes) if (rx_o > data->stats.rx_bytes)
stats.rx_over++; data->stats.rx_over++;
if (tx_o > stats.tx_bytes) if (tx_o > data->stats.tx_bytes)
stats.tx_over++; data->stats.tx_over++;
return (0); return (0);
} }

View File

@ -1,2 +1,6 @@
int get_stat(void);
int checkinterface(void); #include "net.h"
void init_osspecific(netdata* data);
int checkinterface(netdata* data);
int get_stat(netdata* data);

View File

@ -1,7 +1,23 @@
#include <netio.h> #include <netio.h>
#define WAIT_PCKS_COUNTER 15 #define WAIT_PCKS_COUNTER 15
/* $Id: hpux.c,v 1.1 2003/08/24 20:01:48 bwalle Exp $ */ /* $Id: hpux.c,v 1.2 2003/08/25 21:08:58 bwalle Exp $ */
/*****************************************************************************
*
* init_osspecific()
*
* Init function
*
****************************************************************************/
void init_osspecific(netdata* data)
{
wait_pcks_counter = WAIT_PCKS_COUNTER+1;
}
/***************************************************************************** /*****************************************************************************
* *
@ -39,7 +55,7 @@ void _getifdata()
{ {
int buffer, fd, val, ret = -1; int buffer, fd, val, ret = -1;
unsigned int len, i; unsigned int len, i;
char tmpinterfacestring[sizeof(ifdata.if_name)+1],*strstrmatch; char tmpinterfacestring[sizeof(data->ifdata.if_name)+1],*strstrmatch;
struct nmparms params; struct nmparms params;
mib_ifEntry * if_buf; mib_ifEntry * if_buf;
@ -48,10 +64,10 @@ void _getifdata()
* The interface description is more then the pure devicename. * The interface description is more then the pure devicename.
* Let's do some formating to allow a propper pattern matching * Let's do some formating to allow a propper pattern matching
*/ */
strcpy(tmpinterfacestring,ifdata.if_name); strcpy(tmpinterfacestring,data->ifdata.if_name);
strcat(tmpinterfacestring," "); strcat(tmpinterfacestring," ");
for (i=0; i <= ifdata.if_amount; i++) for (i=0; i <= data->ifdata.if_amount; i++)
{ {
if ((fd = open_mib("/dev/lan", O_RDWR, i, 0)) >= 0) if ((fd = open_mib("/dev/lan", O_RDWR, i, 0)) >= 0)
{ {
@ -72,8 +88,8 @@ void _getifdata()
strstrmatch = strstr(if_buf->ifDescr, (char *)tmpinterfacestring); strstrmatch = strstr(if_buf->ifDescr, (char *)tmpinterfacestring);
if ( strstrmatch && (strcmp(strstrmatch,if_buf->ifDescr)== 0)) if ( strstrmatch && (strcmp(strstrmatch,if_buf->ifDescr)== 0))
{ {
ifdata.if_valid = 1; data->ifdata.if_valid = 1;
ifdata.if_id = i+1; data->ifdata.if_id = i+1;
break; break;
} }
} }
@ -93,12 +109,12 @@ void _getifdata()
* function is a wrapper function for _countinterfaces && _getifdata.) * function is a wrapper function for _countinterfaces && _getifdata.)
* *
****************************************************************************/ ****************************************************************************/
int checkinterface(void) int checkinterface(netdata* data)
{ {
/* == 0 no network interfaces, -1 sth. went wrong */ /* == 0 no network interfaces, -1 sth. went wrong */
if ((ifdata.if_amount =_countinterfaces()) > 0) if ((data->ifdata.if_amount =_countinterfaces()) > 0)
_getifdata(); _getifdata();
return ifdata.if_valid; return data->ifdata.if_valid;
} }
/****************************************************************************** /******************************************************************************
@ -109,38 +125,36 @@ int checkinterface(void)
* *
*****************************************************************************/ *****************************************************************************/
int get_stat(void) int get_stat(netdata* data)
{ {
int i,fd, ret=-1; int i,fd, ret=-1;
static int wait_pcks_counter=WAIT_PCKS_COUNTER+1;
unsigned int len; unsigned int len;
unsigned long rx_o, tx_o; unsigned long rx_o, tx_o;
struct nmparms params, params2; struct nmparms params, params2;
mib_ifEntry *if_buf; mib_ifEntry *if_buf;
static nmapi_logstat *if_ptr = (nmapi_logstat *) 0; if (data->ifdata.if_valid == 1 && (fd = open_mib("/dev/lan", O_RDWR, 0, 0)) >= 0)
if (ifdata.if_valid == 1 && (fd = open_mib("/dev/lan", O_RDWR, 0, 0)) >= 0)
{ {
if ((if_buf = (mib_ifEntry *) malloc (sizeof(mib_ifEntry))) != 0) if ((if_buf = (mib_ifEntry *) malloc (sizeof(mib_ifEntry))) != 0)
{ {
if_buf->ifIndex = ifdata.if_id; if_buf->ifIndex = data->ifdata.if_id;
params.objid = ID_ifEntry; params.objid = ID_ifEntry;
params.buffer = if_buf; params.buffer = if_buf;
len = (unsigned int) sizeof(mib_ifEntry); len = (unsigned int) sizeof(mib_ifEntry);
params.len = &len; params.len = &len;
if ((ret = get_mib_info(fd, &params)) == 0) if ((ret = get_mib_info(fd, &params)) == 0)
{ {
rx_o = stats.rx_bytes; tx_o = stats.tx_bytes; rx_o = data->stats.rx_bytes; tx_o = data->stats.tx_bytes;
stats.tx_bytes = if_buf->ifOutOctets; data->stats.tx_bytes = if_buf->ifOutOctets;
stats.rx_bytes = if_buf->ifInOctets; data->stats.rx_bytes = if_buf->ifInOctets;
stats.tx_errors = if_buf->ifOutErrors; data->stats.tx_errors = if_buf->ifOutErrors;
stats.rx_errors = if_buf->ifInErrors; data->stats.rx_errors = if_buf->ifInErrors;
if (rx_o > stats.rx_bytes) if (rx_o > data->stats.rx_bytes)
stats.rx_over++; data->stats.rx_over++;
if (tx_o > stats.tx_bytes) if (tx_o > data->stats.tx_bytes)
stats.tx_over++; data->stats.tx_over++;
} }
} }
free(if_buf); free(if_buf);
@ -150,29 +164,29 @@ int get_stat(void)
* With WAIT_PCKS_COUNTER=15 i save on my system 43% cpu usage.instead of * With WAIT_PCKS_COUNTER=15 i save on my system 43% cpu usage.instead of
* WAIT_PCKS_COUNTER=0 * WAIT_PCKS_COUNTER=0
*/ */
if( wait_pcks_counter > WAIT_PCKS_COUNTER ) if( data->wait_pcks_counter > WAIT_PCKS_COUNTER )
{ {
if ((if_ptr = (nmapi_logstat *) malloc(sizeof(nmapi_logstat) * ifdata.if_amount)) != 0 ) if ((if_ptr = (nmapi_logstat *) malloc(sizeof(nmapi_logstat) * data->ifdata.if_amount)) != 0 )
{ {
len = (unsigned int) ifdata.if_amount *sizeof(nmapi_logstat); len = (unsigned int) data->ifdata.if_amount *sizeof(nmapi_logstat);
if ((ret = get_logical_stat(if_ptr, &len)) == 0) if ((ret = get_logical_stat(if_ptr, &len)) == 0)
{ {
for (i=0; i <= ifdata.if_amount; i++) for (i=0; i <= data->ifdata.if_amount; i++)
{ {
if(if_ptr[i].ifindex == ifdata.if_id) if(if_ptr[i].ifindex == data->ifdata.if_id)
{ {
stats.tx_packets = if_ptr[i].out_packets; data->stats.tx_packets = if_ptr[i].out_packets;
stats.rx_packets = if_ptr[i].in_packets; data->stats.rx_packets = if_ptr[i].in_packets;
} }
} }
} }
} }
free(if_ptr); free(if_ptr);
wait_pcks_counter=0; data->wait_pcks_counter = 0;
} }
else else
{ {
wait_pcks_counter++; data->wait_pcks_counter++;
} }
} }
close_mib(fd); close_mib(fd);

View File

@ -1,5 +1,6 @@
#ifndef _HPUX_H_ #ifndef _HPUX_H_
#define _HPUX_H_ #define _HPUX_H_
extern int checkinterface(void); void init_osspecific(netdata* data);
extern int get_stat(void); int checkinterface(netdata* data);
int get_stat(netdata* data);
#endif #endif

View File

@ -6,7 +6,7 @@
* operating systems. * operating systems.
* *
***************************************************************************** *****************************************************************************
* $Id: if_media.c,v 1.1 2003/08/24 20:01:48 bwalle Exp $ * $Id: if_media.c,v 1.2 2003/08/25 21:08:58 bwalle Exp $
*****************************************************************************/ *****************************************************************************/
#if defined (__FreeBSD__) || (__OpenBSD__) || (__NetBSD__) || (__MicroBSD__) #if defined (__FreeBSD__) || (__OpenBSD__) || (__NetBSD__) || (__MicroBSD__)
@ -260,7 +260,7 @@ int get_if_speed(char *ifstring)
struct nmparms params; struct nmparms params;
mib_ifEntry * if_buf; mib_ifEntry * if_buf;
for (i=0; i <= ifdata.if_amount; i++) for (i=0; i <= data->ifdata.if_amount; i++)
{ {
if ((fd = open_mib("/dev/lan", O_RDWR, i, 0)) >= 0) if ((fd = open_mib("/dev/lan", O_RDWR, i, 0)) >= 0)
{ {
@ -273,7 +273,7 @@ int get_if_speed(char *ifstring)
if_buf->ifIndex = i+1; if_buf->ifIndex = i+1;
if ((ret = get_mib_info(fd, &params)) == 0) if ((ret = get_mib_info(fd, &params)) == 0)
{ {
if ( i+1 == ifdata.if_id) if ( i+1 == data->ifdata.if_id)
if (if_buf->ifOper == 1) if (if_buf->ifOper == 1)
speed = if_buf->ifSpeed/1000; speed = if_buf->ifSpeed/1000;
else else

View File

@ -1,4 +1,20 @@
/* $Id: linux.c,v 1.1 2003/08/24 20:01:48 bwalle Exp $ */ /* $Id: linux.c,v 1.2 2003/08/25 21:08:58 bwalle Exp $ */
/*****************************************************************************
*
* init_osspecific()
*
* Init function
*
****************************************************************************/
void init_osspecific(netdata* data)
{
/* nothing */
}
/***************************************************************************** /*****************************************************************************
* *
@ -9,7 +25,7 @@
* *
****************************************************************************/ ****************************************************************************/
int checkinterface(void) int checkinterface(netdata* data)
{ {
int interfacefound = FALSE; int interfacefound = FALSE;
unsigned int i; unsigned int i;
@ -20,7 +36,7 @@ int checkinterface(void)
for (i = 0; ifs[i].if_index; i++) for (i = 0; ifs[i].if_index; i++)
{ {
if (strcmp(ifs[i].if_name, ifdata.if_name) == 0) if (strcmp(ifs[i].if_name, data->ifdata.if_name) == 0)
{ {
interfacefound = TRUE; interfacefound = TRUE;
break; break;
@ -42,29 +58,29 @@ int checkinterface(void)
* *
*****************************************************************************/ *****************************************************************************/
int get_stat(void) int get_stat(netdata* data)
{ {
static int opened = 0; /* bwalle: Instead of the original code we open the file each time new. The
* performance difference is _very_ minimal. But I don't think that it's a good
* idea to keep the file open for a very long time for _each_ plugin instance.
*/
char buffer[BUFSIZE]; char buffer[BUFSIZE];
char *ptr; char *ptr;
char *devname; char *devname;
int dump; int dump;
int interfacefound; int interfacefound;
FILE* proc_net_dev;
unsigned long rx_o, tx_o; unsigned long rx_o, tx_o;
if (opened != 1) if ((proc_net_dev = fopen(PATH_NET_DEV, "r")) == NULL)
{ {
if ((proc_net_dev = fopen(PATH_NET_DEV, "r")) == NULL) fprintf(stderr, "cannot open %s!\nnot running Linux?\n",
{ PATH_NET_DEV);
fprintf(stderr, "cannot open %s!\nnot running Linux?\n", return 1;
PATH_NET_DEV);
exit(1);
}
opened++;
} }
/* backup old rx/tx values */ /* backup old rx/tx values */
rx_o = stats.rx_bytes; tx_o = stats.tx_bytes; rx_o = data->stats.rx_bytes; tx_o = data->stats.tx_bytes;
/* do not parse the first two lines as they only contain static garbage */ /* do not parse the first two lines as they only contain static garbage */
fseek(proc_net_dev, 0, SEEK_SET); fseek(proc_net_dev, 0, SEEK_SET);
@ -83,24 +99,25 @@ int get_stat(void)
ptr++; ptr++;
*ptr = '\0'; *ptr = '\0';
ptr++; ptr++;
if (!strcmp(devname, (char *) ifdata.if_name)) if (!strcmp(devname, (char *) data->ifdata.if_name))
{ {
/* read stats and fill struct */ /* read stats and fill struct */
sscanf(ptr, "%lg %lu %lu %d %d %d %d %d %lg %lu %lu %d %d %d %d %d", sscanf(ptr, "%lg %lu %lu %d %d %d %d %d %lg %lu %lu %d %d %d %d %d",
&stats.rx_bytes, &stats.rx_packets, &stats.rx_errors, &(data->stats.rx_bytes), &(data->stats.rx_packets), &(data->stats.rx_errors),
&dump, &dump, &dump, &dump, &dump, &dump, &dump, &dump, &dump, &dump,
&stats.tx_bytes, &stats.tx_packets, &stats.tx_errors, &(data->stats.tx_bytes), &(data->stats.tx_packets), &(data->stats.tx_errors),
&dump, &dump, &dump, &dump, &dump); &dump, &dump, &dump, &dump, &dump);
interfacefound = 1; interfacefound = 1;
continue; /* break, as we won't get any new information */ continue; /* break, as we won't get any new information */
} }
} }
fclose( proc_net_dev );
if (interfacefound) if (interfacefound)
{ {
if (rx_o > stats.rx_bytes) if (rx_o > data->stats.rx_bytes)
stats.rx_over++; data->stats.rx_over++;
if (tx_o > stats.tx_bytes) if (tx_o > data->stats.tx_bytes)
stats.tx_over++; data->stats.tx_over++;
} }
return (interfacefound == 1)? 0 : 1; return (interfacefound == 1)? 0 : 1;
} }

View File

@ -1,5 +1,10 @@
int checkinterface(void);
int get_stat(void); #include "net.h"
void init_osspecific(netdata* data);
int checkinterface(netdata* data);
int get_stat(netdata* data);
#ifdef __linux__ #ifdef __linux__
#define BUFSIZE 256 #define BUFSIZE 256
#endif #endif

View File

@ -1,4 +1,31 @@
/* $Id: netbsd.c,v 1.1 2003/08/24 20:01:48 bwalle Exp $ */ /* $Id: netbsd.c,v 1.2 2003/08/25 21:08:58 bwalle Exp $ */
/*****************************************************************************
*
* init_osspecific()
*
* Init function
*
****************************************************************************/
void init_osspecific(netdata* data)
{
mib_name1[0] = CTL_NET;
mib_name1[1] = PF_ROUTE;
mib_name1[2] = 0;
mib_name1[3] = 0;
mib_name1[4] = NET_RT_IFLIST;
mib_name1[5] = 0;
mib_name2[0] = CTL_NET;
mib_name2[1] = PF_ROUTE;
mib_name2[2] = 0;
mib_name2[3] = 0;
mib_name2[4] = NET_RT_IFLIST;
mib_name2[5] = 0;
}
/***************************************************************************** /*****************************************************************************
* *
@ -7,34 +34,31 @@
* check if a given interface exists, return TRUE if it does and FALSE if not * check if a given interface exists, return TRUE if it does and FALSE if not
* *
****************************************************************************/ ****************************************************************************/
int checkinterface() int checkinterface(netdata* data)
{ {
int validinterface = FALSE; int validinterface = FALSE;
static int mib_name[] = { CTL_NET, PF_ROUTE, 0, 0, NET_RT_IFLIST, 0 };
static char *buf;
static int alloc;
char *lim, *next; char *lim, *next;
struct if_msghdr *ifm, *nextifm; struct if_msghdr *ifm, *nextifm;
struct sockaddr_dl *sdl; struct sockaddr_dl *sdl;
size_t needed; size_t needed;
char s[32]; char s[32];
if (sysctl(mib_name, 6, NULL, &needed, NULL, 0) < 0) if (sysctl(data->mib_name1, 6, NULL, &needed, NULL, 0) < 0)
return FALSE; return FALSE;
if (alloc < (signed long) needed) if (data->alloc1 < (signed long) needed)
{ {
if (buf != NULL) if (data->buf1 != NULL)
free (buf); free (data->buf1);
buf = malloc(needed); data->buf1 = malloc(needed);
if (buf == NULL) if (data->buf1 == NULL)
return FALSE; return FALSE;
alloc = needed; data->alloc1 = needed;
} }
if (sysctl(mib_name, 6, buf, &needed, NULL, 0) < 0) if (sysctl(data->mib_name1, 6, data->buf1, &needed, NULL, 0) < 0)
return FALSE; return FALSE;
lim = buf + needed; lim = data->buf1 + needed;
next = buf; next = data->buf1;
while ((next < lim) && (validinterface == 0)) while ((next < lim) && (validinterface == 0))
{ {
ifm = (struct if_msghdr *)next; ifm = (struct if_msghdr *)next;
@ -58,7 +82,7 @@ int checkinterface()
/* search for the right network interface */ /* search for the right network interface */
if (sdl->sdl_family != AF_LINK) if (sdl->sdl_family != AF_LINK)
continue; continue;
if (strcmp(s, ifdata.if_name) != 0) if (strcmp(s, data->ifdata.if_name) != 0)
continue; continue;
else else
{ {
@ -77,11 +101,8 @@ int checkinterface()
* *
****************************************************************************/ ****************************************************************************/
int get_stat(void) int get_stat(netdata* data)
{ {
static int mib_name[] = { CTL_NET, PF_ROUTE, 0, 0, NET_RT_IFLIST, 0 };
static char *buf;
static int alloc;
char *lim, *next; char *lim, *next;
struct if_msghdr *ifm, *nextifm; struct if_msghdr *ifm, *nextifm;
struct sockaddr_dl *sdl; struct sockaddr_dl *sdl;
@ -89,22 +110,22 @@ int get_stat(void)
size_t needed; size_t needed;
unsigned long rx_o, tx_o; unsigned long rx_o, tx_o;
if (sysctl(mib_name, 6, NULL, &needed, NULL, 0) < 0) if (sysctl(data->mib_name2, 6, NULL, &needed, NULL, 0) < 0)
return 1; return 1;
if (alloc < (signed long) needed) if (data->alloc2 < (signed long) needed)
{ {
if (buf != NULL) if (data->buf2 != NULL)
free (buf); free (data->buf2);
buf = malloc(needed); data->buf2 = malloc(needed);
if (buf == NULL) if (data->buf2 == NULL)
return 1; return 1;
alloc = needed; data->alloc2 = needed;
} }
if (sysctl(mib_name, 6, buf, &needed, NULL, 0) < 0) if (sysctl(data->mib_name2, 6, data->buf2, &needed, NULL, 0) < 0)
return 1; return 1;
lim = buf + needed; lim = data->buf2 + needed;
next = buf; next = data->buf2;
while (next < lim) while (next < lim)
{ {
ifm = (struct if_msghdr *)next; ifm = (struct if_msghdr *)next;
@ -127,22 +148,22 @@ int get_stat(void)
s[sdl->sdl_nlen] = '\0'; s[sdl->sdl_nlen] = '\0';
/* search for the right network interface */ /* search for the right network interface */
if (strcmp(s, ifdata.if_name) != 0) if (strcmp(s, data->ifdata.if_name) != 0)
continue; continue;
rx_o = stats.rx_bytes; tx_o = stats.tx_bytes; rx_o = data->stats.rx_bytes; tx_o = data->stats.tx_bytes;
/* write stats */ /* write stats */
stats.tx_packets = ifm->ifm_data.ifi_opackets; data->stats.tx_packets = ifm->ifm_data.ifi_opackets;
stats.rx_packets = ifm->ifm_data.ifi_ipackets; data->stats.rx_packets = ifm->ifm_data.ifi_ipackets;
stats.rx_bytes = ifm->ifm_data.ifi_ibytes; data->stats.rx_bytes = ifm->ifm_data.ifi_ibytes;
stats.tx_bytes = ifm->ifm_data.ifi_obytes; data->stats.tx_bytes = ifm->ifm_data.ifi_obytes;
stats.rx_errors = ifm->ifm_data.ifi_ierrors; data->stats.rx_errors = ifm->ifm_data.ifi_ierrors;
stats.tx_errors = ifm->ifm_data.ifi_oerrors; data->stats.tx_errors = ifm->ifm_data.ifi_oerrors;
if (rx_o > stats.rx_bytes) if (rx_o > data->stats.rx_bytes)
stats.rx_over++; data->stats.rx_over++;
if (tx_o > stats.tx_bytes) if (tx_o > data->stats.tx_bytes)
stats.tx_over++; data->stats.tx_over++;
} }
} }
return 0; return 0;

View File

@ -1,2 +1,4 @@
int get_stat(void); void init_osspecific(netdata* data);
int checkinterface(void); int checkinterface(netdata* data);
int get_stat(netdata* data);

View File

@ -1,4 +1,30 @@
/* $Id: openbsd.c,v 1.1 2003/08/24 20:01:48 bwalle Exp $ */ /* $Id: openbsd.c,v 1.2 2003/08/25 21:08:58 bwalle Exp $ */
/*****************************************************************************
*
* init_osspecific()
*
* Init function
*
****************************************************************************/
void init_osspecific(netdata* data)
{
mib_name1[0] = CTL_NET;
mib_name1[1] = PF_ROUTE;
mib_name1[2] = 0;
mib_name1[3] = 0;
mib_name1[4] = NET_RT_IFLIST;
mib_name1[5] = 0;
mib_name2[0] = CTL_NET;
mib_name2[1] = PF_ROUTE;
mib_name2[2] = 0;
mib_name2[3] = 0;
mib_name2[4] = NET_RT_IFLIST;
mib_name2[5] = 0;
}
/***************************************************************************** /*****************************************************************************
* *
@ -7,35 +33,32 @@
* check if a given interface exists, return TRUE if it does and FALSE if not * check if a given interface exists, return TRUE if it does and FALSE if not
* *
****************************************************************************/ ****************************************************************************/
int checkinterface() int checkinterface(netdata* data)
{ {
int validinterface = FALSE; int validinterface = FALSE;
static int mib_name[] = { CTL_NET, PF_ROUTE, 0, 0, NET_RT_IFLIST, 0 };
static char *buf;
static int alloc;
char *lim, *next; char *lim, *next;
struct if_msghdr *ifm, *nextifm; struct if_msghdr *ifm, *nextifm;
struct sockaddr_dl *sdl; struct sockaddr_dl *sdl;
size_t needed; size_t needed;
char s[32]; char s[32];
if (sysctl(mib_name, 6, NULL, &needed, NULL, 0) < 0) if (sysctl(data->mib_name1, 6, NULL, &needed, NULL, 0) < 0)
return FALSE; return FALSE;
if (alloc < (signed long) needed) if (data->alloc1 < (signed long) needed)
{ {
if (buf != NULL) if (data->buf1 != NULL)
free (buf); free (data->buf1);
buf = malloc(needed); data->buf1 = malloc(needed);
if (buf == NULL) if (data->buf1 == NULL)
return FALSE; return FALSE;
alloc = needed; data->alloc1 = needed;
} }
if (sysctl(mib_name, 6, buf, &needed, NULL, 0) < 0) if (sysctl(data->mib_name1, 6, data->buf1, &needed, NULL, 0) < 0)
return FALSE; return FALSE;
lim = buf + needed; lim = data->buf1 + needed;
next = buf; next = data->buf1;
while ((next < lim) && (validinterface == 0)) while ((next < lim) && (validinterface == 0))
{ {
ifm = (struct if_msghdr *)next; ifm = (struct if_msghdr *)next;
@ -59,7 +82,7 @@ int checkinterface()
/* search for the right network interface */ /* search for the right network interface */
if (sdl->sdl_family != AF_LINK) if (sdl->sdl_family != AF_LINK)
continue; continue;
if (strcmp(s, ifdata.if_name) != 0) if (strcmp(s, data->ifdata.if_name) != 0)
continue; continue;
else else
{ {
@ -79,11 +102,8 @@ int checkinterface()
* *
****************************************************************************/ ****************************************************************************/
int get_stat(void) int get_stat(netdata* data)
{ {
static int mib_name[] = { CTL_NET, PF_ROUTE, 0, 0, NET_RT_IFLIST, 0 };
static char *buf;
static int alloc;
char *lim, *next; char *lim, *next;
struct if_msghdr *ifm, *nextifm; struct if_msghdr *ifm, *nextifm;
struct sockaddr_dl *sdl; struct sockaddr_dl *sdl;
@ -91,22 +111,22 @@ int get_stat(void)
size_t needed; size_t needed;
unsigned long rx_o, tx_o; unsigned long rx_o, tx_o;
if (sysctl(mib_name, 6, NULL, &needed, NULL, 0) < 0) if (sysctl(data->mib_name2, 6, NULL, &needed, NULL, 0) < 0)
return 1; return 1;
if (alloc < (signed long) needed) if (data->alloc2 < (signed long) needed)
{ {
if (buf != NULL) if (data->buf2 != NULL)
free (buf); free (data->buf2);
buf = malloc(needed); data->buf2 = malloc(needed);
if (buf == NULL) if (data->buf2 == NULL)
return 1; return 1;
alloc = needed; data->alloc2 = needed;
} }
if (sysctl(mib_name, 6, buf, &needed, NULL, 0) < 0) if (sysctl(data->mib_name2, 6, data->buf2, &needed, NULL, 0) < 0)
return 1; return 1;
lim = buf + needed; lim = data->buf2 + needed;
next = buf; next = data->buf2;
while (next < lim) while (next < lim)
{ {
ifm = (struct if_msghdr *)next; ifm = (struct if_msghdr *)next;
@ -128,24 +148,24 @@ int get_stat(void)
/* search for the right network interface */ /* search for the right network interface */
if (sdl->sdl_family != AF_LINK) if (sdl->sdl_family != AF_LINK)
continue; continue;
if (strcmp(sdl->sdl_data, ifdata.if_name) != 0) if (strcmp(sdl->sdl_data, data->ifdata.if_name) != 0)
continue; continue;
strncpy(s, sdl->sdl_data, sdl->sdl_nlen); strncpy(s, sdl->sdl_data, sdl->sdl_nlen);
s[sdl->sdl_nlen] = '\0'; s[sdl->sdl_nlen] = '\0';
rx_o = stats.rx_bytes; tx_o = stats.tx_bytes; rx_o = data->stats.rx_bytes; tx_o = data->stats.tx_bytes;
/* write stats */ /* write stats */
stats.tx_packets = ifm->ifm_data.ifi_opackets; data->stats.tx_packets = ifm->ifm_data.ifi_opackets;
stats.rx_packets = ifm->ifm_data.ifi_ipackets; data->stats.rx_packets = ifm->ifm_data.ifi_ipackets;
stats.rx_bytes = ifm->ifm_data.ifi_ibytes; data->stats.rx_bytes = ifm->ifm_data.ifi_ibytes;
stats.tx_bytes = ifm->ifm_data.ifi_obytes; data->stats.tx_bytes = ifm->ifm_data.ifi_obytes;
stats.rx_errors = ifm->ifm_data.ifi_ierrors; data->stats.rx_errors = ifm->ifm_data.ifi_ierrors;
stats.tx_errors = ifm->ifm_data.ifi_oerrors; data->stats.tx_errors = ifm->ifm_data.ifi_oerrors;
if (rx_o > stats.rx_bytes) if (rx_o > data->stats.rx_bytes)
stats.rx_over++; data->stats.rx_over++;
if (tx_o > stats.tx_bytes) if (tx_o > data->stats.tx_bytes)
stats.tx_over++; data->stats.tx_over++;
} }
} }
return 0; return 0;

View File

@ -1,2 +1,3 @@
int get_stat(void); void init_osspecific(netdata* data);
int checkinterface(void); int checkinterface(netdata* data);
int get_stat(netdata* data);

View File

@ -1,4 +1,18 @@
/* $Id: solaris.c,v 1.1 2003/08/24 20:01:48 bwalle Exp $ */ /* $Id: solaris.c,v 1.2 2003/08/25 21:08:58 bwalle Exp $ */
/*****************************************************************************
*
* init_osspecific()
*
* Init function
*
****************************************************************************/
void init_osspecific(netdata* data)
{
/* nothing */
}
/***************************************************************************** /*****************************************************************************
* *
@ -8,7 +22,7 @@
* *
****************************************************************************/ ****************************************************************************/
int checkinterface() int checkinterface(netdata* data)
{ {
int validinterface = FALSE; int validinterface = FALSE;
int sockfd, i, numifs, numifreqs; int sockfd, i, numifs, numifreqs;
@ -64,7 +78,7 @@ int checkinterface()
perror("SIOCGIFFLAGS"); perror("SIOCGIFFLAGS");
continue; continue;
} }
if (!strcmp(ifdata.if_name, ifr.ifr_name) && (ifr.ifr_flags & IFF_UP)) if (!strcmp(data->ifdata.if_name, ifr.ifr_name) && (ifr.ifr_flags & IFF_UP))
{ {
validinterface = TRUE; validinterface = TRUE;
break; break;
@ -85,7 +99,7 @@ int checkinterface()
* *
****************************************************************************/ ****************************************************************************/
int get_stat(void) int get_stat(netdata* data)
{ {
kstat_t *ksp; kstat_t *ksp;
kstat_named_t *knp; kstat_named_t *knp;
@ -98,38 +112,38 @@ int get_stat(void)
return 1; return 1;
} }
rx_o = stats.rx_bytes; tx_o = stats.tx_bytes; rx_o = data->stats.rx_bytes; tx_o = data->stats.tx_bytes;
ksp = kstat_lookup(kc, NULL, -1, ifdata.if_name); ksp = kstat_lookup(kc, NULL, -1, data->ifdata.if_name);
if (ksp && kstat_read(kc, ksp, NULL) >= 0) if (ksp && kstat_read(kc, ksp, NULL) >= 0)
{ {
knp = (kstat_named_t *)kstat_data_lookup(ksp, "opackets"); knp = (kstat_named_t *)kstat_data_lookup(ksp, "opackets");
if (knp) if (knp)
stats.tx_packets = knp->value.ui32; data->stats.tx_packets = knp->value.ui32;
knp = (kstat_named_t *)kstat_data_lookup(ksp, "ipackets"); knp = (kstat_named_t *)kstat_data_lookup(ksp, "ipackets");
if (knp) if (knp)
stats.rx_packets = knp->value.ui32; data->stats.rx_packets = knp->value.ui32;
knp = (kstat_named_t *)kstat_data_lookup(ksp, "obytes"); knp = (kstat_named_t *)kstat_data_lookup(ksp, "obytes");
if (knp) if (knp)
stats.tx_bytes = knp->value.ui32; data->stats.tx_bytes = knp->value.ui32;
knp = (kstat_named_t *)kstat_data_lookup(ksp, "rbytes"); knp = (kstat_named_t *)kstat_data_lookup(ksp, "rbytes");
if (knp) if (knp)
stats.rx_bytes = knp->value.ui32; data->stats.rx_bytes = knp->value.ui32;
knp = (kstat_named_t *)kstat_data_lookup(ksp, "oerrors"); knp = (kstat_named_t *)kstat_data_lookup(ksp, "oerrors");
if (knp) if (knp)
stats.tx_errors = knp->value.ui32; data->stats.tx_errors = knp->value.ui32;
knp = (kstat_named_t *)kstat_data_lookup(ksp, "ierrors"); knp = (kstat_named_t *)kstat_data_lookup(ksp, "ierrors");
if (knp) if (knp)
stats.rx_errors = knp->value.ui32; data->stats.rx_errors = knp->value.ui32;
} }
kstat_close(kc); kstat_close(kc);
/* check for overflows */ /* check for overflows */
if (rx_o > stats.rx_bytes) if (rx_o > data->stats.rx_bytes)
stats.rx_over++; data->stats.rx_over++;
if (tx_o > stats.tx_bytes) if (tx_o > data->stats.tx_bytes)
stats.tx_over++; data->stats.tx_over++;
return 0; return 0;
} }

View File

@ -1,2 +1,4 @@
int get_stat(void);
int checkinterface(void); void init_osspecific(netdata* data);
int checkinterface(netdata* data);
int get_stat(netdata* data);

View File

@ -1,4 +1,4 @@
/* $Id: unsupported.c,v 1.1 2003/08/24 20:01:48 bwalle Exp $ */ /* $Id: unsupported.c,v 1.2 2003/08/25 21:08:58 bwalle Exp $ */
/****************************************************************************** /******************************************************************************
* *
@ -8,7 +8,18 @@
* *
*****************************************************************************/ *****************************************************************************/
int get_stat(void) int get_stat(netdata* data)
{
return 0;
}
void init_osspecific(netdata* data)
{
/* do nothgin */
}
int checkinterface(netdata* data)
{ {
return 0; return 0;
} }

View File

@ -1 +1,3 @@
int get_stat(void); void init_osspecific(netdata* data);
int checkinterface(netdata* data);
int get_stat(netdata* data);

View File

@ -6,7 +6,7 @@
msgid "" msgid ""
msgstr "" msgstr ""
"Project-Id-Version: XFce 4\n" "Project-Id-Version: XFce 4\n"
"POT-Creation-Date: 2003-08-24 16:31+0200\n" "POT-Creation-Date: 2003-08-25 22:58+0200\n"
"PO-Revision-Date: 2003-08-15 15:38+0100\n" "PO-Revision-Date: 2003-08-15 15:38+0100\n"
"Last-Translator: Carles Mu-oz Gorriz <carlesmu@internautas.org>\n" "Last-Translator: Carles Mu-oz Gorriz <carlesmu@internautas.org>\n"
"Language-Team: ca <LL@li.org>\n" "Language-Team: ca <LL@li.org>\n"
@ -14,7 +14,7 @@ msgstr ""
"Content-Type: text/plain; charset=utf-8\n" "Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n" "Content-Transfer-Encoding: 8bit\n"
#: panel-plugin/netload.c:166 #: panel-plugin/netload.c:170
#, fuzzy, c-format #, fuzzy, c-format
msgid "" msgid ""
"Average of last 4 measures:\n" "Average of last 4 measures:\n"
@ -26,44 +26,44 @@ msgstr ""
"Sortint: %lld bit/s\n" "Sortint: %lld bit/s\n"
"Total: %lld bit/s" "Total: %lld bit/s"
#: panel-plugin/netload.c:748 #: panel-plugin/netload.c:752
msgid "Select color" msgid "Select color"
msgstr "Seleccioneu el color" msgstr "Seleccioneu el color"
#: panel-plugin/netload.c:799 #: panel-plugin/netload.c:803
msgid "Bar color (incoming):" msgid "Bar color (incoming):"
msgstr "Color de la barra (sortint):" msgstr "Color de la barra (sortint):"
#: panel-plugin/netload.c:800 #: panel-plugin/netload.c:804
msgid "Bar color (outgoing):" msgid "Bar color (outgoing):"
msgstr "Color de la barra (entrant):" msgstr "Color de la barra (entrant):"
#: panel-plugin/netload.c:803 #: panel-plugin/netload.c:807
#, fuzzy #, fuzzy
msgid "Maximum (incoming):" msgid "Maximum (incoming):"
msgstr "Color de la barra (sortint):" msgstr "Color de la barra (sortint):"
#: panel-plugin/netload.c:804 #: panel-plugin/netload.c:808
#, fuzzy #, fuzzy
msgid "Maximum (outgoing):" msgid "Maximum (outgoing):"
msgstr "Color de la barra (entrant):" msgstr "Color de la barra (entrant):"
#: panel-plugin/netload.c:827 #: panel-plugin/netload.c:831
msgid "Text to display:" msgid "Text to display:"
msgstr "Text a mostrar:" msgstr "Text a mostrar:"
#: panel-plugin/netload.c:857 #: panel-plugin/netload.c:861
msgid "Network device:" msgid "Network device:"
msgstr "Dispositiu de xarxa" msgstr "Dispositiu de xarxa"
#: panel-plugin/netload.c:884 #: panel-plugin/netload.c:888
msgid "Automatic maximum" msgid "Automatic maximum"
msgstr "" msgstr ""
#: panel-plugin/netload.c:916 #: panel-plugin/netload.c:920
msgid "kByte/s" msgid "kByte/s"
msgstr "" msgstr ""
#: panel-plugin/netload.c:1006 #: panel-plugin/netload.c:1010
msgid "Netload" msgid "Netload"
msgstr "Càrrega de red" msgstr "Càrrega de red"

View File

@ -3,7 +3,7 @@
msgid "" msgid ""
msgstr "" msgstr ""
"Project-Id-Version: de\n" "Project-Id-Version: de\n"
"POT-Creation-Date: 2003-08-24 16:31+0200\n" "POT-Creation-Date: 2003-08-25 22:58+0200\n"
"PO-Revision-Date: 2003-08-10 19:35+0200\n" "PO-Revision-Date: 2003-08-10 19:35+0200\n"
"Last-Translator: Bernhard Walle <bernhard.walle@gmx.de>\n" "Last-Translator: Bernhard Walle <bernhard.walle@gmx.de>\n"
"Language-Team: Deutsch <www.xfce.org>\n" "Language-Team: Deutsch <www.xfce.org>\n"
@ -11,7 +11,7 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n" "Content-Transfer-Encoding: 8bit\n"
"X-Generator: KBabel 1.0.2\n" "X-Generator: KBabel 1.0.2\n"
#: panel-plugin/netload.c:166 #: panel-plugin/netload.c:170
#, c-format #, c-format
msgid "" msgid ""
"Average of last 4 measures:\n" "Average of last 4 measures:\n"
@ -24,42 +24,42 @@ msgstr ""
"Ausgehend: %s kByte/s\n" "Ausgehend: %s kByte/s\n"
"Gesamt: %s kByte/s" "Gesamt: %s kByte/s"
#: panel-plugin/netload.c:748 #: panel-plugin/netload.c:752
msgid "Select color" msgid "Select color"
msgstr "Farbe auswählen" msgstr "Farbe auswählen"
#: panel-plugin/netload.c:799 #: panel-plugin/netload.c:803
msgid "Bar color (incoming):" msgid "Bar color (incoming):"
msgstr "Balkenfarbe (eingehend):" msgstr "Balkenfarbe (eingehend):"
#: panel-plugin/netload.c:800 #: panel-plugin/netload.c:804
msgid "Bar color (outgoing):" msgid "Bar color (outgoing):"
msgstr "Balkenfarbe (ausgehend):" msgstr "Balkenfarbe (ausgehend):"
#: panel-plugin/netload.c:803 #: panel-plugin/netload.c:807
msgid "Maximum (incoming):" msgid "Maximum (incoming):"
msgstr "Maximum (eingehend):" msgstr "Maximum (eingehend):"
#: panel-plugin/netload.c:804 #: panel-plugin/netload.c:808
msgid "Maximum (outgoing):" msgid "Maximum (outgoing):"
msgstr "Maximum (ausgehend):" msgstr "Maximum (ausgehend):"
#: panel-plugin/netload.c:827 #: panel-plugin/netload.c:831
msgid "Text to display:" msgid "Text to display:"
msgstr "Angezeigter Text:" msgstr "Angezeigter Text:"
#: panel-plugin/netload.c:857 #: panel-plugin/netload.c:861
msgid "Network device:" msgid "Network device:"
msgstr "Netzwerkschnittstelle:" msgstr "Netzwerkschnittstelle:"
#: panel-plugin/netload.c:884 #: panel-plugin/netload.c:888
msgid "Automatic maximum" msgid "Automatic maximum"
msgstr "Automatisches Maximum" msgstr "Automatisches Maximum"
#: panel-plugin/netload.c:916 #: panel-plugin/netload.c:920
msgid "kByte/s" msgid "kByte/s"
msgstr "kByte/s" msgstr "kByte/s"
#: panel-plugin/netload.c:1006 #: panel-plugin/netload.c:1010
msgid "Netload" msgid "Netload"
msgstr "Netzlast" msgstr "Netzlast"

View File

@ -6,7 +6,7 @@
msgid "" msgid ""
msgstr "" msgstr ""
"Project-Id-Version: xfce4-netload 1.0\n" "Project-Id-Version: xfce4-netload 1.0\n"
"POT-Creation-Date: 2003-08-24 16:31+0200\n" "POT-Creation-Date: 2003-08-25 22:58+0200\n"
"PO-Revision-Date: 2003-08-15 11:08+0300\n" "PO-Revision-Date: 2003-08-15 11:08+0300\n"
"Last-Translator: Mantas <zaz@xxx.lt>\n" "Last-Translator: Mantas <zaz@xxx.lt>\n"
"Language-Team: <komp_lt@konferencijos.lt>\n" "Language-Team: <komp_lt@konferencijos.lt>\n"
@ -14,7 +14,7 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n" "Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n" "Content-Transfer-Encoding: 8bit\n"
#: panel-plugin/netload.c:166 #: panel-plugin/netload.c:170
#, fuzzy, c-format #, fuzzy, c-format
msgid "" msgid ""
"Average of last 4 measures:\n" "Average of last 4 measures:\n"
@ -26,44 +26,44 @@ msgstr ""
"Siunčiami: %lld bitų/s\n" "Siunčiami: %lld bitų/s\n"
"Viso: %lld bitų/s" "Viso: %lld bitų/s"
#: panel-plugin/netload.c:748 #: panel-plugin/netload.c:752
msgid "Select color" msgid "Select color"
msgstr "Pasirinkite spalvą" msgstr "Pasirinkite spalvą"
#: panel-plugin/netload.c:799 #: panel-plugin/netload.c:803
msgid "Bar color (incoming):" msgid "Bar color (incoming):"
msgstr "Juostos spalva (gaunami duomenys)" msgstr "Juostos spalva (gaunami duomenys)"
#: panel-plugin/netload.c:800 #: panel-plugin/netload.c:804
msgid "Bar color (outgoing):" msgid "Bar color (outgoing):"
msgstr "Juostos spalva (siunčiami duomenys)" msgstr "Juostos spalva (siunčiami duomenys)"
#: panel-plugin/netload.c:803 #: panel-plugin/netload.c:807
#, fuzzy #, fuzzy
msgid "Maximum (incoming):" msgid "Maximum (incoming):"
msgstr "Juostos spalva (gaunami duomenys)" msgstr "Juostos spalva (gaunami duomenys)"
#: panel-plugin/netload.c:804 #: panel-plugin/netload.c:808
#, fuzzy #, fuzzy
msgid "Maximum (outgoing):" msgid "Maximum (outgoing):"
msgstr "Juostos spalva (siunčiami duomenys)" msgstr "Juostos spalva (siunčiami duomenys)"
#: panel-plugin/netload.c:827 #: panel-plugin/netload.c:831
msgid "Text to display:" msgid "Text to display:"
msgstr "Rodomas tekstas:" msgstr "Rodomas tekstas:"
#: panel-plugin/netload.c:857 #: panel-plugin/netload.c:861
msgid "Network device:" msgid "Network device:"
msgstr "Tinklo įrenginys" msgstr "Tinklo įrenginys"
#: panel-plugin/netload.c:884 #: panel-plugin/netload.c:888
msgid "Automatic maximum" msgid "Automatic maximum"
msgstr "" msgstr ""
#: panel-plugin/netload.c:916 #: panel-plugin/netload.c:920
msgid "kByte/s" msgid "kByte/s"
msgstr "" msgstr ""
#: panel-plugin/netload.c:1006 #: panel-plugin/netload.c:1010
msgid "Netload" msgid "Netload"
msgstr "Tinklo apkrovimas" msgstr "Tinklo apkrovimas"

View File

@ -7,7 +7,7 @@
msgid "" msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2003-08-24 16:31+0200\n" "POT-Creation-Date: 2003-08-25 22:58+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -15,7 +15,7 @@ msgstr ""
"Content-Type: text/plain; charset=CHARSET\n" "Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n" "Content-Transfer-Encoding: 8bit\n"
#: panel-plugin/netload.c:166 #: panel-plugin/netload.c:170
#, c-format #, c-format
msgid "" msgid ""
"Average of last 4 measures:\n" "Average of last 4 measures:\n"
@ -24,42 +24,42 @@ msgid ""
"Total: %s kByte/s" "Total: %s kByte/s"
msgstr "" msgstr ""
#: panel-plugin/netload.c:748 #: panel-plugin/netload.c:752
msgid "Select color" msgid "Select color"
msgstr "" msgstr ""
#: panel-plugin/netload.c:799 #: panel-plugin/netload.c:803
msgid "Bar color (incoming):" msgid "Bar color (incoming):"
msgstr "" msgstr ""
#: panel-plugin/netload.c:800 #: panel-plugin/netload.c:804
msgid "Bar color (outgoing):" msgid "Bar color (outgoing):"
msgstr "" msgstr ""
#: panel-plugin/netload.c:803 #: panel-plugin/netload.c:807
msgid "Maximum (incoming):" msgid "Maximum (incoming):"
msgstr "" msgstr ""
#: panel-plugin/netload.c:804 #: panel-plugin/netload.c:808
msgid "Maximum (outgoing):" msgid "Maximum (outgoing):"
msgstr "" msgstr ""
#: panel-plugin/netload.c:827 #: panel-plugin/netload.c:831
msgid "Text to display:" msgid "Text to display:"
msgstr "" msgstr ""
#: panel-plugin/netload.c:857 #: panel-plugin/netload.c:861
msgid "Network device:" msgid "Network device:"
msgstr "" msgstr ""
#: panel-plugin/netload.c:884 #: panel-plugin/netload.c:888
msgid "Automatic maximum" msgid "Automatic maximum"
msgstr "" msgstr ""
#: panel-plugin/netload.c:916 #: panel-plugin/netload.c:920
msgid "kByte/s" msgid "kByte/s"
msgstr "" msgstr ""
#: panel-plugin/netload.c:1006 #: panel-plugin/netload.c:1010
msgid "Netload" msgid "Netload"
msgstr "" msgstr ""