1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| #include <stdio.h>
#include <stdlib.h>
#include <pcap.h>
void pcap_fatal(const char* failed_in, const char* errbuf) {
printf("Fatal Error in %s: %s\n", failed_in, errbuf);
exit(1);
}
int main() {
struct pcap_pkthdr header;
const u_char *packet;
char errbuf[PCAP_ERRBUF_SIZE];
char *device;
pcap_t *pcap_handle;
int i;
device = pcap_lookupdev(errbuf);
if(device == NULL)
pcap_fatal("pcap_lookupdev", errbuf);
printf("Sniffing on device %s\n", device);
pcap_handle = pcap_open_live(device, 4096, 1, 0, errbuf);
if(pcap_handle == NULL)
pcap_fatal("pcap_open_live", errbuf);
for(i=0; i<3; i++) {
packet = pcap_next(pcap_handle, &header);
printf("Intercéption de %d bytes\n", header.len);
dump(packet, header.len);
}
pcap_close(pcap_handle);
return 0;
} |
Partager