Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * [pcap_sniff.c]
- *
- * A TCP sniffing program, using raw sockets, @ the sub-Session (5) layer of the OSI model. It
- * utilizes libpcap to handle raw sockets more accurately.
- *
- * compile with:
- * gcc -o pcap_sniff pcap_sniff.c -l pcap
- */
- #include <pcap.h>
- #include "hacking.h"
- /**
- * The pcap_fatal() function:
- */
- void pcap_fatal(const char *failed_in, const char *errBuf)
- {
- printf("Fatal error in %s: %s\n", failed_in, errBuf);
- exit(1);
- }
- /**
- * The main() function:
- */
- int main(void)
- {
- struct pcap_pkthdr header;
- const u_char *packet;
- char errBuf[PCAP_ERRBUF_SIZE];
- char *device;
- pcap_t *pcap_handle; /* Similar to a file descriptor; referencing a packet-capturing object. */
- int i;
- /**
- * Find a suitable device to sniff on:
- */
- device = pcap_lookupdev(errBuf);
- if(device == NULL)
- pcap_fatal("pcap_lookupdev", errBuf);
- printf("Sniffing on device %s\n", device);
- /**
- * Open the packet-capturing device:
- */
- pcap_handle = pcap_open_live(device, 4096, 1, 0, errBuf);
- if(pcap_handle == NULL)
- pcap_fatal("pcap_open_live", errBuf);
- /**
- * Capture the (desired) packets (using a packet capture loop):
- */
- for(i = 0; i < 3; i++)
- {
- packet = pcap_next(pcap_handle, &header);
- printf("Got a %d byte packet\n", header.len);
- dump(packet, header.len);
- }
- /**
- * Close the packet capture interface:
- */
- pcap_close(pcap_handle);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement