2 * Mausezahn - A fast versatile traffic generator
3 * Copyright (C) 2008-2010 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
26 int cmd_port_source (struct cli_def
*cli
, char *command
, char *argv
[], int argc
)
31 if ( (strcmp(argv
[argc
-1],"?")==0) || (argc
>2) ) {
32 cli_print(cli
, "Specify the source port number:\n");
33 cli_print(cli
, " <port> [<end-port>]\r");
34 cli_print(cli
, " random [norandom]\r");
39 if (mz_strcmp(argv
[0], "random",1)==0) {
40 clipkt
->sp_isrand
= 1;
41 clipkt
->sp_isrange
= 0;
42 } else if (mz_strcmp(argv
[0], "norandom",1)==0) {
43 clipkt
->sp_isrand
= 0;
45 if (!mz_strisnum(argv
[0])) {
46 cli_print(cli
, "Unknown keyword\n");
49 t32
= str2int(argv
[0]);
51 cli_print(cli
, "Port number cannot exceed 65535\n");
54 clipkt
->sp
= (u_int16_t
) t32
;
56 clipkt
->sp_isrange
= 0;
60 if ((argc
==2) && (validport
)) {
61 if (!mz_strisnum(argv
[1])) {
62 cli_print(cli
, "Invalid number\n");
65 t32
= str2int(argv
[1]);
67 cli_print(cli
, "Port number cannot exceed 65535\n");
69 clipkt
->sp_start
= clipkt
->sp
;
70 clipkt
->sp_stop
= (u_int16_t
) t32
;
71 clipkt
->sp_isrange
= 1;
81 int cmd_port_destination (struct cli_def
*cli
, char *command
, char *argv
[], int argc
)
86 if ( (strcmp(argv
[argc
-1],"?")==0) || (argc
>2) ) {
87 cli_print(cli
, "Specify the destination port number\r");
88 cli_print(cli
, " <port> [<end-port>]\r");
89 cli_print(cli
, " random [norandom]\r");
94 if (mz_strcmp(argv
[0], "random",1)==0) {
95 clipkt
->dp_isrand
= 1;
96 clipkt
->dp_isrange
= 0;
97 } else if (mz_strcmp(argv
[0], "norandom",1)==0) {
98 clipkt
->dp_isrand
= 0;
100 if (!mz_strisnum(argv
[0])) {
101 cli_print(cli
, "Unknown keyword\n");
105 t32
= str2int(argv
[0]);
107 cli_print(cli
, "Port number cannot exceed 65535\n");
110 clipkt
->dp
= (u_int16_t
) t32
;
112 clipkt
->dp_isrange
= 0;
116 if ((argc
==2) && (validport
)) {
117 if (!mz_strisnum(argv
[1])) {
118 cli_print(cli
, "Invalid number\n");
121 t32
= str2int(argv
[1]);
123 cli_print(cli
, "Port number cannot exceed 65535\n");
125 clipkt
->dp_start
= clipkt
->dp
;
126 clipkt
->dp_stop
= (u_int16_t
) t32
;
127 clipkt
->dp_isrange
= 1;
136 int cmd_udp_sum (struct cli_def
*cli
, char *command
, char *argv
[], int argc
)
140 if ( (strcmp(argv
[argc
-1],"?")==0) || (argc
>1) )
142 cli_print(cli
, "Specify the UDP checksum:\n");
143 cli_print(cli
, " - either in hexadecimal format (0-ffff)\r");
144 cli_print(cli
, " - or use the keyword 'auto' (default)\r");
145 cli_print(cli
, " - or use the keyword 'unset'\r");
146 cli_print(cli
, "\r");
147 cli_print(cli
, "By default, the checksum is computed automatically. The keyword\r");
148 cli_print(cli
, "'unset' signals the receiver that the checksum has not be computed\r");
149 cli_print(cli
, "and should be ignored.\n");
153 if (mz_strcmp(argv
[0], "auto", 2)==0)
155 clipkt
->udp_sum_false
=0;
159 if (mz_strcmp(argv
[0], "unset", 2)==0)
161 clipkt
->udp_sum_false
=1;
162 clipkt
->udp_sum
= 0xffff;
166 sum
= (int) xstr2int(argv
[0]);
170 cli_print(cli
, "The checksum must be within range 0..ffff\n");
174 clipkt
->udp_sum
= (u_int16_t
) sum
;
175 clipkt
->udp_sum_false
=1;
182 int cmd_udp_len (struct cli_def
*cli
, char *command
, char *argv
[], int argc
)
185 if ( (strcmp(argv
[argc
-1],"?")==0) || (argc
>1) )
187 cli_print(cli
, "Specify the UDP length\r");
188 cli_print(cli
, "\n");
192 cli_print(cli
, "Not supported in this version.\n");
198 int cmd_udp_end(struct cli_def
*cli
, char *command
, char *argv
[], int argc
)
201 sprintf(prompt
, "pkt-%i",clipkt
->id
);
202 cli_set_configmode(cli
, MZ_MODE_PACKET
, prompt
);