$NetBSD: patch-ac,v 1.1.1.1 1998/12/03 15:08:53 frueauf Exp $ --- network.c.orig Mon Oct 26 05:35:01 1998 +++ network.c Mon Nov 30 18:25:26 1998 @@ -26,13 +26,14 @@ #include #include #include +#include #include #ifdef SUNOS41x extern int socket(), ioctl(), sscanf(), printf(), pclose(); #elif defined(SUNOS5x) #include -#else +#elif !(defined(BSD) && BSD >= 199306) /* Returns kernel revision number (10*major+minor). Only used on Linux to figure out what kind of parsing format to use for /proc/net/dev output */ @@ -92,6 +93,10 @@ #define AddrOpen popen("/usr/bin/netstat -nr", "r") #define AddrScanf sscanf(routeLine, "%*s %*s %*s %*s %*s %s", IF) #define AddrClose while (fgets(routeLine,128,infofp) != NULL); pclose(infofp) +#elif (defined(BSD) && BSD >= 199306) + #define AddrOpen popen("/usr/bin/netstat -nr", "r") + #define AddrScanf sscanf(routeLine, "%*s %*s %*s %*s %*s %*s %s", IF) + #define AddrClose while (fgets(routeLine,128,infofp) != NULL); pclose(infofp) #else #define AddrOpen fopen("/proc/net/route", "r") #define AddrScanf sscanf(routeLine,"%s", IF) @@ -137,6 +142,12 @@ #define PktsScanf sscanf(line, "%s %*s %*s %*s %u %*s %u", \ interface, &recv, &trans) #define PktsClose while (fgets(line,128,infofp) != NULL); pclose(infofp) +#elif (defined(BSD) && BSD >= 199306) + #define PktsOpen popen((sprintf(line,"/usr/bin/netstat -n -I %s",IFName)) ? \ + line:line, "r") + #define PktsScanf sscanf(line, "%s %*s %s %*s %u %*s %u", \ + interface, network, &recv, &trans) + #define PktsClose while (fgets(line,128,infofp) != NULL); pclose(infofp) #else #define PktsOpen fopen("/proc/net/dev", "r") #define PktsScanf sscanf(line, ((kernelRevNo()>20) ? \ @@ -151,16 +162,26 @@ int IFLen = strlen(IFName); FILE *infofp; char line[129], interface[16]; +#if (defined(BSD) && BSD >= 199306) + char network[16]; +#endif unsigned recv = 0, trans = 0; infofp = PktsOpen; /* open IF stats info stream */ while (fgets(line, 128, infofp) != NULL) { PktsScanf; /* read line by line */ if (!strncmp(interface,IFName,IFLen)) { /* scanning for interface */ +#if (defined(BSD) && BSD >= 199306) + /* Discard non-conforming multicast line. */ + if (strncmp(network,"",strlen(network))) { +#endif PktsClose; /* found, close info stream */ if (pTX) *pTX = trans; /* if return storage avail */ if (pRX) *pRX = recv; /* save TXed/RXed separately */ return (recv + trans); /* return total I/O packets */ +#if (defined(BSD) && BSD >= 199306) + } +#endif } } PktsClose; /* close info stream */