2003-08-25 04:05:32 +08:00
|
|
|
#include <netio.h>
|
|
|
|
#define WAIT_PCKS_COUNTER 15
|
|
|
|
|
2003-08-31 20:54:36 +08:00
|
|
|
/* $Id: hpux.c,v 1.3 2003/08/31 12:54:36 bwalle Exp $ */
|
2003-08-26 05:08:58 +08:00
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
*
|
|
|
|
* init_osspecific()
|
|
|
|
*
|
|
|
|
* Init function
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void init_osspecific(netdata* data)
|
|
|
|
{
|
|
|
|
wait_pcks_counter = WAIT_PCKS_COUNTER+1;
|
2003-08-31 20:54:36 +08:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
fprintf( stderr, "The netload plugin was initialized for HP_UX.\n" );
|
|
|
|
#endif
|
|
|
|
|
2003-08-26 05:08:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-08-25 04:05:32 +08:00
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
*
|
|
|
|
* _countinterfaces()
|
|
|
|
*
|
|
|
|
* count all network interfaces in the system. This function is intended to
|
|
|
|
* use it only in hpux.c
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int _countinterfaces(void)
|
|
|
|
{
|
|
|
|
int val, num_iface=-1, sd;
|
|
|
|
if ((sd = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
|
|
|
|
return (-1);
|
|
|
|
|
|
|
|
if (ioctl(sd, SIOCGIFNUM, &val) != -1)
|
|
|
|
num_iface = val;
|
|
|
|
close(sd);
|
|
|
|
|
|
|
|
return num_iface;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
*
|
|
|
|
* _getifdata()
|
|
|
|
*
|
|
|
|
* get the Interface-ID, the Interface-Speed, and over all, check if the
|
|
|
|
* given interface really exists. This function is intended to use it only in
|
|
|
|
* hpux.c
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void _getifdata()
|
|
|
|
{
|
|
|
|
int buffer, fd, val, ret = -1;
|
|
|
|
unsigned int len, i;
|
2003-08-26 05:08:58 +08:00
|
|
|
char tmpinterfacestring[sizeof(data->ifdata.if_name)+1],*strstrmatch;
|
2003-08-25 04:05:32 +08:00
|
|
|
struct nmparms params;
|
|
|
|
mib_ifEntry * if_buf;
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The interface description is more then the pure devicename.
|
|
|
|
* Let's do some formating to allow a propper pattern matching
|
|
|
|
*/
|
2003-08-26 05:08:58 +08:00
|
|
|
strcpy(tmpinterfacestring,data->ifdata.if_name);
|
2003-08-25 04:05:32 +08:00
|
|
|
strcat(tmpinterfacestring," ");
|
|
|
|
|
2003-08-26 05:08:58 +08:00
|
|
|
for (i=0; i <= data->ifdata.if_amount; i++)
|
2003-08-25 04:05:32 +08:00
|
|
|
{
|
|
|
|
if ((fd = open_mib("/dev/lan", O_RDWR, i, 0)) >= 0)
|
|
|
|
{
|
|
|
|
if ((if_buf = (mib_ifEntry *) malloc (sizeof(mib_ifEntry))) != 0) {
|
|
|
|
params.objid = ID_ifEntry;
|
|
|
|
params.buffer = if_buf;
|
|
|
|
len = sizeof(mib_ifEntry);
|
|
|
|
params.len = &len;
|
|
|
|
if_buf->ifIndex = i+1;
|
|
|
|
if ((ret = get_mib_info(fd, ¶ms)) == 0) {
|
|
|
|
/*
|
|
|
|
* The interface given by the user must start at the
|
|
|
|
* beginning of if_buf->ifDescr. If that's the case,
|
|
|
|
* strstrmatch is equal to if_buf->ifDescr. If not,
|
|
|
|
* strstrmatch might be a subset of if_buf->ifDescr,
|
|
|
|
* or NULL
|
|
|
|
*/
|
|
|
|
strstrmatch = strstr(if_buf->ifDescr, (char *)tmpinterfacestring);
|
|
|
|
if ( strstrmatch && (strcmp(strstrmatch,if_buf->ifDescr)== 0))
|
|
|
|
{
|
2003-08-26 05:08:58 +08:00
|
|
|
data->ifdata.if_valid = 1;
|
|
|
|
data->ifdata.if_id = i+1;
|
2003-08-25 04:05:32 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(if_buf);
|
|
|
|
close_mib(fd);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
*
|
|
|
|
* checkinterface()
|
|
|
|
*
|
|
|
|
* check if a given interface exists, return 1 if it does and 0 if not (This
|
|
|
|
* function is a wrapper function for _countinterfaces && _getifdata.)
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2003-08-26 05:08:58 +08:00
|
|
|
int checkinterface(netdata* data)
|
2003-08-25 04:05:32 +08:00
|
|
|
{
|
|
|
|
/* == 0 no network interfaces, -1 sth. went wrong */
|
2003-08-26 05:08:58 +08:00
|
|
|
if ((data->ifdata.if_amount =_countinterfaces()) > 0)
|
2003-08-25 04:05:32 +08:00
|
|
|
_getifdata();
|
2003-08-26 05:08:58 +08:00
|
|
|
return data->ifdata.if_valid;
|
2003-08-25 04:05:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
*
|
|
|
|
* get_stat()
|
|
|
|
*
|
|
|
|
* stub function for all unsupported operating systems
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2003-08-26 05:08:58 +08:00
|
|
|
int get_stat(netdata* data)
|
2003-08-25 04:05:32 +08:00
|
|
|
{
|
|
|
|
int i,fd, ret=-1;
|
|
|
|
unsigned int len;
|
|
|
|
unsigned long rx_o, tx_o;
|
|
|
|
struct nmparms params, params2;
|
|
|
|
mib_ifEntry *if_buf;
|
|
|
|
|
2003-08-26 05:08:58 +08:00
|
|
|
if (data->ifdata.if_valid == 1 && (fd = open_mib("/dev/lan", O_RDWR, 0, 0)) >= 0)
|
2003-08-25 04:05:32 +08:00
|
|
|
{
|
|
|
|
if ((if_buf = (mib_ifEntry *) malloc (sizeof(mib_ifEntry))) != 0)
|
|
|
|
{
|
2003-08-26 05:08:58 +08:00
|
|
|
if_buf->ifIndex = data->ifdata.if_id;
|
2003-08-25 04:05:32 +08:00
|
|
|
params.objid = ID_ifEntry;
|
|
|
|
params.buffer = if_buf;
|
|
|
|
len = (unsigned int) sizeof(mib_ifEntry);
|
|
|
|
params.len = &len;
|
|
|
|
if ((ret = get_mib_info(fd, ¶ms)) == 0)
|
|
|
|
{
|
2003-08-26 05:08:58 +08:00
|
|
|
rx_o = data->stats.rx_bytes; tx_o = data->stats.tx_bytes;
|
2003-08-25 04:05:32 +08:00
|
|
|
|
2003-08-26 05:08:58 +08:00
|
|
|
data->stats.tx_bytes = if_buf->ifOutOctets;
|
|
|
|
data->stats.rx_bytes = if_buf->ifInOctets;
|
|
|
|
data->stats.tx_errors = if_buf->ifOutErrors;
|
|
|
|
data->stats.rx_errors = if_buf->ifInErrors;
|
2003-08-25 04:05:32 +08:00
|
|
|
|
2003-08-26 05:08:58 +08:00
|
|
|
if (rx_o > data->stats.rx_bytes)
|
|
|
|
data->stats.rx_over++;
|
|
|
|
if (tx_o > data->stats.tx_bytes)
|
|
|
|
data->stats.tx_over++;
|
2003-08-25 04:05:32 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
free(if_buf);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Getting the tx/rx packets every run often hurts to much performance
|
|
|
|
* With WAIT_PCKS_COUNTER=15 i save on my system 43% cpu usage.instead of
|
|
|
|
* WAIT_PCKS_COUNTER=0
|
|
|
|
*/
|
2003-08-26 05:08:58 +08:00
|
|
|
if( data->wait_pcks_counter > WAIT_PCKS_COUNTER )
|
2003-08-25 04:05:32 +08:00
|
|
|
{
|
2003-08-26 05:08:58 +08:00
|
|
|
if ((if_ptr = (nmapi_logstat *) malloc(sizeof(nmapi_logstat) * data->ifdata.if_amount)) != 0 )
|
2003-08-25 04:05:32 +08:00
|
|
|
{
|
2003-08-26 05:08:58 +08:00
|
|
|
len = (unsigned int) data->ifdata.if_amount *sizeof(nmapi_logstat);
|
2003-08-25 04:05:32 +08:00
|
|
|
if ((ret = get_logical_stat(if_ptr, &len)) == 0)
|
|
|
|
{
|
2003-08-26 05:08:58 +08:00
|
|
|
for (i=0; i <= data->ifdata.if_amount; i++)
|
2003-08-25 04:05:32 +08:00
|
|
|
{
|
2003-08-26 05:08:58 +08:00
|
|
|
if(if_ptr[i].ifindex == data->ifdata.if_id)
|
2003-08-25 04:05:32 +08:00
|
|
|
{
|
2003-08-26 05:08:58 +08:00
|
|
|
data->stats.tx_packets = if_ptr[i].out_packets;
|
|
|
|
data->stats.rx_packets = if_ptr[i].in_packets;
|
2003-08-25 04:05:32 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(if_ptr);
|
2003-08-26 05:08:58 +08:00
|
|
|
data->wait_pcks_counter = 0;
|
2003-08-25 04:05:32 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-08-26 05:08:58 +08:00
|
|
|
data->wait_pcks_counter++;
|
2003-08-25 04:05:32 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
close_mib(fd);
|
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|