ifpps: remove unused member from struct
[netsniff.git] / src / cli_udp.c
blob1bc108bd30717419efaa576648c4d0ca51d7d28d
1 /*
2 * Mausezahn - A fast versatile traffic generator
3 * Copyright (C) 2008-2010 Herbert Haas
4 *
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.
8 *
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
12 * details.
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
20 #include "mz.h"
21 #include "cli.h"
22 #include "mops.h"
26 int cmd_port_source (struct cli_def *cli, char *command, char *argv[], int argc)
28 u_int32_t t32=0;
29 int validport=0;
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");
35 cli_print(cli, "\n");
36 return CLI_OK;
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;
44 } else {
45 if (!mz_strisnum(argv[0])) {
46 cli_print(cli, "Unknown keyword\n");
47 return CLI_OK;
49 t32 = str2int(argv[0]);
50 if (t32>65535) {
51 cli_print(cli, "Port number cannot exceed 65535\n");
52 return CLI_OK;
53 } else {
54 clipkt->sp= (u_int16_t) t32;
55 validport=1;
56 clipkt->sp_isrange = 0;
60 if ((argc==2) && (validport)) {
61 if (!mz_strisnum(argv[1])) {
62 cli_print(cli, "Invalid number\n");
63 return CLI_OK;
65 t32 = str2int(argv[1]);
66 if (t32>65535) {
67 cli_print(cli, "Port number cannot exceed 65535\n");
68 } else {
69 clipkt->sp_start = clipkt->sp;
70 clipkt->sp_stop = (u_int16_t) t32;
71 clipkt->sp_isrange = 1;
75 return CLI_OK;
81 int cmd_port_destination (struct cli_def *cli, char *command, char *argv[], int argc)
83 u_int32_t t32=0;
84 int validport=0;
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");
90 cli_print(cli, "\n");
91 return CLI_OK;
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;
99 } else {
100 if (!mz_strisnum(argv[0])) {
101 cli_print(cli, "Unknown keyword\n");
102 return CLI_OK;
105 t32 = str2int(argv[0]);
106 if (t32>65535) {
107 cli_print(cli, "Port number cannot exceed 65535\n");
108 return CLI_OK;
109 } else {
110 clipkt->dp= (u_int16_t) t32;
111 validport=1;
112 clipkt->dp_isrange = 0;
116 if ((argc==2) && (validport)) {
117 if (!mz_strisnum(argv[1])) {
118 cli_print(cli, "Invalid number\n");
119 return CLI_OK;
121 t32 = str2int(argv[1]);
122 if (t32>65535) {
123 cli_print(cli, "Port number cannot exceed 65535\n");
124 } else {
125 clipkt->dp_start = clipkt->dp;
126 clipkt->dp_stop = (u_int16_t) t32;
127 clipkt->dp_isrange = 1;
131 return CLI_OK;
136 int cmd_udp_sum (struct cli_def *cli, char *command, char *argv[], int argc)
138 int sum;
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");
150 return CLI_OK;
153 if (mz_strcmp(argv[0], "auto", 2)==0)
155 clipkt->udp_sum_false=0;
156 return CLI_OK;
159 if (mz_strcmp(argv[0], "unset", 2)==0)
161 clipkt->udp_sum_false=1;
162 clipkt->udp_sum = 0xffff;
163 return CLI_OK;
166 sum = (int) xstr2int(argv[0]);
168 if (sum>0xffff)
170 cli_print(cli, "The checksum must be within range 0..ffff\n");
171 return CLI_OK;
174 clipkt->udp_sum = (u_int16_t) sum;
175 clipkt->udp_sum_false=1;
177 return CLI_OK;
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");
189 return CLI_OK;
192 cli_print(cli, "Not supported in this version.\n");
194 return CLI_OK;
198 int cmd_udp_end(struct cli_def *cli, char *command, char *argv[], int argc)
200 char prompt[16];
201 sprintf(prompt, "pkt-%i",clipkt->id);
202 cli_set_configmode(cli, MZ_MODE_PACKET, prompt);
203 return CLI_OK;