1*6f9cba8fSJoseph Mingrone #include <config.h> 2*6f9cba8fSJoseph Mingrone 3*6f9cba8fSJoseph Mingrone #include <stdlib.h> 4*6f9cba8fSJoseph Mingrone #include <string.h> 5*6f9cba8fSJoseph Mingrone #include <sys/types.h> 6*6f9cba8fSJoseph Mingrone #ifdef _WIN32 7*6f9cba8fSJoseph Mingrone #include <winsock2.h> 8*6f9cba8fSJoseph Mingrone #include <ws2tcpip.h> 9*6f9cba8fSJoseph Mingrone #include <windows.h> 10*6f9cba8fSJoseph Mingrone #else 11*6f9cba8fSJoseph Mingrone #include <unistd.h> 12*6f9cba8fSJoseph Mingrone #include <sys/resource.h> 13*6f9cba8fSJoseph Mingrone #endif 14*6f9cba8fSJoseph Mingrone 15*6f9cba8fSJoseph Mingrone #include <pcap.h> 16*6f9cba8fSJoseph Mingrone 17*6f9cba8fSJoseph Mingrone #include "varattrs.h" 18*6f9cba8fSJoseph Mingrone #include "pcap/funcattrs.h" 19*6f9cba8fSJoseph Mingrone #include "portability.h" 20*6f9cba8fSJoseph Mingrone 21*6f9cba8fSJoseph Mingrone int main(int argc _U_, char **argv _U_) 22*6f9cba8fSJoseph Mingrone { 23*6f9cba8fSJoseph Mingrone pcap_if_t *alldevs; 24*6f9cba8fSJoseph Mingrone int exit_status = 0; 25*6f9cba8fSJoseph Mingrone char errbuf[PCAP_ERRBUF_SIZE+1]; 26*6f9cba8fSJoseph Mingrone #ifdef _WIN32 27*6f9cba8fSJoseph Mingrone FILETIME start_ktime, start_utime, end_ktime, end_utime; 28*6f9cba8fSJoseph Mingrone FILETIME dummy1, dummy2; 29*6f9cba8fSJoseph Mingrone ULARGE_INTEGER start_kticks, end_kticks, start_uticks, end_uticks; 30*6f9cba8fSJoseph Mingrone ULONGLONG ktime, utime, tottime; 31*6f9cba8fSJoseph Mingrone #else 32*6f9cba8fSJoseph Mingrone struct rusage start_rusage, end_rusage; 33*6f9cba8fSJoseph Mingrone struct timeval ktime, utime, tottime; 34*6f9cba8fSJoseph Mingrone #endif 35*6f9cba8fSJoseph Mingrone 36*6f9cba8fSJoseph Mingrone #ifdef _WIN32 37*6f9cba8fSJoseph Mingrone if (!GetProcessTimes(GetCurrentProcess(), &dummy1, &dummy2, 38*6f9cba8fSJoseph Mingrone &start_ktime, &start_utime)) 39*6f9cba8fSJoseph Mingrone { 40*6f9cba8fSJoseph Mingrone fprintf(stderr, "GetProcessTimes() fails at start\n"); 41*6f9cba8fSJoseph Mingrone exit(1); 42*6f9cba8fSJoseph Mingrone } 43*6f9cba8fSJoseph Mingrone start_kticks.LowPart = start_ktime.dwLowDateTime; 44*6f9cba8fSJoseph Mingrone start_kticks.HighPart = start_ktime.dwHighDateTime; 45*6f9cba8fSJoseph Mingrone start_uticks.LowPart = start_utime.dwLowDateTime; 46*6f9cba8fSJoseph Mingrone start_uticks.HighPart = start_utime.dwHighDateTime; 47*6f9cba8fSJoseph Mingrone #else 48*6f9cba8fSJoseph Mingrone if (getrusage(RUSAGE_SELF, &start_rusage) == -1) { 49*6f9cba8fSJoseph Mingrone fprintf(stderr, "getrusage() fails at start\n"); 50*6f9cba8fSJoseph Mingrone exit(1); 51*6f9cba8fSJoseph Mingrone } 52*6f9cba8fSJoseph Mingrone #endif 53*6f9cba8fSJoseph Mingrone for (int i = 0; i < 500; i++) 54*6f9cba8fSJoseph Mingrone { 55*6f9cba8fSJoseph Mingrone if (pcap_findalldevs(&alldevs, errbuf) == -1) 56*6f9cba8fSJoseph Mingrone { 57*6f9cba8fSJoseph Mingrone fprintf(stderr,"Error in pcap_findalldevs: %s\n",errbuf); 58*6f9cba8fSJoseph Mingrone exit(1); 59*6f9cba8fSJoseph Mingrone } 60*6f9cba8fSJoseph Mingrone pcap_freealldevs(alldevs); 61*6f9cba8fSJoseph Mingrone } 62*6f9cba8fSJoseph Mingrone 63*6f9cba8fSJoseph Mingrone #ifdef _WIN32 64*6f9cba8fSJoseph Mingrone if (!GetProcessTimes(GetCurrentProcess(), &dummy1, &dummy2, 65*6f9cba8fSJoseph Mingrone &end_ktime, &end_utime)) 66*6f9cba8fSJoseph Mingrone { 67*6f9cba8fSJoseph Mingrone fprintf(stderr, "GetProcessTimes() fails at end\n"); 68*6f9cba8fSJoseph Mingrone exit(1); 69*6f9cba8fSJoseph Mingrone } 70*6f9cba8fSJoseph Mingrone end_kticks.LowPart = end_ktime.dwLowDateTime; 71*6f9cba8fSJoseph Mingrone end_kticks.HighPart = end_ktime.dwHighDateTime; 72*6f9cba8fSJoseph Mingrone end_uticks.LowPart = end_utime.dwLowDateTime; 73*6f9cba8fSJoseph Mingrone end_uticks.HighPart = end_utime.dwHighDateTime; 74*6f9cba8fSJoseph Mingrone ktime = end_kticks.QuadPart - start_kticks.QuadPart; 75*6f9cba8fSJoseph Mingrone utime = end_uticks.QuadPart - start_uticks.QuadPart; 76*6f9cba8fSJoseph Mingrone tottime = ktime + utime; 77*6f9cba8fSJoseph Mingrone printf("Total CPU secs: kernel %g, user %g, total %g\n", 78*6f9cba8fSJoseph Mingrone ((double)ktime) / 10000000.0, 79*6f9cba8fSJoseph Mingrone ((double)utime) / 10000000.0, 80*6f9cba8fSJoseph Mingrone ((double)tottime) / 10000000.0); 81*6f9cba8fSJoseph Mingrone #else 82*6f9cba8fSJoseph Mingrone if (getrusage(RUSAGE_SELF, &end_rusage) == -1) { 83*6f9cba8fSJoseph Mingrone fprintf(stderr, "getrusage() fails at end\n"); 84*6f9cba8fSJoseph Mingrone exit(1); 85*6f9cba8fSJoseph Mingrone } 86*6f9cba8fSJoseph Mingrone timersub(&end_rusage.ru_stime, &start_rusage.ru_stime, &ktime); 87*6f9cba8fSJoseph Mingrone timersub(&end_rusage.ru_utime, &start_rusage.ru_utime, &utime); 88*6f9cba8fSJoseph Mingrone timeradd(&ktime, &utime, &tottime); 89*6f9cba8fSJoseph Mingrone printf("Total CPU secs: kernel %g, user %g, total %g\n", 90*6f9cba8fSJoseph Mingrone (double)ktime.tv_sec + ((double)ktime.tv_usec / 1000000.0), 91*6f9cba8fSJoseph Mingrone (double)utime.tv_sec + ((double)utime.tv_usec / 1000000.0), 92*6f9cba8fSJoseph Mingrone (double)tottime.tv_sec + ((double)tottime.tv_usec / 1000000.0)); 93*6f9cba8fSJoseph Mingrone #endif 94*6f9cba8fSJoseph Mingrone exit(exit_status); 95*6f9cba8fSJoseph Mingrone } 96