aboutsummaryrefslogtreecommitdiffstats
path: root/interface.c
diff options
context:
space:
mode:
authorGraham Wilson <graham@mknod.org>2004-11-14 18:58:40 +0000
committerGraham Wilson <graham@mknod.org>2004-11-14 18:58:40 +0000
commitdf821496b2ef39a477c392cf1aa5efd5cf2520df (patch)
tree77743ad9c79625ab895150903e15522085a6fc8f /interface.c
parentb677d2e088a32227cda28496bd321c470e422246 (diff)
downloadfetchmail-df821496b2ef39a477c392cf1aa5efd5cf2520df.tar.gz
fetchmail-df821496b2ef39a477c392cf1aa5efd5cf2520df.tar.bz2
fetchmail-df821496b2ef39a477c392cf1aa5efd5cf2520df.zip
Default to Linux 2.2 /proc/net/dev format, and use uname(2) to determine the kernel version instead of calling uname(1). Thanks to Paul Slootman.
svn path=/trunk/; revision=4007
Diffstat (limited to 'interface.c')
-rw-r--r--interface.c25
1 files changed, 14 insertions, 11 deletions
diff --git a/interface.c b/interface.c
index 4c9dde32..c264f22b 100644
--- a/interface.c
+++ b/interface.c
@@ -14,6 +14,10 @@
#include <sys/types.h>
#include <sys/param.h>
+#if defined(linux)
+#include <sys/utsname.h>
+#endif
+
#if (defined(linux) && !defined(INET6_ENABLE)) || defined(__FreeBSD__)
#include "config.h"
@@ -73,24 +77,23 @@ static char *netdevfmt;
#if defined(linux)
void interface_init(void)
-/* figure out which /proc/dev/net format to use */
+/* figure out which /proc/net/dev format to use */
{
- FILE *fp = popen("uname -r", "r"); /* still wins if /proc is out */
+ struct utsname utsname;
- /* pre-linux-2.2 format -- transmit packet count in 8th field */
- netdevfmt = "%d %d %*d %*d %*d %d %*d %d %*d %*d %*d %*d %d";
+ /* Linux 2.2 -- transmit packet count in 10th field */
+ netdevfmt = "%d %d %*d %*d %*d %d %*d %*d %*d %d %*d %*d %d";
- if (!fp)
- return;
+ if (uname(&utsname) < 0)
+ return;
else
{
int major, minor;
- if (fscanf(fp, "%d.%d.%*d", &major, &minor) >= 2
- && major >= 2 && minor >= 2)
- /* Linux 2.2 -- transmit packet count in 10th field */
- netdevfmt = "%d %d %*d %*d %*d %d %*d %*d %*d %d %*d %*d %d";
- pclose(fp);
+ if (sscanf(utsname.release, "%d.%d.%*d", &major, &minor) >= 2
+ && !(major >= 2 && minor >= 2))
+ /* pre-linux-2.2 format -- transmit packet count in 8th field */
+ netdevfmt = "%d %d %*d %*d %*d %d %*d %d %*d %*d %*d %*d %d";
}
}