Created
May 29, 2012 01:55
-
-
Save pfsmorigo/2822115 to your computer and use it in GitHub Desktop.
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
int main(int argc,char **argv) | |
{ | |
pcap_t *handle; | |
char errbuf[PCAP_ERRBUF_SIZE]; | |
struct bpf_program fp; | |
const char *pcap_file = "trafego1.pcap"; | |
bpf_u_int32 net; | |
char *string_mac = "00:0f:20:2f:63:d9"; | |
char *string_ip = "189.126.11.82"; | |
char filter_exp[100]; | |
sprintf(filter_exp, "ether host %s and host %s", string_mac, string_ip); | |
handle = pcap_open_offline(pcap_file, errbuf); | |
if (handle == NULL) { | |
fprintf(stderr, "Couldn't open pcap file %s\n", errbuf); | |
return 1; | |
} | |
if (pcap_compile(handle, &fp, filter_exp, 0, net) == -1) { | |
fprintf(stderr, "Couldn't parse filter %s: %s\n", filter_exp, pcap_geterr(handle)); | |
return(2); | |
} | |
if (pcap_setfilter(handle, &fp) == -1) { | |
fprintf(stderr, "Couldn't install filter %s: %s\n", filter_exp, pcap_geterr(handle)); | |
return(2); | |
} | |
// read and dispatch packets until EOF is reached | |
pcap_loop(handle , -1 , my_callback, NULL); | |
printf("TCP packets: %u\n", counter_tcp); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment