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
28 // - Currently only IP/MAC resolution supported (i.e. hw_size=6, pr_size=4)
29 // - Add macro support: commands like request/response should set all params correctly
34 int cmd_arp_hwtype (struct cli_def
*cli
, char *command
, char *argv
[], int argc
)
36 struct mops_ext_arp
* pd
= clipkt
->p_desc
;
38 if ( (strncmp(argv
[argc
-1],"?",1)==0) || (argc
!=1) )
40 cli_print(cli
,"Specify the hardware type (0-ffff, default 1=Eth)\n");
42 else if (mops_pdesc_2byte(&pd
->hw_type
, argv
[0], 1, 0, 0xffff))
44 cli_print(cli
, "Hardware type must be between 0 and ffff\n");
52 int cmd_arp_prtype (struct cli_def
*cli
, char *command
, char *argv
[], int argc
)
54 struct mops_ext_arp
* pd
= clipkt
->p_desc
;
56 if ( (strncmp(argv
[argc
-1],"?",1)==0) || (argc
!=1) )
58 cli_print(cli
,"Specify the protocol type (0-ffff, default=800=IP)\n");
60 else if (mops_pdesc_2byte(&pd
->pr_type
, argv
[0], 1, 0, 0xffff))
62 cli_print(cli
, "Protocol type must be between 0 and ffff\n");
70 int cmd_arp_hwaddrsize (struct cli_def
*cli
, char *command
, char *argv
[], int argc
)
72 struct mops_ext_arp
* pd
= clipkt
->p_desc
;
74 if ( (strncmp(argv
[argc
-1],"?",1)==0) || (argc
!=1) )
76 cli_print(cli
,"Specify the hardware address size (0-255, default=6)\n");
78 else if (mops_pdesc_1byte(&pd
->hw_size
, argv
[0], 0, 0, 255))
80 cli_print(cli
, "Hardware size must be between 0 and 255\n");
87 int cmd_arp_praddrsize (struct cli_def
*cli
, char *command
, char *argv
[], int argc
)
89 struct mops_ext_arp
* pd
= clipkt
->p_desc
;
91 if ( (strncmp(argv
[argc
-1],"?",1)==0) || (argc
!=1) )
93 cli_print(cli
,"Specify the protocol address size (0-255, default=4)\n");
95 else if (mops_pdesc_1byte(&pd
->pr_size
, argv
[0], 0, 0, 255))
97 cli_print(cli
, "Protocol size must be between 0 and 255\n");
104 int cmd_arp_opcode (struct cli_def
*cli
, char *command
, char *argv
[], int argc
)
106 struct mops_ext_arp
* pd
= clipkt
->p_desc
;
108 if ( (strncmp(argv
[argc
-1],"?",1)==0) || (argc
!=1) )
110 cli_print(cli
,"Specify the ARP operation code (0-ffff)\n");
111 cli_print(cli
,"Optional keywords: 'request' (default) or 'response'\n");
113 else if (mz_strcmp(argv
[0],"request", 3)==0)
115 cli_print(cli
, "Set ARP mode to request\n");
118 else if (mz_strcmp(argv
[0],"response", 3)==0)
120 cli_print(cli
, "Set ARP mode to response\n");
125 cli_print(cli
, "Invalid ARP mode\n");
133 int cmd_arp_smac (struct cli_def
*cli
, char *command
, char *argv
[], int argc
)
135 struct mops_ext_arp
* pd
= clipkt
->p_desc
;
137 if ( (strncmp(argv
[argc
-1],"?",1)==0) || (argc
!=1) )
139 cli_print(cli
,"Specify a source MAC address (format: XX:XX:XX:XX:XX:XX)\n");
143 if (mops_pdesc_mac(pd
->sender_mac
, argv
[0]))
145 cli_print(cli
,"Invalid MAC address (use format: XX:XX:XX:XX:XX:XX)\n");
153 int cmd_arp_sip (struct cli_def
*cli
, char *command
, char *argv
[], int argc
)
155 struct mops_ext_arp
* pd
= clipkt
->p_desc
;
157 if ( (strncmp(argv
[argc
-1],"?",1)==0) || (argc
!=1) )
159 cli_print(cli
,"Specify a source IP address (format: A.B.C.D)\n");
161 else if (mops_pdesc_ip (pd
->sender_ip
, argv
[0]))
163 cli_print(cli
,"Invalid IP address (use format: A.B.C.D)\n");
171 int cmd_arp_tmac (struct cli_def
*cli
, char *command
, char *argv
[], int argc
)
173 struct mops_ext_arp
* pd
= clipkt
->p_desc
;
175 if ( (strncmp(argv
[argc
-1],"?",1)==0) || (argc
!=1) )
177 cli_print(cli
,"Specify a target MAC address (format: XX:XX:XX:XX:XX:XX)\n");
179 else if (mops_pdesc_mac(pd
->target_mac
, argv
[0]))
181 cli_print(cli
,"Invalid MAC address (use format: XX:XX:XX:XX:XX:XX)\n");
189 int cmd_arp_tip (struct cli_def
*cli
, char *command
, char *argv
[], int argc
)
191 struct mops_ext_arp
* pd
= clipkt
->p_desc
;
193 if ( (strncmp(argv
[argc
-1],"?",1)==0) || (argc
!=1) )
195 cli_print(cli
,"Specify a target IP address (format: A.B.C.D)\n");
197 else if (mops_pdesc_ip (pd
->target_ip
, argv
[0]))
199 cli_print(cli
,"Invalid IP address (use format: A.B.C.D)\n");
207 int cmd_arp_trailer (struct cli_def
*cli
, char *command
, char *argv
[], int argc
)
209 struct mops_ext_arp
* pd
= (MOPS_EXT_ARP
) clipkt
->p_desc
;
211 if ( (strncmp(argv
[argc
-1],"?",1)==0) || (argc
!=1) )
213 cli_print(cli
,"Specify the trailer length (0-2000, default=18)\n");
215 else if (mops_pdesc_2byte(&pd
->trailer
, argv
[0], 0, 0, 2000))
217 cli_print(cli
, "Trailer must be between 0 and 2000\n");
225 int cmd_arp_end(struct cli_def
*cli
, char *command
, char *argv
[], int argc
)
228 sprintf(prompt
, "pkt-%i",clipkt
->id
);
229 cli_set_configmode(cli
, MZ_MODE_PACKET
, prompt
);