2 * Mausezahn - A fast versatile traffic generator
3 * Copyright (C) 2008 Herbert Haas
5 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License version 2 as published by the
7 * Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, see http://www.gnu.org/licenses/gpl-2.0.html
23 // ***************************************************************************
25 // This sections contains:
27 // - complexity() ... calculates and reports how many frames will
29 // - send_frame() ... the general and mighty SENDING FUNCTION.
31 // ***************************************************************************
37 // Calculates the number of frames to be sent.
38 // Should be used as standard output except the
39 // 'quiet' option (-q) has been specified.
56 if (tx
.count
==0) goto infinity
;
60 // How many sequence numbers?
63 sn1
= tx
.tcp_seq_start
;
64 sn2
= tx
.tcp_seq_stop
;
65 delta
= tx
.tcp_seq_delta
;
67 if (sn1
<sn2
) // the easier case
69 nr_sqnr
= (sn2
-sn1
)/delta
;
73 nr_sqnr
= (sn2
+ (0xffffffff - sn1
)) / delta
;
75 //fprintf(stderr,"SQNR Range = %lu\n",nr_sqnr);
81 nr_dp
= tx
.dp_stop
- tx
.dp_start
+ 1;
82 //fprintf(stderr,"DP Range = %lu\n",nr_dp);
87 nr_sp
= tx
.sp_stop
- tx
.sp_start
+ 1;
88 //fprintf(stderr,"SP Range = %lu\n",nr_sp);
91 if (tx
.ip_dst_isrange
)
93 nr_da
= tx
.ip_dst_stop
- tx
.ip_dst_start
+ 1;
94 //fprintf(stderr,"DA Range = %lu\n",nr_da);
97 if (tx
.ip_src_isrange
)
99 nr_sa
= tx
.ip_src_stop
- tx
.ip_src_start
+ 1;
100 //fprintf(stderr,"SA Range = %lu\n",nr_sa);
119 fprintf(stderr
, "You must be crazy...\n");
121 else if (total_d
>0xffffffff)
123 fprintf(stderr
, "Do you REALLY know what you do?\n");
125 else if (total_d
>0xffffff)
127 fprintf(stderr
, "Do you know what you do?\n");
132 cli_print(gcli
, "Mausezahn will send %.Lf frames...\r", total_d
);
136 fprintf(stderr
, "Mausezahn will send %.Lf frames... ", total_d
);
138 if (verbose
) fprintf(stderr
,"\n");
152 cli_print(gcli
, "Mausezahn will send frames infinitly...\n");
156 fprintf(stderr
, "Mausezahn will send frames infinitly...\n");
166 ///////////////////////////////////////////////////////////////////////
168 // Send complete frame (layers 2, 3, 4) multiple times if required
171 int send_frame (libnet_t
*l
, libnet_ptag_t t3
, libnet_ptag_t t4
)
175 int // local vars are faster ;-)
185 tcp_seq_delta
= tx
.tcp_seq_delta
;
186 dp_isrange
= tx
.dp_isrange
;
187 sp_isrange
= tx
.sp_isrange
;
188 ip_dst_isrange
= tx
.ip_dst_isrange
;
189 ip_src_isrange
= tx
.ip_src_isrange
| tx
.ip_src_rand
;
190 if (mode
== RTP
) rtp_mode
= 1;
192 if (count
==0) goto AGAIN
;
194 for (i
=0; i
<count
; i
++)
199 if (verbose
) (void) print_frame_details();
201 if (mz_rand
) tx
.delay
=(unsigned int) tx
.delay
*rand()/RAND_MAX
;
202 if (tx
.delay
) SLEEP (tx
.delay
);
204 // No layer-2 modifications done here
205 // (see create_eth_frame which does L2 modifications additionally)
210 if (update_TCP_SQNR(l
, t4
)==0) // end of range not yet reached
218 if (update_DPORT(l
, t4
)==0) // end of range not yet reached
226 if (update_SPORT(l
, t4
)==0) // end of range not yet reached
235 if (update_IP_DA(l
, t3
)==0) // end of range not yet reached
241 if (ip_src_isrange
) // also catches random SA (see above)
243 if (update_IP_SA(l
, t3
)==0) // end of range not yet reached
249 if (rtp_mode
) // update SQNR and Timestamps in RTP header and payload
255 if (!count
) goto AGAIN
;