Advertisement
Guest User

Untitled

a guest
May 26th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.99 KB | None | 0 0
  1.   1 #include <pcap.h>
  2.   2 #include "hacking.h"
  3.   3
  4.   4 void pcap_fatal(const char *failed_in, const char *errbuf) {
  5.   5     printf("Fatal Error in %s: %s\n", failed_in, errbuf);
  6.   6     exit(1);
  7.   7 }
  8.   8
  9.   9 int main() {
  10.  10     struct pcap_pkthdr header;
  11.  11     const u_char *packet;
  12.  12     char errbuf[PCAP_ERRBUF_SIZE];
  13.  13     char *device;
  14.  14     pcap_t *pcap_handle;
  15.  15     int i;
  16.  16
  17.  17     device = pcap_lookupdev(errbuf);
  18.  18     if(device == NULL)
  19.  19             pcap_fatal("pcap_lookupdev", errbuf);
  20.  20
  21.  21     printf("Sniffing on device %s \n", device);
  22.  22
  23.  23     pcap_handle = pcap_open_live(device, 4096, i, 0, errbuf);
  24.  24     if(pcap_handle = NULL)
  25.  25             pcap_fatal("pcap_open_live", errbuf);
  26.  26
  27.  27     for(i=0; i < 3; i++) {
  28.  28             packet = pcap_next(pcap_handle, &header);
  29.  29             printf("Got a %d byte packet\n", header.len);
  30.  30             dump(packet, header.len);
  31.  31     }
  32.  32     pcap_close(pcap_handle);
  33.  33 }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement