make: add mrproper and help targets
[netsniff-ng.git] / src / cli_eth.c
blobc3b0c905fe6fe6de4a3dcb3d76213fdb81c31d9f
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"
28 int cmd_packet_mac_address_source (struct cli_def *cli, char *command, char *argv[], int argc)
30 int i,j;
32 if ( (strcmp(argv[argc-1],"?")==0) || (argc>1) )
34 cli_print(cli, "XX:XX:XX:XX:XX:XX Configure a source MAC address\n");
35 cli_print(cli, "Optionally you may use randomly generated (unicast)\r");
36 cli_print(cli, "MAC addresses, using the keyword 'random'\n");
37 return CLI_OK;
40 if (argc==1)
42 if (mz_strcmp(argv[0], "random", 3)==0)
44 clipkt->eth_src_israndom = 1;
45 return CLI_OK;
48 if (mz_strcmp(argv[0], "default", 3)==0)
50 // find index of device_list with the device configured in clipkt:
51 i=0;
52 while (strncmp(device_list[i].dev, clipkt->device, 10) && (i<device_list_entries)) i++;
53 for (j=0;j<6;j++) clipkt->eth_src[j] = device_list[i].mac_mops[j];
54 clipkt->eth_src_israndom = 0;
55 return CLI_OK;
58 if (mops_pdesc_mac(clipkt->eth_src, argv[0]))
60 cli_print(cli,"Invalid MAC address (use format: XX:XX:XX:XX:XX:XX)\n");
62 else // MAC was OK
64 clipkt->eth_src_israndom = 0;
67 else
68 cli_print(cli, "Invalid MAC format!\n");
71 return CLI_OK;
76 int cmd_packet_mac_address_destination (struct cli_def *cli, char *command, char *argv[], int argc)
79 if ( (strcmp(argv[argc-1],"?")==0) || (argc>1) )
81 cli_print(cli, "XX:XX:XX:XX:XX:XX Configure a destination MAC address\n");
82 return CLI_OK;
84 if (argc==1)
86 if (mz_strcmp(argv[0], "bcast", 2)==0)
88 mops_pdesc_mac (clipkt->eth_dst, "ff:ff:ff:ff:ff:ff");
89 return CLI_OK;
91 else if (mz_strcmp(argv[0], "pvst", 2)==0)
93 mops_pdesc_mac (clipkt->eth_dst, "01:00:0C:CC:CC:CD");
94 return CLI_OK;
96 else if (mz_strcmp(argv[0], "cisco", 2)==0)
98 mops_pdesc_mac (clipkt->eth_dst, "01:00:0C:CC:CC:CC");
99 return CLI_OK;
101 else if (mz_strcmp(argv[0], "stp", 2)==0)
103 mops_pdesc_mac (clipkt->eth_dst, "01:80:C2:00:00:00");
104 return CLI_OK;
107 if (mops_pdesc_mac(clipkt->eth_dst, argv[0]))
109 cli_print(cli,"Invalid MAC address (use format: XX:XX:XX:XX:XX:XX)\n");
112 else
113 cli_print(cli, "Invalid MAC format!\n");
115 return CLI_OK;
123 int cmd_eth_type (struct cli_def *cli, char *command, char *argv[], int argc)
125 unsigned long int t32;
127 if ( (strcmp(argv[argc-1],"?")==0) || (argc>1) )
129 cli_print(cli, "Specify the Ethernet type field in hexadecimal format.\n");
130 cli_print(cli, "For example:\n");
131 cli_print(cli, " 800 ......... IP\r");
132 cli_print(cli, " 806 ......... ARP\r");
133 cli_print(cli, " 835 ......... RARP\r");
134 cli_print(cli, " 8100 ......... 802.1Q\r");
135 cli_print(cli, " 888E ......... 802.1X\r");
136 cli_print(cli, "\n");
137 return CLI_OK;
140 if (argc==1)
142 t32 = xstr2int(argv[0]);
143 if (t32>0xffff)
145 cli_print(cli, "EtherType must not exceed ffff.\n");
146 return CLI_OK;
148 if (t32<0x800)
150 cli_print(cli, "WARNING: 'Officially' the EtherType must be greater or equal 800.\n");
153 clipkt->eth_type = (u_int16_t) t32;
155 else
157 cli_print(cli, "Only one parameter accepted.\n");
160 return CLI_OK;
166 int cmd_eth_length (struct cli_def *cli, char *command, char *argv[], int argc)
168 unsigned long int t32;
170 if ( (strcmp(argv[argc-1],"?")==0) || (argc>1) )
172 cli_print(cli, "Specify the 802.3 length field in decimal notation.\r");
173 cli_print(cli, "\n");
174 return CLI_OK;
177 if (argc==1)
179 t32 = str2int(argv[0]);
180 if (t32>0xffff)
182 cli_print(cli, "The length field must not exceed 65535.\n");
183 return CLI_OK;
185 if (t32>0x7ff)
187 cli_print(cli, "WARNING: 'Officially' the 802.3 length field must not be greater than 1522.\n");
190 clipkt->eth_len = (u_int16_t) t32;
192 else
194 cli_print(cli, "Only one parameter accepted.\n");
199 return CLI_OK;
206 int cmd_eth_llc (struct cli_def *cli, char *command, char *argv[], int argc)
209 if ( (strcmp(argv[argc-1],"?")==0) || (argc>1) )
211 cli_print(cli, "Specify the IEEE 802.2 Logical Link Control (LLC) in hexadecimal format.\n");
212 return CLI_OK;
215 // DSAP-SSAP-Ctrl
216 // ***** TODO *****
217 cli_print(cli, "Not supported in this version.\n");
219 return CLI_OK;
225 int cmd_eth_snap (struct cli_def *cli, char *command, char *argv[], int argc)
228 u_int8_t
229 oui[16],
230 etp[16],
231 t8[16] = {0xAA, 0xAA, 0x03};
234 if ( (strcmp(argv[argc-1],"?")==0) || (argc>1) )
236 cli_print(cli, "Specify the SNAP header (OUI+Type) in hexadecimal format\r");
237 cli_print(cli, "Example: 00:00:0e 08:00\r");
238 cli_print(cli, "\n");
239 return CLI_OK;
242 if (argc!=2)
244 cli_print(cli, "Two arguments required: 3-byte OUI and 2-byte EtherType\n");
245 return CLI_OK;
248 if (str2hex(argv[0], oui, 15)!=3)
250 cli_print(cli, "Three bytes required for the OUI\n");
251 return CLI_OK;
254 if (str2hex(argv[1], etp, 15)!=2)
256 cli_print(cli, "Two bytes required for the EtherType\n");
257 return CLI_OK;
261 memcpy(&clipkt->eth_snap[0], &t8, 3);
262 memcpy(&clipkt->eth_snap[3], &oui, 3);
263 memcpy(&clipkt->eth_snap[6], &etp, 2);
264 clipkt->eth_snap_s = 8;
268 return CLI_OK;