Skip to content

Instantly share code, notes, and snippets.

@crondaemon
Last active May 13, 2018 17:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crondaemon/ec4ebd6d3e577aac9dd5 to your computer and use it in GitHub Desktop.
Save crondaemon/ec4ebd6d3e577aac9dd5 to your computer and use it in GitHub Desktop.
pcap_stats() example
#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