summaryrefslogtreecommitdiff
path: root/sysdeps
diff options
context:
space:
mode:
authorMartin Baulig <martin@home-of-linux.org>2000-01-22 17:33:51 +0000
committerMartin Baulig <martin@src.gnome.org>2000-01-22 17:33:51 +0000
commit931ba0fa8de50b72566d3fea9ed6152eb25b7a59 (patch)
tree024dcde2e12cfc285a7c3b20326c37af855db0da /sysdeps
parent8da7cfd0320f9906c176aa7e6aa70559ae2387a3 (diff)
downloadlibgtop-931ba0fa8de50b72566d3fea9ed6152eb25b7a59.tar.gz
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.
Diffstat (limited to 'sysdeps')
-rw-r--r--sysdeps/freebsd/ppp.c3
-rw-r--r--sysdeps/kernel/ppp.c3
-rw-r--r--sysdeps/linux/ppp.c133
-rw-r--r--sysdeps/osf1/ppp.c3
-rw-r--r--sysdeps/solaris/ppp.c3
-rw-r--r--sysdeps/stub/ppp.c3
-rw-r--r--sysdeps/stub_suid/ppp.c3
7 files changed, 134 insertions, 17 deletions
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);