ifpps: remove unused member from struct
[netsniff.git] / src / cli_arp.c
blob71815752e5b74bce90c8a7cba5f35ebdd3a0881e
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 // ISSUES:
27 //
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");
47 return CLI_OK;
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");
65 return CLI_OK;
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");
83 return CLI_OK;
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");
100 return CLI_OK;
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");
116 pd->opcode = 1;
118 else if (mz_strcmp(argv[0],"response", 3)==0)
120 cli_print(cli, "Set ARP mode to response\n");
121 pd->opcode = 2;
123 else
125 cli_print(cli, "Invalid ARP mode\n");
128 return CLI_OK;
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");
141 else
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");
148 return CLI_OK;
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");
166 return CLI_OK;
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");
184 return CLI_OK;
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");
202 return CLI_OK;
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");
220 return CLI_OK;
225 int cmd_arp_end(struct cli_def *cli, char *command, char *argv[], int argc)
227 char prompt[16];
228 sprintf(prompt, "pkt-%i",clipkt->id);
229 cli_set_configmode(cli, MZ_MODE_PACKET, prompt);
230 return CLI_OK;