Advertisement
LocutusOfBorg

PCAP

Aug 16th, 2013
328
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. change "wlan0" with your interface name, and set the maximum number of packets to be received
  2. build with gcc file.c -lpcap
  3. sudo ./a.out
  4.  
  5. wireshark out.pcap
  6.  
  7. #include <pcap.h>
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <stdint.h>
  11.  
  12. pcap_dumper_t *pdump;
  13. void ec_decode(u_char* prova, const struct pcap_pkthdr *pkthdr, const u_char *pkt)
  14. {
  15. pcap_dump((u_char*)prova, pkthdr, pkt);
  16. }
  17.  
  18. int main()
  19. {
  20. char pcap_errbuf[PCAP_ERRBUF_SIZE];
  21. char perrbuf[PCAP_ERRBUF_SIZE];
  22. pcap_t *pcap = NULL;
  23. //pcap_lookupdev(perrbuf) // finds the first suitable interface
  24. pcap = pcap_open_live(/*pcap_lookupdev(perrbuf)*/"wlan0", UINT16_MAX, 1, 0, pcap_errbuf);
  25. if(pcap==NULL)
  26. printf("\n\nPCAP NULL\n\n");
  27. pdump = pcap_dump_open(pcap, "out.pcap");
  28. if(pcap==NULL)
  29. printf("\n\nPDUMP NULL\n\n");
  30.  
  31. // 15 equals 15 packets, -1 equals inf
  32. pcap_loop(pcap, 15, ec_decode, (unsigned char *)pdump);
  33.  
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement