Advertisement
Guest User

Untitled

a guest
Nov 26th, 2014
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.86 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <time.h>
  4. #include <pcap.h>
  5.  
  6. void main(int argc, char **argv) {
  7.     pcap_t *fp;
  8.     char errbuf[PCAP_ERRBUF_SIZE];
  9.     int i;
  10.  
  11.     fp = pcap_open_live("eth1", 100, 1, 1000, errbuf);
  12.     if (fp == NULL) {
  13.         fprintf(stderr, "\nUnable to open eth1\n");
  14.         return;
  15.     }
  16.  
  17.     printf("Press ^C to exit\n");
  18.     while (1) {
  19.         u_char packet[100];
  20.  
  21.         /* Set destination mac to FF:FF:FF:FF:FF:FF (broadcast) */
  22.         int x;
  23.         for (x = 0; x <= 5; x++) {
  24.             packet[x] = 0xFF;
  25.         }
  26.  
  27.         /* Set source to a randomized mac */
  28.         for (x = 6; x <= 11; x++) {
  29.             int r = rand() % 0xFF;
  30.             packet[x] = r;
  31.         }
  32.  
  33.         /* Other garbage data */
  34.         for (x = 12; x < 100; x++) {
  35.             packet[x] = x%256;
  36.         }
  37.  
  38.         if(pcap_sendpacket(fp, packet, 100) != 0) {
  39.             fprintf(stderr, "\nError sending the packet: %s\n", pcap_geterr(fp));
  40.             return;
  41.         }
  42.     }
  43.  
  44.     return;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement