krot

winpcap sendpacket

Aug 15th, 2016
101
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <stdint.h>
  4. #include <WinSock2.h>
  5. #include <Windows.h>
  6.  
  7. #define HAVE_REMOTE
  8. #include <pcap.h>
  9. #pragma comment(lib, "ws2_32.lib")
  10. #pragma comment(lib, "wpcap.lib")
  11. void main(int argc, char **argv)
  12. {
  13.     pcap_t *fp;
  14.     char errbuf[PCAP_ERRBUF_SIZE];
  15.     char datagram[4096];
  16.     unsigned long sz = make_datagram(datagram);
  17.     if(argc != 2)
  18.     {
  19.         pcap_if_t * devs = nullptr;
  20.         pcap_findalldevs(&devs, nullptr);
  21.         printf("usage: %s interface\nAvaliable interfaces:\n", argv[0]);
  22.         pcap_if_t * cur_dev = devs;
  23.         while(cur_dev)
  24.         {
  25.             printf("%s (%s)\n", cur_dev->name, cur_dev->description);
  26.             cur_dev = cur_dev->next;
  27.         }
  28.         pcap_freealldevs(devs);
  29.         return;
  30.     }
  31.     if((fp = pcap_open(argv[1], 100, PCAP_OPENFLAG_PROMISCUOUS, 1000, NULL, errbuf)) == NULL)
  32.     {
  33.         fprintf(stderr, "\nUnable to open the adapter. %s is not supported by WinPcap\n", argv[1]);
  34.         return;
  35.     }
  36.     if(pcap_sendpacket(fp, (u_char *)datagram, sz) != 0)
  37.     {
  38.         fprintf(stderr, "\nError sending the packet: %s\n", pcap_geterr(fp));
  39.         return;
  40.     }
  41.     else
  42.     {
  43.         printf("Packet Send \n");
  44.     }
  45.     pcap_close(fp);
  46. }
RAW Paste Data