aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>1997-08-04 14:10:57 +0000
committerEric S. Raymond <esr@thyrsus.com>1997-08-04 14:10:57 +0000
commit2555a9c485cdff12816ae571754dc213c075712f (patch)
tree9c3cb710fa28a2162273c7d7fc6f28377841078e
parent0fac6a743ae2f6fc7664743918f7b5777644b106 (diff)
downloadfetchmail-2555a9c485cdff12816ae571754dc213c075712f.tar.gz
fetchmail-2555a9c485cdff12816ae571754dc213c075712f.tar.bz2
fetchmail-2555a9c485cdff12816ae571754dc213c075712f.zip
Ian T. Zimmerman's `interface' option.
svn path=/trunk/; revision=1228
-rw-r--r--interface.c33
1 files changed, 19 insertions, 14 deletions
diff --git a/interface.c b/interface.c
index b379786b..58f6e0a4 100644
--- a/interface.c
+++ b/interface.c
@@ -45,10 +45,24 @@ static int _get_ifinfo_(int socket_fd, FILE *stats_file, const char *ifname,
int namelen = strlen(ifname);
struct ifreq request;
char *cp, buffer[256];
+ int found = 0;
/* initialize result */
memset((char *) ifinfo, 0, sizeof(ifinfo_t));
+ /* get the packet I/O counts */
+ while (fgets(buffer, sizeof(buffer) - 1, stats_file)) {
+ for (cp = buffer; *cp && *cp == ' '; ++cp);
+ if (!strncmp(cp, ifname, namelen) &&
+ cp[namelen] == ':') {
+ cp += namelen + 1;
+ sscanf(cp, "%d %*d %*d %*d %*d %d %*d %*d %*d %*d %*d",
+ &ifinfo->rx_packets, &ifinfo->tx_packets);
+ found = 1;
+ }
+ }
+ if (!found) return (FALSE);
+
/* see if the interface is up */
strcpy(request.ifr_name, ifname);
if (ioctl(socket_fd, SIOCGIFFLAGS, &request) < 0)
@@ -70,21 +84,12 @@ static int _get_ifinfo_(int socket_fd, FILE *stats_file, const char *ifname,
/* get the netmask */
strcpy(request.ifr_name, ifname);
- if (ioctl(socket_fd, SIOCGIFNETMASK, &request) >= 0)
- ifinfo->netmask = ((struct sockaddr_in *)
- (&request.ifr_netmask))->sin_addr;
+ if (ioctl(socket_fd, SIOCGIFNETMASK, &request) >= 0) {
+ ifinfo->netmask = ((struct sockaddr_in *)
+ (&request.ifr_netmask))->sin_addr;
+ return (TRUE);
+ }
- /* get the packet I/O counts */
- while (fgets(buffer, sizeof(buffer) - 1, stats_file)) {
- for (cp = buffer; *cp && *cp == ' '; ++cp);
- if (!strncmp(cp, ifname, namelen) &&
- cp[namelen] == ':') {
- cp += namelen + 1;
- sscanf(cp, "%d %*d %*d %*d %*d %d %*d %*d %*d %*d %*d",
- &ifinfo->rx_packets, &ifinfo->tx_packets);
- return(TRUE);
- }
- }
return(FALSE);
}