2 * Copyright (c) 1999 - 2005 NetGroup, Politecnico di Torino (Italy)
3 * Copyright (c) 2005 - 2006 CACE Technologies, Davis (California)
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the Politecnico di Torino, CACE Technologies
16 * nor the names of its contributors may be used to endorse or promote
17 * products derived from this software without specific prior written
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 #include "..\..\..\Include\packet32.h"
41 #define Max_Num_Adapter 10
45 void PrintPackets(LPPACKET lpPacket
);
47 char AdapterList
[Max_Num_Adapter
][8192];
51 int main(int argc
, char **argv
)
53 char packetbuff
[5000];
55 // define a pointer to a ADAPTER structure
57 LPADAPTER lpAdapter
= 0;
59 // define a pointer to a PACKET structure
67 char AdapterName
[8192]; // string that contains a list of the network adapters
70 int AdapterNum
=0,Open
;
75 printf("Traffic Generator v 0.9999\nCopyright 1999 Loris Degioanni (loris@netgroup-serv.polito.it)");
76 printf("\nSends a set of packets to the network using packet.dll API.\n");
79 printf("\n\n Usage: TestpacketSend [-i adapter] -n npacks -s size");
80 printf("\n size is between 60 and 1514\n\n");
87 //get the command line parameters
94 sscanf(argv
[i
+1],"%s",AdapterName
);
98 sscanf(argv
[i
+1],"%d",&npacks
);
102 sscanf(argv
[i
+1],"%d",&Snaplen
);
111 if(AdapterName
[0]==0){
114 // Obtain the name of the adapters installed on this machine
116 printf("Adapters installed:\n");
119 AdapterLength
= sizeof(AdapterName
);
121 if(PacketGetAdapterNames(AdapterName
,&AdapterLength
)==FALSE
){
122 printf("Unable to retrieve the list of the adapters!\n");
128 while ((*temp
!='\0')||(*(temp
-1)!='\0'))
132 memcpy(AdapterList
[i
],temp1
,temp
-temp1
);
140 for (i
=0;i
<AdapterNum
;i
++)
141 printf("\n%d- %s\n",i
+1,AdapterList
[i
]);
146 printf("Select the number of the adapter to open : ");scanf("%d",&Open
);
147 if (Open
>AdapterNum
) printf("\nThe number must be smaller than %d",AdapterNum
);
148 } while (Open
>AdapterNum
);
153 lpAdapter
= PacketOpenAdapter(AdapterList
[Open
-1]);
155 if (!lpAdapter
|| (lpAdapter
->hFile
== INVALID_HANDLE_VALUE
))
157 dwErrorCode
=GetLastError();
158 printf("Unable to open the driver, Error Code : %lx\n",dwErrorCode
);
166 lpAdapter
= PacketOpenAdapter(AdapterName
);
168 if (!lpAdapter
|| (lpAdapter
->hFile
== INVALID_HANDLE_VALUE
))
170 dwErrorCode
=GetLastError();
171 printf("Unable to open the driver, Error Code : %lx\n",dwErrorCode
);
178 if((lpPacket
= PacketAllocatePacket())==NULL
){
179 printf("\nError:failed to allocate the LPPACKET structure.");
197 for(i
=12;i
<1514;i
++){
201 PacketInitPacket(lpPacket
,packetbuff
,Snaplen
);
202 // capture the packet
205 if(PacketSetNumWrites(lpAdapter
,npacks
)==FALSE
){
206 printf("warning: Unable to send more than one packet in a single write!\n");
209 printf("\n\nGenerating %d packets...",npacks
);
211 cpu_time
= (float)clock ();
213 if(PacketSendPacket(lpAdapter
,lpPacket
,TRUE
)==FALSE
){
214 printf("Error sending the packets!\n");
218 cpu_time
= (clock() - cpu_time
)/CLK_TCK
;
220 printf ("\n\nElapsed time: %5.3f\n", cpu_time
);
221 printf ("\nTotal packets generated = %d", npacks
);
222 printf ("\nTotal bytes generated = %d", (Snaplen
+24)*npacks
);
223 printf ("\nTotal bits generated = %d", (Snaplen
+24)*npacks
*8);
224 printf ("\nAverage packets per second = %d", (int)((double)npacks
/cpu_time
));
225 printf ("\nAverage bytes per second = %d", (int)((double)((Snaplen
+24)*npacks
)/cpu_time
));
226 printf ("\nAverage bits per second = %d", (int)((double)((Snaplen
+24)*npacks
*8)/cpu_time
));
229 PacketFreePacket(lpPacket
);
231 // close the adapter and exit
233 PacketCloseAdapter(lpAdapter
);