make: fix access to env vars
[netsniff.git] / src / cli_igmp.c
blob4fa5867b4abebf6ec4ffa3173e1d568036731d89
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
21 #include "mz.h"
22 #include "cli.h"
23 #include "mops.h"
26 int cmd_igmpv2_genquery (struct cli_def *cli, char *command, char *argv[], int argc)
28 int mrt, sum;
30 if ( (strcmp(argv[argc-1],"?")==0) || (argc>2) ) {
31 cli_print(cli, "Configure a IGMPv2 general query.\n");
32 cli_print(cli, "ARGUMENTS: [<MRT> [<checksum>]]\n");
33 cli_print(cli, "<MRT> ... maximum response time in 100 msec units (default: 10 s)\r");
34 cli_print(cli, "<checksum> ... user-defined checksum (usually wrong by intention) in \r");
35 cli_print(cli, " hexadecimal notation (e. g. 'c7b3').\n");
36 return CLI_OK;
39 if (argc>=1) {
40 if (mz_strisnum(argv[0])==0) {
41 cli_print(cli, "Maximum response time must only contain numbers!\n");
42 return CLI_OK;
44 mrt = (int) str2int(argv[0]);
45 } else mrt = 100; // default: 10 s
47 if (argc==2) {
48 if (mz_strishex(argv[1])==0) {
49 cli_print(cli, "Checksum must only contain hexadecimal numbers!\n");
50 return CLI_OK;
52 sum = (int) xstr2int(argv[1]);
53 if (sum>0xffff) {
54 cli_print(cli, "Checksum must be a 2-byte value!\n");
55 return CLI_OK;
58 } else sum = -1;
60 clipkt->ip_dst = str2ip32("224.0.0.1");
61 clipkt->ip_ttl = 1;
62 clipkt->ndelay.tv_sec = 125;
63 clipkt->ndelay.tv_nsec = 0;
64 if (mops_create_igmpv2 (clipkt, 0, IGMP_GENERAL_QUERY, mrt, sum, 0))
65 cli_print(cli, "Invalid parameters!\n");
67 return CLI_OK;
71 int cmd_igmpv2_specquery (struct cli_def *cli, char *command, char *argv[], int argc)
73 int mrt=100, sum=-1;
74 u_int8_t IP[4];
75 u_int32_t mip=0;
77 if ( (strcmp(argv[argc-1],"?")==0) || (argc>3) ) {
78 cli_print(cli, "Configure a IGMPv2 group-specific query.\n");
79 cli_print(cli, "ARGUMENTS: <IP-address> [<MRT> [<checksum>]]\n");
80 cli_print(cli, "<IP-Address> ... multicast group to be queried (can be ANY IP address!)\r");
81 cli_print(cli, "<MRT> ... maximum response time in 100 msec units (default: 10 s)\r");
82 cli_print(cli, "<checksum> ... user-defined checksum (usually wrong by intention) in \r");
83 cli_print(cli, " hexadecimal notation (e. g. 'c7b3').\n");
84 return CLI_OK;
88 if (argc==0) {
89 cli_print(cli, "You must at least specify the group address\n");
90 return CLI_OK;
93 if (argc>=1) {
94 if (mops_pdesc_ip (IP, argv[0])==0) // check if format is really an IP address
95 mip = str2ip32(argv[0]);
96 else {
97 cli_print(cli, "Invalid IP address\n");
98 return CLI_OK;
102 if (argc>=2) {
103 if (mz_strisnum(argv[1])==0) {
104 cli_print(cli, "Maximum response time must only contain numbers!\n");
105 return CLI_OK;
107 mrt = (int) str2int(argv[1]);
110 if (argc==3) {
111 if (mz_strishex(argv[2])==0) {
112 cli_print(cli, "Checksum must only contain hexadecimal numbers!\n");
113 return CLI_OK;
115 sum = (int) xstr2int(argv[2]);
116 if (sum>0xffff) {
117 cli_print(cli, "Checksum must be a 2-byte value!\n");
118 return CLI_OK;
122 clipkt->ip_dst = mip;
123 clipkt->ip_ttl = 1;
124 clipkt->ndelay.tv_sec = 125;
125 clipkt->ndelay.tv_nsec = 0;
126 if (mops_create_igmpv2 (clipkt, 0, IGMP_GSPEC_QUERY, mrt, sum, mip))
127 cli_print(cli, "Invalid parameters!\n");
129 return CLI_OK;
136 int cmd_igmpv2_report (struct cli_def *cli, char *command, char *argv[], int argc)
138 int sum;
139 u_int8_t IP[4];
140 u_int32_t mip=0;
142 if ( (strcmp(argv[argc-1],"?")==0) || (argc>2) || (argc==0)) {
143 cli_print(cli, "Configure a IGMPv2 membership report.\n");
144 cli_print(cli, "ARGUMENTS: <IP-Address> [<checksum>]\n");
145 cli_print(cli, "<IP-Address> ... multicast group address to be reported (but ANY IP\r");
146 cli_print(cli, " address allowed, Mausezahn is really generous...)\r");
147 cli_print(cli, "<checksum> ... user-defined checksum (usually wrong by intention) in \r");
148 cli_print(cli, " hexadecimal notation (e. g. 'c7b3').\n");
149 return CLI_OK;
153 if (argc>=1) {
154 if (mops_pdesc_ip (IP, argv[0])==0) // check if format is really an IP address
155 mip = str2ip32(argv[0]);
156 else {
157 cli_print(cli, "Invalid IP address\n");
158 return CLI_OK;
162 if (argc==2) {
163 if (mz_strishex(argv[1])==0) {
164 cli_print(cli, "Checksum must only contain hexadecimal numbers!\n");
165 return CLI_OK;
167 sum = (int) xstr2int(argv[1]);
168 if (sum>0xffff) {
169 cli_print(cli, "Checksum must be a 2-byte value!\n");
170 return CLI_OK;
172 } else sum = -1;
174 clipkt->ip_dst = mip;
175 clipkt->ip_ttl = 1;
176 clipkt->ndelay.tv_sec = 1;
177 clipkt->ndelay.tv_nsec = 0;
179 if (mops_create_igmpv2 (clipkt, 0, IGMP_V2_REPORT, 0, sum, mip))
180 cli_print(cli, "Invalid parameters!\n");
182 return CLI_OK;
186 int cmd_igmpv2_leave (struct cli_def *cli, char *command, char *argv[], int argc)
188 int sum;
189 u_int8_t IP[4];
190 u_int32_t mip=0;
192 if ( (strcmp(argv[argc-1],"?")==0) || (argc>2) || (argc==0)) {
193 cli_print(cli, "Configure a IGMPv2 leave group message.\n");
194 cli_print(cli, "ARGUMENTS: <IP-Address> [<checksum>]\n");
195 cli_print(cli, "<IP-Address> ... multicast group address that should be left; use\r");
196 cli_print(cli, " the special address 0.0.0.0 for a 'general leave'\r");
197 cli_print(cli, "<checksum> ... user-defined checksum (usually wrong by intention) in \r");
198 cli_print(cli, " hexadecimal notation (e. g. 'c7b3').\n");
199 return CLI_OK;
203 if (argc>=1) {
204 if (mops_pdesc_ip (IP, argv[0])==0) // check if format is really an IP address
205 mip = str2ip32(argv[0]);
206 else {
207 cli_print(cli, "Invalid IP address\n");
208 return CLI_OK;
212 if (argc==2) {
213 if (mz_strishex(argv[1])==0) {
214 cli_print(cli, "Checksum must only contain hexadecimal numbers!\n");
215 return CLI_OK;
217 sum = (int) xstr2int(argv[1]);
218 if (sum>0xffff) {
219 cli_print(cli, "Checksum must be a 2-byte value!\n");
220 return CLI_OK;
222 } else sum = -1;
224 clipkt->ip_dst = str2ip32("224.0.0.2");
225 clipkt->ip_ttl = 1;
226 clipkt->ndelay.tv_sec = 1;
227 clipkt->ndelay.tv_nsec = 0;
229 if (mops_create_igmpv2 (clipkt, 0, IGMP_LEAVE, 0, sum, mip))
230 cli_print(cli, "Invalid parameters!\n");
232 return CLI_OK;
239 int cmd_igmpv1_query (struct cli_def *cli, char *command, char *argv[], int argc)
241 int sum;
243 if ( (strcmp(argv[argc-1],"?")==0) || (argc>1) ) {
244 cli_print(cli, "Configure a IGMPv1 query.\n");
245 cli_print(cli, "OPTIONAL ARGUMENT: [<checksum>]\n");
246 cli_print(cli, "<checksum> ... user-defined checksum (usually wrong by intention) in \r");
247 cli_print(cli, " hexadecimal notation (e. g. 'c7b3').\n");
248 return CLI_OK;
251 if (argc==1) {
252 if (mz_strishex(argv[0])==0) {
253 cli_print(cli, "Checksum must only contain hexadecimal numbers!\n");
254 return CLI_OK;
256 sum = (int) xstr2int(argv[0]);
257 if (sum>0xffff) {
258 cli_print(cli, "Checksum must be a 2-byte value!\n");
259 return CLI_OK;
261 } else sum = -1;
263 clipkt->ip_dst = str2ip32("224.0.0.1");
264 clipkt->ip_ttl = 1;
265 clipkt->ndelay.tv_sec = 125;
266 clipkt->ndelay.tv_nsec = 0;
267 if (mops_create_igmpv2 (clipkt, 0, IGMP_GENERAL_QUERY, 0, sum, 0))
268 cli_print(cli, "Invalid parameters!\n");
270 return CLI_OK;
274 int cmd_igmpv1_report (struct cli_def *cli, char *command, char *argv[], int argc)
276 int sum;
277 u_int8_t IP[4];
278 u_int32_t mip=0;
280 if ( (strcmp(argv[argc-1],"?")==0) || (argc>2) || (argc==0)) {
281 cli_print(cli, "Configure a IGMPv1 membership report.\n");
282 cli_print(cli, "ARGUMENTS: <IP-Address> [<checksum>]\n");
283 cli_print(cli, "<IP-Address> ... multicast group address to be reported (but ANY IP\r");
284 cli_print(cli, " address allowed, Mausezahn is really generous...)\r");
285 cli_print(cli, "<checksum> ... user-defined checksum (usually wrong by intention) in \r");
286 cli_print(cli, " hexadecimal notation (e. g. 'c7b3').\n");
287 return CLI_OK;
291 if (argc>=1) {
292 if (mops_pdesc_ip (IP, argv[0])==0) // check if format is really an IP address
293 mip = str2ip32(argv[0]);
294 else {
295 cli_print(cli, "Invalid IP address\n");
296 return CLI_OK;
300 if (argc==2) {
301 if (mz_strishex(argv[1])==0) {
302 cli_print(cli, "Checksum must only contain hexadecimal numbers!\n");
303 return CLI_OK;
305 sum = (int) xstr2int(argv[1]);
306 if (sum>0xffff) {
307 cli_print(cli, "Checksum must be a 2-byte value!\n");
308 return CLI_OK;
310 } else sum = -1;
312 clipkt->ip_dst = mip;
313 clipkt->ip_ttl = 1;
314 clipkt->ndelay.tv_sec = 1;
315 clipkt->ndelay.tv_nsec = 0;
317 if (mops_create_igmpv2 (clipkt, 0, IGMP_V1_REPORT, 0, sum, mip))
318 cli_print(cli, "Invalid parameters!\n");
320 return CLI_OK;