Advertisement
LocutusOfBorg

pcap/glibc bug?

Sep 6th, 2013
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.34 KB | None | 0 0
  1. first change "wlan0" on the source code with your interface, after
  2. "gcc filename.c -lpcap"
  3.  
  4.  
  5.  
  6. #include <pcap.h>
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <stdint.h>
  10. #include <unistd.h>
  11.  
  12. pcap_t *pcap = NULL;
  13. pcap_dumper_t *pdump;
  14.  
  15. void decode(u_char* param, const struct pcap_pkthdr *pkthdr, const u_char *pkt)
  16. {
  17.    pcap_dump((u_char*)param, pkthdr, pkt);
  18. }
  19.  
  20. static void close_network()
  21. {
  22.    fprintf(stderr,"closing network \n");
  23.    pcap_close(pcap);
  24.    pcap_dump_close(pdump);
  25. }
  26.  
  27. void disable_interface_offload(void)
  28. {
  29.    char *newargv[] = {"ethtool", "-K", "wlan0", "tso", "off", "gso", "off", "gro", "off", "lro", "off", NULL };
  30.    int ret_val;
  31.  
  32.    switch(fork()) {
  33.       case 0:
  34.          execvp("ethtool", newargv);
  35.          fprintf(stderr,"problem, ethtool not found!\n\n");
  36.          exit(10); // this one causes the double header inclusion
  37.          //_exit(10); // while this one does not
  38.       default:
  39.          wait(&ret_val);
  40.    }
  41. int main()
  42. {
  43.    char pcap_errbuf[PCAP_ERRBUF_SIZE];
  44.    pcap = pcap_open_live("wlan0", UINT16_MAX, 1, 0, pcap_errbuf);
  45.    if(pcap==NULL)
  46.       printf("\n\nPCAP NULL\n\n");
  47.    pdump = pcap_dump_open(pcap, "out.pcap");
  48.    if(pcap==NULL)
  49.       printf("\n\nPDUMP NULL\n\n");
  50.    disable_interface_offload();
  51.    pcap_loop(pcap, 2, decode, (unsigned char *)pdump);
  52.    return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement