Compare commits
	
		
			7 Commits
		
	
	
		
			LIBGTOP_2_
			...
			LIBGTOP_2_
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					84e45a6519 | ||
| 
						 | 
					96fe554afd | ||
| 
						 | 
					16e0c943b2 | ||
| 
						 | 
					f409c553f5 | ||
| 
						 | 
					b6a10fd8f7 | ||
| 
						 | 
					efeca4a865 | ||
| 
						 | 
					5e70932b66 | 
@@ -1,3 +1,11 @@
 | 
			
		||||
2005-07-13  Benoît Dejean  <TazForEver@dlfp.org>
 | 
			
		||||
 | 
			
		||||
	* NEWS: Released 2.11.2.
 | 
			
		||||
 | 
			
		||||
2005-07-06  Benoît Dejean  <TazForEver@dlfp.org>
 | 
			
		||||
 | 
			
		||||
	* configure.in: 2.11.2 post release version bump.
 | 
			
		||||
 | 
			
		||||
2005-07-03  Benoît Dejean  <TazForEver@dlfp.org>
 | 
			
		||||
 | 
			
		||||
	* NEWS: Released 2.11.1.
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										5
									
								
								NEWS
									
									
									
									
									
								
							
							
						
						
									
										5
									
								
								NEWS
									
									
									
									
									
								
							@@ -1,3 +1,8 @@
 | 
			
		||||
July &3, 2005: Overview of changes from 2.11.1 to 2.11.2
 | 
			
		||||
========================================================
 | 
			
		||||
* Linux:
 | 
			
		||||
  - little improvements for 2.6.
 | 
			
		||||
 | 
			
		||||
July 3, 2005: Overview of changes from 2.11.0 to 2.11.1
 | 
			
		||||
=======================================================
 | 
			
		||||
* Linux:
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										49
									
								
								configure.in
									
									
									
									
									
								
							
							
						
						
									
										49
									
								
								configure.in
									
									
									
									
									
								
							@@ -8,7 +8,7 @@ AC_CANONICAL_SYSTEM
 | 
			
		||||
 | 
			
		||||
LIBGTOP_MAJOR_VERSION=2
 | 
			
		||||
LIBGTOP_MINOR_VERSION=11
 | 
			
		||||
LIBGTOP_MICRO_VERSION=1
 | 
			
		||||
LIBGTOP_MICRO_VERSION=2
 | 
			
		||||
LIBGTOP_VERSION=$LIBGTOP_MAJOR_VERSION.$LIBGTOP_MINOR_VERSION.$LIBGTOP_MICRO_VERSION
 | 
			
		||||
AM_INIT_AUTOMAKE(libgtop, $LIBGTOP_VERSION)
 | 
			
		||||
 | 
			
		||||
@@ -195,28 +195,33 @@ AH_TEMPLATE(HAVE_VMGETINFO, [Define to 1 if you have the 'vmgetinfo' function in
 | 
			
		||||
AC_CHECK_LIB(perfstat, vmgetinfo, AC_DEFINE(HAVE_VMGETINFO))
 | 
			
		||||
 | 
			
		||||
dnl Solaris
 | 
			
		||||
AC_CHECK_LIB(kstat, kstat_open)
 | 
			
		||||
AC_CHECK_FUNCS(getloadavg swapctl)
 | 
			
		||||
AC_CHECK_HEADERS(procfs.h sys/procfs.h, break)
 | 
			
		||||
case "$host_os" in
 | 
			
		||||
     solaris*)
 | 
			
		||||
     AC_CHECK_LIB(kstat, kstat_open)
 | 
			
		||||
     AC_CHECK_FUNCS(getloadavg swapctl)
 | 
			
		||||
     AC_CHECK_HEADERS(procfs.h sys/procfs.h, break)
 | 
			
		||||
 | 
			
		||||
dnl Some versions of Solaris require -lelf for -lkvm
 | 
			
		||||
AC_CHECK_LIB(kvm, kvm_open,[
 | 
			
		||||
  LIBS="-lkvm $LIBS"
 | 
			
		||||
],[AC_MSG_CHECKING(for kvm_open in -lkvm with -lelf)
 | 
			
		||||
   AC_CACHE_VAL(ac_cv_lib_kvm_with_elf,
 | 
			
		||||
   [ac_save_LIBS="$LIBS"
 | 
			
		||||
    LIBS="-lkvm -lelf $LIBS"
 | 
			
		||||
    AC_TRY_LINK([char kvm_open();], [kvm_open()],
 | 
			
		||||
                ac_cv_lib_kvm_with_elf=yes, ac_cv_lib_kvm_with_elf=no)
 | 
			
		||||
    LIBS="$ac_save_LIBS"
 | 
			
		||||
   ])
 | 
			
		||||
   if test "$ac_cv_lib_kvm_with_elf" = "yes"; then
 | 
			
		||||
     AC_MSG_RESULT(yes)
 | 
			
		||||
     LIBS="-lkvm -lelf $LIBS"
 | 
			
		||||
   else
 | 
			
		||||
     AC_MSG_RESULT(no)
 | 
			
		||||
   fi
 | 
			
		||||
])
 | 
			
		||||
 | 
			
		||||
    dnl Some versions of Solaris require -lelf for -lkvm
 | 
			
		||||
    AC_CHECK_LIB(kvm, kvm_open,[
 | 
			
		||||
      LIBS="-lkvm $LIBS"
 | 
			
		||||
    ],[AC_MSG_CHECKING(for kvm_open in -lkvm with -lelf)
 | 
			
		||||
       AC_CACHE_VAL(ac_cv_lib_kvm_with_elf,
 | 
			
		||||
       [ac_save_LIBS="$LIBS"
 | 
			
		||||
        LIBS="-lkvm -lelf $LIBS"
 | 
			
		||||
        AC_TRY_LINK([char kvm_open();], [kvm_open()],
 | 
			
		||||
                    ac_cv_lib_kvm_with_elf=yes, ac_cv_lib_kvm_with_elf=no)
 | 
			
		||||
        LIBS="$ac_save_LIBS"
 | 
			
		||||
       ])
 | 
			
		||||
       if test "$ac_cv_lib_kvm_with_elf" = "yes"; then
 | 
			
		||||
         AC_MSG_RESULT(yes)
 | 
			
		||||
         LIBS="-lkvm -lelf $LIBS"
 | 
			
		||||
       else
 | 
			
		||||
         AC_MSG_RESULT(no)
 | 
			
		||||
       fi
 | 
			
		||||
    ])
 | 
			
		||||
     ;;
 | 
			
		||||
esac
 | 
			
		||||
 | 
			
		||||
dnl For DEC OSF1
 | 
			
		||||
AC_CHECK_LIB(mach, vm_statistics)
 | 
			
		||||
 
 | 
			
		||||
@@ -1,3 +1,8 @@
 | 
			
		||||
2005-07-04  Hendrik Richter  <hendi@gnome-de.org>
 | 
			
		||||
 | 
			
		||||
	* de.po: Fixed German translation by
 | 
			
		||||
	Jens Seidel <jensseidel@users.sf.net>.
 | 
			
		||||
 | 
			
		||||
2005-06-22  Abel Cheung  <maddog@linuxhall.org>
 | 
			
		||||
 | 
			
		||||
	* zh_TW.po: Fix language team reference.
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										6
									
								
								po/de.po
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								po/de.po
									
									
									
									
									
								
							@@ -11,8 +11,8 @@ msgstr ""
 | 
			
		||||
"Project-Id-Version: libgtop 2.5.0\n"
 | 
			
		||||
"Report-Msgid-Bugs-To: \n"
 | 
			
		||||
"POT-Creation-Date: 2005-01-16 16:59+0100\n"
 | 
			
		||||
"PO-Revision-Date: 2005-01-16 17:00+0100\n"
 | 
			
		||||
"Last-Translator: Hendrik Richter <hendrik@gnome-de.org>\n"
 | 
			
		||||
"PO-Revision-Date: 2005-07-04 17:11+0200\n"
 | 
			
		||||
"Last-Translator: Hendrik Richter <hendi@gnome-de.org>\n"
 | 
			
		||||
"Language-Team: German <gnome-de@gnome.org>\n"
 | 
			
		||||
"MIME-Version: 1.0\n"
 | 
			
		||||
"Content-Type: text/plain; charset=UTF-8\n"
 | 
			
		||||
@@ -967,7 +967,7 @@ msgstr "Benutzerdefiniertes Signal 2"
 | 
			
		||||
#~ msgstr "Sitzungskennung"
 | 
			
		||||
 | 
			
		||||
#~ msgid "Full device number of controlling terminal"
 | 
			
		||||
#~ msgstr "Volle Gerätenummer des kontrolierenden Terminals"
 | 
			
		||||
#~ msgstr "Volle Gerätenummer des kontrollierenden Terminals"
 | 
			
		||||
 | 
			
		||||
#~ msgid "Terminal process group ID"
 | 
			
		||||
#~ msgstr "Terminalprozessgruppenkennung"
 | 
			
		||||
 
 | 
			
		||||
@@ -1,3 +1,27 @@
 | 
			
		||||
2005-07-09  Benoît Dejean  <TazForEver@dlfp.org>
 | 
			
		||||
 | 
			
		||||
	* netload.c: (read_value), (linux_2_6_stats), (linux_2_0_stats),
 | 
			
		||||
	(linux_2_4_stats), (glibtop_get_netload_s): Split implementations.
 | 
			
		||||
	New (simpler) implementation for 2.6 (/sys is so nice ;)
 | 
			
		||||
 | 
			
		||||
2005-07-07  Benoît Dejean  <TazForEver@dlfp.org>
 | 
			
		||||
 | 
			
		||||
	* glibtop_private.c: (read_boot_time), (get_boot_time): Cached boot_time.
 | 
			
		||||
 | 
			
		||||
2005-07-06  Benoît Dejean  <TazForEver@dlfp.org>
 | 
			
		||||
 | 
			
		||||
	Et m***e ... CVS got me. I wanted to commit a single change on the
 | 
			
		||||
	toplevel configure.in but commited the whole tree. Sorry.
 | 
			
		||||
	
 | 
			
		||||
	* glibtop_private.c:
 | 
			
		||||
	* glibtop_private.h:
 | 
			
		||||
	* proctime.c:
 | 
			
		||||
	* uptime.c:
 | 
			
		||||
	
 | 
			
		||||
	Added new function get_boot_time.
 | 
			
		||||
	
 | 
			
		||||
	Retrieve boot_time from /proc/stat.
 | 
			
		||||
 | 
			
		||||
2005-06-13  Benoît Dejean  <TazForEver@dlfp.org>
 | 
			
		||||
 | 
			
		||||
	* glibtop_private.c: (try_file_to_buffer): Ensures buffer is 0-terminated.
 | 
			
		||||
 
 | 
			
		||||
@@ -96,3 +96,36 @@ file_to_buffer(glibtop *server, char *buffer, const char *filename)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
static unsigned long
 | 
			
		||||
read_boot_time(glibtop *server)
 | 
			
		||||
{
 | 
			
		||||
	char buffer[BUFSIZ];
 | 
			
		||||
	char *btime;
 | 
			
		||||
 | 
			
		||||
	file_to_buffer(server, buffer, "/proc/stat");
 | 
			
		||||
 | 
			
		||||
	btime = strstr(buffer, "btime");
 | 
			
		||||
 | 
			
		||||
	g_return_val_if_fail(btime != NULL, 0UL);
 | 
			
		||||
 | 
			
		||||
	btime = skip_token(btime);
 | 
			
		||||
	return strtoul(btime, NULL, 10);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
unsigned long
 | 
			
		||||
get_boot_time(glibtop *server)
 | 
			
		||||
{
 | 
			
		||||
	static unsigned long boot_time = 0UL;
 | 
			
		||||
 | 
			
		||||
	if(G_UNLIKELY(!boot_time))
 | 
			
		||||
	{
 | 
			
		||||
		boot_time = read_boot_time(server);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return boot_time;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -111,6 +111,12 @@ proc_stat_after_cmd (char *p)
 | 
			
		||||
		*p++ = '\0';
 | 
			
		||||
	return p;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
unsigned long
 | 
			
		||||
get_boot_time(glibtop *server) G_GNUC_INTERNAL;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
G_END_DECLS
 | 
			
		||||
 | 
			
		||||
#endif /* __LINUX__GLIBTOP_PRIVATE_H__ */
 | 
			
		||||
 
 | 
			
		||||
@@ -186,179 +186,179 @@ static void get_ipv6(glibtop *server, glibtop_netload *buf,
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/* Provides network statistics. */
 | 
			
		||||
static gboolean
 | 
			
		||||
read_value(glibtop *server,
 | 
			
		||||
	   const char *device,
 | 
			
		||||
	   const char *filename,
 | 
			
		||||
	   guint64 *value)
 | 
			
		||||
{
 | 
			
		||||
    char buffer[BUFSIZ];
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
glibtop_get_netload_s (glibtop *server, glibtop_netload *buf,
 | 
			
		||||
		       const char *interface)
 | 
			
		||||
    if(try_file_to_buffer(buffer,
 | 
			
		||||
			  "/sys/class/net/%s/statistics/%s",
 | 
			
		||||
			  device,
 | 
			
		||||
			  filename))
 | 
			
		||||
    {
 | 
			
		||||
	glibtop_warn_io_r(server,
 | 
			
		||||
			  "Failed to open \"/sys/class/net/%s/statistics/%s\"",
 | 
			
		||||
			  device,
 | 
			
		||||
			  filename);
 | 
			
		||||
 | 
			
		||||
	return FALSE;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    *value = strtoull(buffer, NULL, 10);
 | 
			
		||||
    return TRUE;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
linux_2_6_stats(glibtop *server,
 | 
			
		||||
		   glibtop_netload *buf,
 | 
			
		||||
		   const char *dev)
 | 
			
		||||
{
 | 
			
		||||
    if(read_value(server, dev, "rx_packets", &buf->packets_in))
 | 
			
		||||
	buf->flags |= (1 << GLIBTOP_NETLOAD_PACKETS_IN);
 | 
			
		||||
 | 
			
		||||
    if(read_value(server, dev, "tx_packets", &buf->packets_out))
 | 
			
		||||
	buf->flags |= (1 << GLIBTOP_NETLOAD_PACKETS_OUT);
 | 
			
		||||
 | 
			
		||||
    buf->packets_total = buf->packets_in + buf->packets_out;
 | 
			
		||||
    buf->flags |= (1 << GLIBTOP_NETLOAD_PACKETS_TOTAL);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    if(read_value(server, dev, "rx_bytes", &buf->bytes_in))
 | 
			
		||||
	buf->flags |= (1 << GLIBTOP_NETLOAD_BYTES_IN);
 | 
			
		||||
 | 
			
		||||
    if(read_value(server, dev, "tx_bytes", &buf->bytes_out))
 | 
			
		||||
	buf->flags |= (1 << GLIBTOP_NETLOAD_BYTES_OUT);
 | 
			
		||||
 | 
			
		||||
    buf->bytes_total = buf->bytes_in + buf->bytes_out;
 | 
			
		||||
    buf->flags |= (1 << GLIBTOP_NETLOAD_BYTES_TOTAL);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    if(read_value(server, dev, "rx_errors", &buf->errors_in))
 | 
			
		||||
	buf->flags |= (1 << GLIBTOP_NETLOAD_ERRORS_IN);
 | 
			
		||||
 | 
			
		||||
    if(read_value(server, dev, "tx_errors", &buf->errors_out))
 | 
			
		||||
	buf->flags |= (1 << GLIBTOP_NETLOAD_ERRORS_OUT);
 | 
			
		||||
 | 
			
		||||
    buf->errors_total = buf->errors_in + buf->errors_out;
 | 
			
		||||
    buf->flags |= (1 << GLIBTOP_NETLOAD_ERRORS_TOTAL);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    if(read_value(server, dev, "collisions", &buf->collisions))
 | 
			
		||||
	buf->flags |= (1 << GLIBTOP_NETLOAD_COLLISIONS);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
linux_2_0_stats(glibtop *server,
 | 
			
		||||
		glibtop_netload *buf,
 | 
			
		||||
		const char *interface)
 | 
			
		||||
{
 | 
			
		||||
    FILE *f;
 | 
			
		||||
    char buffer[BUFSIZ];
 | 
			
		||||
 | 
			
		||||
    f = fopen ("/proc/net/ip_acct", "r");
 | 
			
		||||
 | 
			
		||||
    if (!f) {
 | 
			
		||||
	glibtop_warn_io_r (server,
 | 
			
		||||
			   "Failed to open \"/proc/net/ip_acct\"");
 | 
			
		||||
	return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* Skip over the header line. */
 | 
			
		||||
    fgets (buffer, BUFSIZ-1, f);
 | 
			
		||||
 | 
			
		||||
    while (fgets (buffer, BUFSIZ-1, f)) {
 | 
			
		||||
	unsigned long long flags, packets, bytes;
 | 
			
		||||
	char *p, *dev;
 | 
			
		||||
 | 
			
		||||
	/* Skip over the network thing. */
 | 
			
		||||
	dev = skip_token (buffer) + 1;
 | 
			
		||||
	p = skip_token (dev);
 | 
			
		||||
	*p++ = 0;
 | 
			
		||||
 | 
			
		||||
	if (strcmp (dev, interface))
 | 
			
		||||
	    continue;
 | 
			
		||||
 | 
			
		||||
	p = skip_token (p);
 | 
			
		||||
 | 
			
		||||
	flags   = strtoull (p, &p, 16);
 | 
			
		||||
 | 
			
		||||
	p = skip_multiple_token (p, 2);
 | 
			
		||||
 | 
			
		||||
	packets = strtoull (p, &p, 0);
 | 
			
		||||
	bytes   = strtoull (p, &p, 0);
 | 
			
		||||
 | 
			
		||||
	if (flags & _GLIBTOP_IP_FW_ACCTIN) {
 | 
			
		||||
	    /* Incoming packets only. */
 | 
			
		||||
 | 
			
		||||
	    buf->packets_total += packets;
 | 
			
		||||
	    buf->packets_in += packets;
 | 
			
		||||
 | 
			
		||||
	    buf->bytes_total += bytes;
 | 
			
		||||
	    buf->bytes_in += bytes;
 | 
			
		||||
 | 
			
		||||
	    buf->flags |= _glibtop_sysdeps_netload_in;
 | 
			
		||||
 | 
			
		||||
	} else if (flags & _GLIBTOP_IP_FW_ACCTOUT) {
 | 
			
		||||
	    /* Outgoing packets only. */
 | 
			
		||||
 | 
			
		||||
	    buf->packets_total += packets;
 | 
			
		||||
	    buf->packets_out += packets;
 | 
			
		||||
 | 
			
		||||
	    buf->bytes_total += bytes;
 | 
			
		||||
	    buf->bytes_out += bytes;
 | 
			
		||||
 | 
			
		||||
	    buf->flags |= _glibtop_sysdeps_netload_out;
 | 
			
		||||
 | 
			
		||||
	} else {
 | 
			
		||||
	    /* Only have total values. */
 | 
			
		||||
 | 
			
		||||
	    buf->packets_total += packets;
 | 
			
		||||
	    buf->bytes_total += bytes;
 | 
			
		||||
 | 
			
		||||
	    buf->flags |= _glibtop_sysdeps_netload_total;
 | 
			
		||||
	}
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fclose (f);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
linux_2_4_stats(glibtop *server,
 | 
			
		||||
		glibtop_netload *buf,
 | 
			
		||||
		const char *interface)
 | 
			
		||||
{
 | 
			
		||||
    char buffer [BUFSIZ], *p;
 | 
			
		||||
    int have_bytes, fields, skfd;
 | 
			
		||||
    int have_bytes, fields;
 | 
			
		||||
    FILE *f;
 | 
			
		||||
 | 
			
		||||
    memset (buf, 0, sizeof (glibtop_netload));
 | 
			
		||||
 | 
			
		||||
    skfd = socket (AF_INET, SOCK_DGRAM, 0);
 | 
			
		||||
    if (skfd) {
 | 
			
		||||
	struct ifreq ifr;
 | 
			
		||||
 | 
			
		||||
	g_strlcpy (ifr.ifr_name, interface, sizeof ifr.ifr_name);
 | 
			
		||||
	if (!ioctl (skfd, SIOCGIFFLAGS, &ifr)) {
 | 
			
		||||
	    const unsigned long long flags = ifr.ifr_flags;
 | 
			
		||||
 | 
			
		||||
	    buf->flags |= (1L << GLIBTOP_NETLOAD_IF_FLAGS);
 | 
			
		||||
 | 
			
		||||
	    if (flags & IFF_UP)
 | 
			
		||||
		buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_UP);
 | 
			
		||||
 | 
			
		||||
	    if (flags & IFF_BROADCAST)
 | 
			
		||||
		buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_BROADCAST);
 | 
			
		||||
 | 
			
		||||
	    if (flags & IFF_DEBUG)
 | 
			
		||||
		buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_DEBUG);
 | 
			
		||||
 | 
			
		||||
	    if (flags & IFF_LOOPBACK)
 | 
			
		||||
		buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_LOOPBACK);
 | 
			
		||||
 | 
			
		||||
	    if (flags & IFF_POINTOPOINT)
 | 
			
		||||
		buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_POINTOPOINT);
 | 
			
		||||
 | 
			
		||||
	    if (flags & IFF_RUNNING)
 | 
			
		||||
		buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_RUNNING);
 | 
			
		||||
 | 
			
		||||
	    if (flags & IFF_NOARP)
 | 
			
		||||
		buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_NOARP);
 | 
			
		||||
 | 
			
		||||
	    if (flags & IFF_PROMISC)
 | 
			
		||||
		buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_PROMISC);
 | 
			
		||||
 | 
			
		||||
	    if (flags & IFF_ALLMULTI)
 | 
			
		||||
		buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_ALLMULTI);
 | 
			
		||||
 | 
			
		||||
	    if (flags & IFF_MULTICAST)
 | 
			
		||||
		buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_MULTICAST);
 | 
			
		||||
	    }
 | 
			
		||||
 | 
			
		||||
	g_strlcpy (ifr.ifr_name, interface, sizeof ifr.ifr_name);
 | 
			
		||||
	if (!ioctl (skfd, SIOCGIFADDR, &ifr)) {
 | 
			
		||||
	    buf->address = ((struct sockaddr_in *) &ifr.ifr_addr)->sin_addr.s_addr;
 | 
			
		||||
	    buf->flags |= (1L << GLIBTOP_NETLOAD_ADDRESS);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	g_strlcpy (ifr.ifr_name, interface, sizeof ifr.ifr_name);
 | 
			
		||||
	if (!ioctl (skfd, SIOCGIFNETMASK, &ifr)) {
 | 
			
		||||
	    buf->subnet = ((struct sockaddr_in *) &ifr.ifr_addr)->sin_addr.s_addr;
 | 
			
		||||
	    buf->flags |= (1L << GLIBTOP_NETLOAD_SUBNET);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	g_strlcpy (ifr.ifr_name, interface, sizeof ifr.ifr_name);
 | 
			
		||||
	if (!ioctl (skfd, SIOCGIFMTU, &ifr)) {
 | 
			
		||||
	    buf->mtu = ifr.ifr_mtu;
 | 
			
		||||
	    buf->flags |= (1L << GLIBTOP_NETLOAD_MTU);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	g_strlcpy (ifr.ifr_name, interface, sizeof ifr.ifr_name);
 | 
			
		||||
	if (!ioctl (skfd, SIOCGIFHWADDR, &ifr)) {
 | 
			
		||||
	    memcpy(buf->hwaddress, &ifr.ifr_hwaddr.sa_data, 8);
 | 
			
		||||
	    buf->flags |= (1L << GLIBTOP_NETLOAD_HWADDRESS);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	close (skfd);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* Linux 2.1.114 - don't know where exactly this was added, but
 | 
			
		||||
	 * recent kernels have byte count in /proc/net/dev so we don't
 | 
			
		||||
	 * need IP accounting.
 | 
			
		||||
	 */
 | 
			
		||||
 | 
			
		||||
    if (server->os_version_code < LINUX_VERSION_CODE(2, 1, 14)) {
 | 
			
		||||
 | 
			
		||||
	/* If IP accounting is enabled in the kernel and it is
 | 
			
		||||
	 * enabled for the requested interface, we use it to
 | 
			
		||||
	 * get the data. In this case, we don't use /proc/net/dev
 | 
			
		||||
	 * to get errors and collisions.
 | 
			
		||||
	 */
 | 
			
		||||
 | 
			
		||||
	f = fopen ("/proc/net/ip_acct", "r");
 | 
			
		||||
	if (f) {
 | 
			
		||||
	    int success = 0;
 | 
			
		||||
 | 
			
		||||
	    /* Skip over the header line. */
 | 
			
		||||
	    fgets (buffer, BUFSIZ-1, f);
 | 
			
		||||
 | 
			
		||||
	    while (fgets (buffer, BUFSIZ-1, f)) {
 | 
			
		||||
		unsigned long long flags, packets, bytes;
 | 
			
		||||
		char *p, *dev;
 | 
			
		||||
 | 
			
		||||
		/* Skip over the network thing. */
 | 
			
		||||
		dev = skip_token (buffer) + 1;
 | 
			
		||||
		p = skip_token (dev);
 | 
			
		||||
		*p++ = 0;
 | 
			
		||||
 | 
			
		||||
		if (strcmp (dev, interface))
 | 
			
		||||
		    continue;
 | 
			
		||||
 | 
			
		||||
		success = 1;
 | 
			
		||||
 | 
			
		||||
		p = skip_token (p);
 | 
			
		||||
 | 
			
		||||
		flags   = strtoull (p, &p, 16);
 | 
			
		||||
 | 
			
		||||
		p = skip_multiple_token (p, 2);
 | 
			
		||||
 | 
			
		||||
		packets = strtoull (p, &p, 0);
 | 
			
		||||
		bytes   = strtoull (p, &p, 0);
 | 
			
		||||
 | 
			
		||||
		if (flags & _GLIBTOP_IP_FW_ACCTIN) {
 | 
			
		||||
		    /* Incoming packets only. */
 | 
			
		||||
 | 
			
		||||
		    buf->packets_total += packets;
 | 
			
		||||
		    buf->packets_in += packets;
 | 
			
		||||
 | 
			
		||||
		    buf->bytes_total += bytes;
 | 
			
		||||
		    buf->bytes_in += bytes;
 | 
			
		||||
 | 
			
		||||
		    buf->flags |= _glibtop_sysdeps_netload_in;
 | 
			
		||||
 | 
			
		||||
		} else if (flags & _GLIBTOP_IP_FW_ACCTOUT) {
 | 
			
		||||
		    /* Outgoing packets only. */
 | 
			
		||||
 | 
			
		||||
		    buf->packets_total += packets;
 | 
			
		||||
		    buf->packets_out += packets;
 | 
			
		||||
 | 
			
		||||
		    buf->bytes_total += bytes;
 | 
			
		||||
		    buf->bytes_out += bytes;
 | 
			
		||||
 | 
			
		||||
		    buf->flags |= _glibtop_sysdeps_netload_out;
 | 
			
		||||
 | 
			
		||||
		} else {
 | 
			
		||||
		    /* Only have total values. */
 | 
			
		||||
 | 
			
		||||
		    buf->packets_total += packets;
 | 
			
		||||
		    buf->bytes_total += bytes;
 | 
			
		||||
 | 
			
		||||
		    buf->flags |= _glibtop_sysdeps_netload_total;
 | 
			
		||||
		}
 | 
			
		||||
	    }
 | 
			
		||||
 | 
			
		||||
	    fclose (f);
 | 
			
		||||
 | 
			
		||||
	    if (success) return;
 | 
			
		||||
	}
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* Ok, either IP accounting is not enabled in the kernel or
 | 
			
		||||
	 * it was not enabled for the requested interface. */
 | 
			
		||||
     * it was not enabled for the requested interface. */
 | 
			
		||||
 | 
			
		||||
    f = fopen ("/proc/net/dev", "r");
 | 
			
		||||
    if (!f) return;
 | 
			
		||||
    if (!f) {
 | 
			
		||||
	glibtop_warn_io_r(server,
 | 
			
		||||
			  "Failed to open \"/proc/net/dev\"");
 | 
			
		||||
	return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
	/* Skip over the header line. */
 | 
			
		||||
    /* Skip over the header line. */
 | 
			
		||||
    fgets (buffer, BUFSIZ-1, f);
 | 
			
		||||
    fgets (buffer, BUFSIZ-1, f);
 | 
			
		||||
 | 
			
		||||
	/* Starting with 2.1.xx (don't know exactly which version)
 | 
			
		||||
	 * /proc/net/dev contains both byte and package counters. */
 | 
			
		||||
    /* Starting with 2.1.xx (don't know exactly which version)
 | 
			
		||||
     * /proc/net/dev contains both byte and package counters. */
 | 
			
		||||
 | 
			
		||||
    p = strchr (buffer, '|');
 | 
			
		||||
    if (!p) {
 | 
			
		||||
@@ -370,7 +370,7 @@ glibtop_get_netload_s (glibtop *server, glibtop_netload *buf,
 | 
			
		||||
    have_bytes = strncmp (++p, "bytes", 5) == 0;
 | 
			
		||||
 | 
			
		||||
    /* Count remaining 'Receive' fields so we know where
 | 
			
		||||
	 * the first 'Transmit' field starts. */
 | 
			
		||||
     * the first 'Transmit' field starts. */
 | 
			
		||||
 | 
			
		||||
    fields = 0;
 | 
			
		||||
    while (*p != '|') {
 | 
			
		||||
@@ -445,6 +445,107 @@ glibtop_get_netload_s (glibtop *server, glibtop_netload *buf,
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fclose (f);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/* Provides network statistics. */
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
glibtop_get_netload_s (glibtop *server, glibtop_netload *buf,
 | 
			
		||||
		       const char *interface)
 | 
			
		||||
{
 | 
			
		||||
    int skfd;
 | 
			
		||||
    memset (buf, 0, sizeof (glibtop_netload));
 | 
			
		||||
 | 
			
		||||
    skfd = socket (AF_INET, SOCK_DGRAM, 0);
 | 
			
		||||
    if (skfd) {
 | 
			
		||||
	struct ifreq ifr;
 | 
			
		||||
 | 
			
		||||
	g_strlcpy (ifr.ifr_name, interface, sizeof ifr.ifr_name);
 | 
			
		||||
	if (!ioctl (skfd, SIOCGIFFLAGS, &ifr)) {
 | 
			
		||||
	    const unsigned long long flags = ifr.ifr_flags;
 | 
			
		||||
 | 
			
		||||
	    buf->flags |= (1L << GLIBTOP_NETLOAD_IF_FLAGS);
 | 
			
		||||
 | 
			
		||||
	    if (flags & IFF_UP)
 | 
			
		||||
		buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_UP);
 | 
			
		||||
 | 
			
		||||
	    if (flags & IFF_BROADCAST)
 | 
			
		||||
		buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_BROADCAST);
 | 
			
		||||
 | 
			
		||||
	    if (flags & IFF_DEBUG)
 | 
			
		||||
		buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_DEBUG);
 | 
			
		||||
 | 
			
		||||
	    if (flags & IFF_LOOPBACK)
 | 
			
		||||
		buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_LOOPBACK);
 | 
			
		||||
 | 
			
		||||
	    if (flags & IFF_POINTOPOINT)
 | 
			
		||||
		buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_POINTOPOINT);
 | 
			
		||||
 | 
			
		||||
	    if (flags & IFF_RUNNING)
 | 
			
		||||
		buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_RUNNING);
 | 
			
		||||
 | 
			
		||||
	    if (flags & IFF_NOARP)
 | 
			
		||||
		buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_NOARP);
 | 
			
		||||
 | 
			
		||||
	    if (flags & IFF_PROMISC)
 | 
			
		||||
		buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_PROMISC);
 | 
			
		||||
 | 
			
		||||
	    if (flags & IFF_ALLMULTI)
 | 
			
		||||
		buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_ALLMULTI);
 | 
			
		||||
 | 
			
		||||
	    if (flags & IFF_MULTICAST)
 | 
			
		||||
		buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_MULTICAST);
 | 
			
		||||
	    }
 | 
			
		||||
 | 
			
		||||
	g_strlcpy (ifr.ifr_name, interface, sizeof ifr.ifr_name);
 | 
			
		||||
	if (!ioctl (skfd, SIOCGIFADDR, &ifr)) {
 | 
			
		||||
	    buf->address = ((struct sockaddr_in *) &ifr.ifr_addr)->sin_addr.s_addr;
 | 
			
		||||
	    buf->flags |= (1L << GLIBTOP_NETLOAD_ADDRESS);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	g_strlcpy (ifr.ifr_name, interface, sizeof ifr.ifr_name);
 | 
			
		||||
	if (!ioctl (skfd, SIOCGIFNETMASK, &ifr)) {
 | 
			
		||||
	    buf->subnet = ((struct sockaddr_in *) &ifr.ifr_addr)->sin_addr.s_addr;
 | 
			
		||||
	    buf->flags |= (1L << GLIBTOP_NETLOAD_SUBNET);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	g_strlcpy (ifr.ifr_name, interface, sizeof ifr.ifr_name);
 | 
			
		||||
	if (!ioctl (skfd, SIOCGIFMTU, &ifr)) {
 | 
			
		||||
	    buf->mtu = ifr.ifr_mtu;
 | 
			
		||||
	    buf->flags |= (1L << GLIBTOP_NETLOAD_MTU);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	g_strlcpy (ifr.ifr_name, interface, sizeof ifr.ifr_name);
 | 
			
		||||
	if (!ioctl (skfd, SIOCGIFHWADDR, &ifr)) {
 | 
			
		||||
	    memcpy(buf->hwaddress, &ifr.ifr_hwaddr.sa_data, 8);
 | 
			
		||||
	    buf->flags |= (1L << GLIBTOP_NETLOAD_HWADDRESS);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	close (skfd);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    /*
 | 
			
		||||
     * Statistics
 | 
			
		||||
     */
 | 
			
		||||
 | 
			
		||||
    /* Linux 2.1.114 - don't know where exactly this was added, but
 | 
			
		||||
	 * recent kernels have byte count in /proc/net/dev so we don't
 | 
			
		||||
	 * need IP accounting.
 | 
			
		||||
	 */
 | 
			
		||||
 | 
			
		||||
    if (server->os_version_code < LINUX_VERSION_CODE(2, 1, 14)) {
 | 
			
		||||
	linux_2_0_stats(server, buf, interface);
 | 
			
		||||
    }
 | 
			
		||||
    else if (server->os_version_code > LINUX_VERSION_CODE(2, 6, 0)) {
 | 
			
		||||
	linux_2_6_stats(server, buf, interface);
 | 
			
		||||
    }
 | 
			
		||||
    else if (server->os_version_code > LINUX_VERSION_CODE(2, 4, 0)) {
 | 
			
		||||
	linux_2_4_stats(server, buf, interface);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
#ifdef HAVE_IFADDRS_H
 | 
			
		||||
    get_ipv6(server, buf, interface);
 | 
			
		||||
 
 | 
			
		||||
@@ -87,11 +87,7 @@ glibtop_get_proc_time_s (glibtop *server, glibtop_proc_time *buf, pid_t pid)
 | 
			
		||||
 | 
			
		||||
	/* seconds since epoch */
 | 
			
		||||
	{
 | 
			
		||||
	  /* Linux provides start_time as clock_t representing
 | 
			
		||||
	     the start of <pid> after boot_time.
 | 
			
		||||
	     Let's use glibtop_get_uptime to get boot_time.
 | 
			
		||||
	     But i'm not sure if this is safe
 | 
			
		||||
 | 
			
		||||
	  /*
 | 
			
		||||
	     See libgtop documentation.
 | 
			
		||||
 | 
			
		||||
	     #ifdef __KERNEL__
 | 
			
		||||
@@ -109,10 +105,7 @@ glibtop_get_proc_time_s (glibtop *server, glibtop_proc_time *buf, pid_t pid)
 | 
			
		||||
	     system clock is not synchronised with you hardware clock.
 | 
			
		||||
	     'man hwclock'
 | 
			
		||||
	  */
 | 
			
		||||
	  glibtop_uptime up;
 | 
			
		||||
	  glibtop_get_uptime_s(server, &up);
 | 
			
		||||
 | 
			
		||||
	  buf->start_time = up.boot_time + strtoull (p, &p, 0) / 100;
 | 
			
		||||
	  buf->start_time = get_boot_time(server) + strtoull (p, &p, 0) / 100;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	buf->frequency = 100;
 | 
			
		||||
 
 | 
			
		||||
@@ -57,7 +57,7 @@ glibtop_get_uptime_s (glibtop *server, glibtop_uptime *buf)
 | 
			
		||||
 | 
			
		||||
	buf->uptime   = g_ascii_strtod (buffer, &p);
 | 
			
		||||
	buf->idletime = g_ascii_strtod (p, &p);
 | 
			
		||||
	buf->boot_time = (guint64) time(NULL) - (guint64) buf->uptime;
 | 
			
		||||
	buf->boot_time = get_boot_time(server);
 | 
			
		||||
 | 
			
		||||
	buf->flags = _glibtop_sysdeps_uptime;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user