diff options
author | Eric S. Raymond <esr@thyrsus.com> | 1999-01-31 18:23:17 +0000 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 1999-01-31 18:23:17 +0000 |
commit | 1715ab1008073e39d9355e58fea0a6fa62f9ebd7 (patch) | |
tree | 7f20db02e04b95535c5a01ec6d4e94edceb73779 /interface.c | |
parent | d460f445287037708d6962fff4082704164850e9 (diff) | |
download | fetchmail-1715ab1008073e39d9355e58fea0a6fa62f9ebd7.tar.gz fetchmail-1715ab1008073e39d9355e58fea0a6fa62f9ebd7.tar.bz2 fetchmail-1715ab1008073e39d9355e58fea0a6fa62f9ebd7.zip |
Move /proc/net/dev derivation to runtime.
svn path=/trunk/; revision=2367
Diffstat (limited to 'interface.c')
-rw-r--r-- | interface.c | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/interface.c b/interface.c index 05d34404..eeff225c 100644 --- a/interface.c +++ b/interface.c @@ -41,13 +41,30 @@ struct interface_pair_s { struct in_addr interface_mask; } *interface_pair; -#ifdef HAVE_NEWPROCNETDEV -/* Linux 2.2 /proc/net/dev format -- transmit packet count in 10th field */ -#define PROCNETDEV "%d %d %*d %*d %*d %d %*d %*d %*d %*d %d %*d %d" -#else -/* pre-linux-2.2 format -- transmit packet count in 8th field */ -#define PROCNETDEV "%d %d %*d %*d %*d %d %*d %d %*d %*d %*d %*d %d" -#endif +static char *netdevfmt; + +void interface_init(void) +/* figure out which /roc/dev/net format to use */ +{ + FILE *fp = fopen("/proc/sys/kernel/osrelease", "r"); + + /* 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"; + + if (!fp) + return; + else + { + int major, minor; + + if (fscanf(fp, "%d.%d.%*d", &major, &minor) != 2) + return; + + if (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"; + } +} static int _get_ifinfo_(int socket_fd, FILE *stats_file, const char *ifname, ifinfo_t *ifinfo) @@ -68,7 +85,7 @@ static int _get_ifinfo_(int socket_fd, FILE *stats_file, const char *ifname, if (!strncmp(cp, ifname, namelen) && cp[namelen] == ':') { cp += namelen + 1; - if (sscanf(cp, PROCNETDEV, + if (sscanf(cp, netdevfmt, counts, counts+1, counts+2, counts+3,&found)>4) { /* found = dummy */ /* newer kernel with byte counts */ |