Added use_isdn' and lockfile' arguments. When `use_isdn' is TRUE, we

2000-01-22  Martin Baulig  <martin@home-of-linux.org>

	* include/glibtop/ppp.h (glibtop_get_ppp): Added `use_isdn' and
	`lockfile' arguments. When `use_isdn' is TRUE, we return ISDN
	statistics, otherwise `lockfile' is expected to be the modem
	lockfile and we return PPP statistics for that Modem.

	Note that for Modem statistics, you need to set both `device' and
	`lockfile' for some sysdeps ports; so if you have more than one PPP
	connection active and want to get statistics on the second one you
	need to set `device' to 1 and `lockfile' to the correct modem lockfile.

	* include/glibtop/error.h (GLIBTOP_ERROR_NEED_MODEM_LOCKFILE): New
	error constant; this is returned when you call glibtop_get_ppp ()
	without a modem lockfile and the current sysdeps port requires it.
This commit is contained in:
Martin Baulig
2000-01-22 17:33:51 +00:00
committed by Martin Baulig
parent 8da7cfd032
commit 931ba0fa8d
11 changed files with 158 additions and 24 deletions

View File

@@ -1,3 +1,19 @@
2000-01-22 Martin Baulig <martin@home-of-linux.org>
* include/glibtop/ppp.h (glibtop_get_ppp): Added `use_isdn' and
`lockfile' arguments. When `use_isdn' is TRUE, we return ISDN
statistics, otherwise `lockfile' is expected to be the modem
lockfile and we return PPP statistics for that Modem.
Note that for Modem statistics, you need to set both `device' and
`lockfile' for some sysdeps ports; so if you have more than one PPP
connection active and want to get statistics on the second one you
need to set `device' to 1 and `lockfile' to the correct modem lockfile.
* include/glibtop/error.h (GLIBTOP_ERROR_NEED_MODEM_LOCKFILE): New
error constant; this is returned when you call glibtop_get_ppp ()
without a modem lockfile and the current sysdeps port requires it.
2000-01-18 Martin Baulig <martin@home-of-linux.org>
* lib/sysdeps-init-osf1.c: New file. Added sysdeps initialization

View File

@@ -21,4 +21,4 @@ retval|@fsusage|ulong(blocks,bfree,bavail,files,ffree)|string(mount_dir)
array(glibtop_interface)|interface_names|array|ulong(interface,number,instance,strategy)
retval|netinfo|ulong(if_flags,transport,mtu,subnet,address)|string(interface):unsigned(transport)
retval|netload|ulong(packets_in,packets_out,packets_total,bytes_in,bytes_out,bytes_total,errors_in,errors_out,errors_total,collisions)|string(interface):unsigned(transport,protocol)
retval|ppp|ulong(state,bytes_in,bytes_out)|ushort(device)
retval|ppp|ulong(state,bytes_in,bytes_out)|ushort(device,use_isdn):string(lockfile)

View File

@@ -49,8 +49,9 @@ BEGIN_LIBGTOP_DECLS
#define GLIBTOP_ERROR_NO_BACKEND_OPENED 12
#define GLIBTOP_ERROR_DEMARSHAL_ERROR 13
#define GLIBTOP_ERROR_NEED_MODEM_LOCKFILE 14
#define GLIBTOP_MAX_ERROR 14
#define GLIBTOP_MAX_ERROR 15
char *
glibtop_get_error_string_l (glibtop *server, unsigned error_number);

View File

@@ -53,7 +53,7 @@ struct _glibtop_ppp
bytes_out; /* GLIBTOP_PPP_BYTES_OUT */
};
#define glibtop_get_ppp(ppp,device) glibtop_get_ppp_l(glibtop_global_server, ppp, device)
#define glibtop_get_ppp(ppp,device,use_isdn,lockfile) glibtop_get_ppp_l(glibtop_global_server, ppp, device, use_isdn, lockfile)
#if GLIBTOP_SUID_PPP
#define glibtop_get_ppp_r glibtop_get_ppp_p
@@ -61,14 +61,14 @@ struct _glibtop_ppp
#define glibtop_get_ppp_r glibtop_get_ppp_s
#endif
int glibtop_get_ppp_l (glibtop *server, glibtop_ppp *buf, unsigned short device);
int glibtop_get_ppp_l (glibtop *server, glibtop_ppp *buf, unsigned short device, unsigned short use_isdn, const char *lockfile);
#if GLIBTOP_SUID_PPP
int glibtop_init_ppp_p (glibtop *server);
int glibtop_get_ppp_p (glibtop *server, glibtop_ppp *buf, unsigned short device);
int glibtop_get_ppp_p (glibtop *server, glibtop_ppp *buf, unsigned short device, unsigned short use_isdn, const char *lockfile);
#else
int glibtop_init_ppp_s (glibtop *server);
int glibtop_get_ppp_s (glibtop *server, glibtop_ppp *buf, unsigned short device);
int glibtop_get_ppp_s (glibtop *server, glibtop_ppp *buf, unsigned short device, unsigned short use_isdn, const char *lockfile);
#endif
#ifdef GLIBTOP_NAMES

View File

@@ -93,7 +93,8 @@ glibtop_init_ppp_p (glibtop *server)
/* Provides information about ppp usage. */
int
glibtop_get_ppp_p (glibtop *server, glibtop_ppp *buf, unsigned short device)
glibtop_get_ppp_p (glibtop *server, glibtop_ppp *buf, unsigned short device,
unsigned short isdn, const char *lockfile)
{
#ifdef HAVE_I4B
#ifdef HAVE_I4B_ACCT

View File

@@ -182,7 +182,8 @@ static int is_ISDN_on (glibtop *server, int *online)
/* Provides PPP/ISDN information. */
int
glibtop_get_ppp_s (glibtop *server, glibtop_ppp *buf, unsigned short device)
glibtop_get_ppp_s (glibtop *server, glibtop_ppp *buf, unsigned short device,
unsigned short isdn, const char *lockfile)
{
int in, out, online;

View File

@@ -37,10 +37,34 @@
#include <glib.h>
#if !defined (_LIBC) && defined (__GNU_LIBRARY__) && __GNU_LIBRARY__ > 1
/* GNU LibC */
#include <net/if.h>
#include <netinet/ip_icmp.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <netinet/tcp.h>
#include <netinet/udp.h>
#include <net/if.h>
#include <net/if_ppp.h>
#else /* Libc 5 */
#include <linux/if.h>
#include <linux/in.h>
#include <linux/ip.h>
#include <linux/icmp.h>
#include <linux/tcp.h>
#include <linux/udp.h>
#include <linux/isdn.h>
#endif
static const unsigned long _glibtop_sysdeps_ppp =
(1L << GLIBTOP_PPP_STATE) + (1L << GLIBTOP_PPP_BYTES_IN) +
(1L << GLIBTOP_PPP_BYTES_OUT);
#ifdef SIOCDEVPRIVATE
static int ip_socket;
#endif
/* Init function. */
int
@@ -48,6 +72,12 @@ glibtop_init_ppp_s (glibtop *server)
{
server->sysdeps.ppp = _glibtop_sysdeps_ppp;
#ifdef SIOCDEVPRIVATE
/* open ip socket */
if ((ip_socket = socket (AF_INET, SOCK_DGRAM, 0)) < 0)
return -GLIBTOP_ERROR_NO_KERNEL_SUPPORT; /* should never happen */
#endif
return 0;
}
@@ -85,7 +115,8 @@ get_ISDN_stats (glibtop *server, int *in, int *out)
return TRUE;
}
static int is_ISDN_on (glibtop *server, int *online)
static int
is_ISDN_on (glibtop *server, int *online)
{
FILE *f = 0;
char buffer [BUFSIZ], *p;
@@ -179,10 +210,72 @@ static int is_ISDN_on (glibtop *server, int *online)
return TRUE;
}
static int
is_Modem_on (glibtop *server, const char *lock_file)
{
FILE *f = 0;
gchar buf[64];
pid_t pid = -1;
f = fopen (lock_file, "r");
if(!f) return FALSE;
if (fgets (buf, sizeof(buf), f) == NULL) {
fclose (f);
return FALSE;
}
fclose (f);
pid = (pid_t) strtol (buf, NULL, 10);
if (pid < 1 || (kill (pid, 0) == -1 && errno != EPERM)) return FALSE;
return TRUE;
}
static int
get_Modem_stats (int device, int *in, int *out)
{
struct ifreq ifreq;
struct ppp_stats stats;
char device_name [IFNAMSIZ];
sprintf (device_name, "ppp%d", device);
memset (&ifreq, 0, sizeof(ifreq));
strncpy (ifreq.ifr_ifrn.ifrn_name, device_name, IFNAMSIZ);
ifreq.ifr_ifru.ifru_data = (caddr_t)&stats;
#ifdef SIOCDEVPRIVATE
/* open ip socket */
if ((ip_socket = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
{
g_print("could not open an ip socket\n");
return 1;
}
if ((ioctl (ip_socket, SIOCDEVPRIVATE, (caddr_t)&ifreq) < 0)) {
*in = *out = 0; /* failure means ppp is not up */
return FALSE;
} else {
*in = stats.p.ppp_ibytes;
*out = stats.p.ppp_obytes;
return TRUE;
}
#else /* not SIOCDEVPRIVATE */
*in = *out = 0;
return FALSE;
#endif /* not SIOCDEVPRIVATE */
}
/* Provides PPP/ISDN information. */
int
glibtop_get_ppp_s (glibtop *server, glibtop_ppp *buf, unsigned short device)
glibtop_get_ppp_s (glibtop *server, glibtop_ppp *buf, unsigned short device,
unsigned short use_isdn, const char *lockfile)
{
int in, out, online;
@@ -190,17 +283,35 @@ glibtop_get_ppp_s (glibtop *server, glibtop_ppp *buf, unsigned short device)
memset (buf, 0, sizeof (glibtop_ppp));
if (is_ISDN_on (server, &online)) {
buf->state = online ? GLIBTOP_PPP_STATE_ONLINE :
GLIBTOP_PPP_STATE_HANGUP;
buf->flags |= (1L << GLIBTOP_PPP_STATE);
}
if (use_isdn) {
/* ISDN */
if (is_ISDN_on (server, &online)) {
buf->state = online ? GLIBTOP_PPP_STATE_ONLINE :
GLIBTOP_PPP_STATE_HANGUP;
buf->flags |= (1L << GLIBTOP_PPP_STATE);
}
if (get_ISDN_stats (server, &in, &out)) {
buf->bytes_in = in;
buf->bytes_out = out;
buf->flags |= (1L << GLIBTOP_PPP_BYTES_IN) |
(1L << GLIBTOP_PPP_BYTES_OUT);
if (get_ISDN_stats (server, &in, &out)) {
buf->bytes_in = in;
buf->bytes_out = out;
buf->flags |= (1L << GLIBTOP_PPP_BYTES_IN) |
(1L << GLIBTOP_PPP_BYTES_OUT);
}
} else {
/* Modem */
if (!lockfile)
return -GLIBTOP_ERROR_NEED_MODEM_LOCKFILE;
buf->state = is_Modem_on (server, lockfile) ?
GLIBTOP_PPP_STATE_ONLINE : GLIBTOP_PPP_STATE_HANGUP;
buf->flags |= (1L << GLIBTOP_PPP_STATE);
if (get_Modem_stats (device, &in, &out)) {
buf->bytes_in = in;
buf->bytes_out = out;
buf->flags |= (1L << GLIBTOP_PPP_BYTES_IN) |
(1L << GLIBTOP_PPP_BYTES_OUT);
}
}
return 0;

View File

@@ -42,7 +42,8 @@ glibtop_init_ppp_s (glibtop *server)
/* Provides PPP/ISDN information. */
int
glibtop_get_ppp_s (glibtop *server, glibtop_ppp *buf, unsigned short device)
glibtop_get_ppp_s (glibtop *server, glibtop_ppp *buf, unsigned short device,
unsigned short isdn, const char *lockfile)
{
memset (buf, 0, sizeof (glibtop_ppp));
return 0;

View File

@@ -42,7 +42,8 @@ glibtop_init_ppp_s (glibtop *server)
/* Provides PPP/ISDN information. */
int
glibtop_get_ppp_s (glibtop *server, glibtop_ppp *buf, unsigned short device)
glibtop_get_ppp_s (glibtop *server, glibtop_ppp *buf, unsigned short device,
unsigned short isdn, const char *lockfile)
{
memset (buf, 0, sizeof (glibtop_ppp));

View File

@@ -42,7 +42,8 @@ glibtop_init_ppp_s (glibtop *server)
/* Provides PPP/ISDN information. */
int
glibtop_get_ppp_s (glibtop *server, glibtop_ppp *buf, unsigned short device)
glibtop_get_ppp_s (glibtop *server, glibtop_ppp *buf, unsigned short device,
unsigned short isdn, const char *lockfile)
{
memset (buf, 0, sizeof (glibtop_ppp));

View File

@@ -44,7 +44,8 @@ glibtop_init_ppp_p (glibtop *server)
/* Provides PPP/ISDN information. */
int
glibtop_get_ppp_p (glibtop *server, glibtop_ppp *buf, unsigned short device)
glibtop_get_ppp_p (glibtop *server, glibtop_ppp *buf, unsigned short device,
unsigned short isdn, const char *lockfile)
{
glibtop_init_p (server, GLIBTOP_SYSDEPS_PPP, 0);