diff options
-rw-r--r-- | ChangeLog | 16 | ||||
-rw-r--r-- | features.def | 2 | ||||
-rw-r--r-- | include/glibtop/errors.h | 3 | ||||
-rw-r--r-- | include/glibtop/ppp.h | 8 | ||||
-rw-r--r-- | sysdeps/freebsd/ppp.c | 3 | ||||
-rw-r--r-- | sysdeps/kernel/ppp.c | 3 | ||||
-rw-r--r-- | sysdeps/linux/ppp.c | 133 | ||||
-rw-r--r-- | sysdeps/osf1/ppp.c | 3 | ||||
-rw-r--r-- | sysdeps/solaris/ppp.c | 3 | ||||
-rw-r--r-- | sysdeps/stub/ppp.c | 3 | ||||
-rw-r--r-- | sysdeps/stub_suid/ppp.c | 3 |
11 files changed, 157 insertions, 23 deletions
@@ -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 diff --git a/features.def b/features.def index 92ba9537..9202d5bd 100644 --- a/features.def +++ b/features.def @@ -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) diff --git a/include/glibtop/errors.h b/include/glibtop/errors.h index 56f5b9a7..6523047d 100644 --- a/include/glibtop/errors.h +++ b/include/glibtop/errors.h @@ -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); diff --git a/include/glibtop/ppp.h b/include/glibtop/ppp.h index 348b480a..29aabb85 100644 --- a/include/glibtop/ppp.h +++ b/include/glibtop/ppp.h @@ -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 diff --git a/sysdeps/freebsd/ppp.c b/sysdeps/freebsd/ppp.c index fef0c58d..0964eb86 100644 --- a/sysdeps/freebsd/ppp.c +++ b/sysdeps/freebsd/ppp.c @@ -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 diff --git a/sysdeps/kernel/ppp.c b/sysdeps/kernel/ppp.c index 6c1ced21..2fcb1ed1 100644 --- a/sysdeps/kernel/ppp.c +++ b/sysdeps/kernel/ppp.c @@ -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; diff --git a/sysdeps/linux/ppp.c b/sysdeps/linux/ppp.c index 6c1ced21..61ec7b8a 100644 --- a/sysdeps/linux/ppp.c +++ b/sysdeps/linux/ppp.c @@ -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; + 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); + } + } 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_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_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; diff --git a/sysdeps/osf1/ppp.c b/sysdeps/osf1/ppp.c index 84958472..8752e0d1 100644 --- a/sysdeps/osf1/ppp.c +++ b/sysdeps/osf1/ppp.c @@ -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; diff --git a/sysdeps/solaris/ppp.c b/sysdeps/solaris/ppp.c index c2599fb0..fdc348e9 100644 --- a/sysdeps/solaris/ppp.c +++ b/sysdeps/solaris/ppp.c @@ -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)); diff --git a/sysdeps/stub/ppp.c b/sysdeps/stub/ppp.c index c2599fb0..fdc348e9 100644 --- a/sysdeps/stub/ppp.c +++ b/sysdeps/stub/ppp.c @@ -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)); diff --git a/sysdeps/stub_suid/ppp.c b/sysdeps/stub_suid/ppp.c index 784df4b7..30a168c1 100644 --- a/sysdeps/stub_suid/ppp.c +++ b/sysdeps/stub_suid/ppp.c @@ -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); |