add winpcap 4.0.2 from url http://www.winpcap.org/
[natblaster.git] / winpcap / Examples / misc / sendpack.c
blob91d83b67a44529afd49a3a6ad632a255af27bd48
1 #include <stdlib.h>
2 #include <stdio.h>
4 #include <pcap.h>
7 void main(int argc, char **argv)
9 pcap_t *fp;
10 char errbuf[PCAP_ERRBUF_SIZE];
11 u_char packet[100];
12 int i;
14 /* Check the validity of the command line */
15 if (argc != 2)
17 printf("usage: %s interface (e.g. 'rpcap://eth0')", argv[0]);
18 return;
21 /* Open the output device */
22 if ( (fp= pcap_open(argv[1], // name of the device
23 100, // portion of the packet to capture (only the first 100 bytes)
24 PCAP_OPENFLAG_PROMISCUOUS, // promiscuous mode
25 1000, // read timeout
26 NULL, // authentication on the remote machine
27 errbuf // error buffer
28 ) ) == NULL)
30 fprintf(stderr,"\nUnable to open the adapter. %s is not supported by WinPcap\n", argv[1]);
31 return;
34 /* Supposing to be on ethernet, set mac destination to 1:1:1:1:1:1 */
35 packet[0]=1;
36 packet[1]=1;
37 packet[2]=1;
38 packet[3]=1;
39 packet[4]=1;
40 packet[5]=1;
42 /* set mac source to 2:2:2:2:2:2 */
43 packet[6]=2;
44 packet[7]=2;
45 packet[8]=2;
46 packet[9]=2;
47 packet[10]=2;
48 packet[11]=2;
50 /* Fill the rest of the packet */
51 for(i=12;i<100;i++)
53 packet[i]=i%256;
56 /* Send down the packet */
57 if (pcap_sendpacket(fp, packet, 100 /* size */) != 0)
59 fprintf(stderr,"\nError sending the packet: \n", pcap_geterr(fp));
60 return;
63 return;