Advertisement
teknoraver

mrelay

May 28th, 2015
359
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.36 KB | None | 0 0
  1. /************************************************************************
  2.  *                                  *
  3.  *  mrelay - Copyright 2011 Matteo Croce <rootkit85@yahoo.it>   *
  4.  *                                  *
  5.  ***********************************************************************/
  6.  
  7. //#include <stdio.h>
  8. #include <stdlib.h>
  9. //#include <string.h>
  10.  
  11. #include <pcap.h>
  12.  
  13. #define DEV1    "wlan0"
  14. #define DEV2    "eth0"
  15.  
  16. void got_packet(u_char *, const struct pcap_pkthdr *, const u_char *);
  17.  
  18. int main(int argc, char *argv[])
  19. {
  20.     pcap_t *handle;
  21.     char errbuf[PCAP_ERRBUF_SIZE] = {0};
  22.     struct bpf_program fp;
  23.  
  24.     handle = pcap_open_live(DEV1, BUFSIZ, 0, 0, errbuf);
  25.     if(!handle) {
  26.         printf("!handle");
  27.         return 1;
  28.     }
  29.  
  30.     pcap_compile(handle, &fp, "host 239.255.255.250 && udp port 1900", 1, 0);
  31. //  pcap_compile(handle, &fp, "(host 239.255.255.250 && udp port 1900) || (host 224.0.0.251 && udp port 5353)", 1, 0);
  32.     pcap_setfilter(handle, &fp);
  33.  
  34.     pcap_loop(handle, -1, got_packet, NULL);
  35.  
  36.     pcap_close(handle);
  37.  
  38.     return 0;
  39. }
  40.  
  41. void got_packet(u_char *args, const struct pcap_pkthdr *header, const u_char *packet)
  42. {
  43.     printf("Got packet\n");
  44.  
  45.     char errbuf[PCAP_ERRBUF_SIZE];
  46.     pcap_t* inject_int_desc = pcap_open_live(DEV2, BUFSIZ, 0, 0, errbuf);
  47.  
  48.     if(!inject_int_desc) {
  49.         printf("Error: %s\n", errbuf);
  50.         exit(1);
  51.     }
  52.  
  53.     pcap_inject(inject_int_desc, packet, header->len);
  54.  
  55.     pcap_close(inject_int_desc);
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement