Last active
May 13, 2018 17:51
-
-
Save crondaemon/ec4ebd6d3e577aac9dd5 to your computer and use it in GitHub Desktop.
pcap_stats() example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <pcap.h> | |
#include <unistd.h> | |
int main(int argc, char* argv[]) | |
{ | |
struct pcap_stat stat; | |
pcap_t* pcaph; | |
char errbuf[PCAP_ERRBUF_SIZE]; | |
if (argc != 2) { | |
printf("Usage: %s <if>\n", argv[0]); | |
return 1; | |
} | |
pcaph = pcap_open_live(argv[1], 65535, 0, 0, errbuf); | |
if (!pcaph) { | |
fprintf(stderr, "Error opening interface %s: %s\n", argv[1], errbuf); | |
return 2; | |
} | |
while(1) { | |
if (pcap_stats(pcaph, &stat) == -1) { | |
fprintf(stderr, "Error collecting stats\n"); | |
return 2; | |
} | |
printf("%u\n", stat.ps_recv); | |
sleep(1); | |
} | |
pcap_close(pcaph); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment