dev: mark paths likely/unlikely
[netsniff-ng.git] / staging / cli_legacy.c
blob2adc5351a1f675006009ea6c88641ec4d7903077
1 /*
2 * Mausezahn - A fast versatile traffic generator
3 * Copyright (C) 2008 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"
25 int transmit (struct cli_def *cli, const char *command, char *argv[], int argc)
27 int i;
28 char argstr[10000];
30 argstr[0]='\0';
32 if (argc>1)
34 for (i=1; i<argc; i++)
36 if ((strlen(argv[i])+strlen(argstr))>10000)
38 cli_print(cli, "Argument list too long!\n");
39 return CLI_OK;
41 if (strncmp(argv[i], "?", 1)==0)
43 strcat(argstr, ",help");
45 else
46 strncat(argstr, argv[i], 5000); // TODO: This is ugly!
48 // TEST: cli_print(cli, "argc=%i, got '%s'\n", argc, argstr);
52 if (argv[0] == NULL) // raw hex string given
54 mode = BYTE_STREAM;
56 else if (strcmp(argv[0],"arp")==0)
58 mode = ARP;
60 else if (strcmp(argv[0],"bpdu")==0)
62 mode = BPDU;
64 else if (strcmp(argv[0],"ip")==0)
66 mode = IP;
68 else if (strcmp(argv[0],"udp")==0)
70 mode = UDP;
72 else if (strcmp(argv[0],"icmp")==0)
74 mode = ICMP;
76 else if (strcmp(argv[0],"tcp")==0)
78 mode = TCP;
80 else if (strcmp(argv[0],"dns")==0)
82 mode = DNS;
84 else if (strcmp(argv[0],"cdp")==0)
86 mode = CDP;
88 else if (strcmp(argv[0],"syslog")==0)
90 mode = SYSLOG;
92 else if (strcmp(argv[0],"lldp")==0)
94 mode = LLDP;
95 tx.packet_mode=0; // create whole frame by ourself
97 else if (strcmp(argv[0],"rtp")==0)
99 mode = RTP;
101 else if (strcmp(argv[0],"raw")==0)
103 strncpy(tx.arg_string, argstr, MAX_PAYLOAD_SIZE);
104 send_eth();
106 else if (strcmp(argv[0],"?")==0)
108 cli_print(cli,
109 "| The following packet types are currently implemented:\n"
110 "|\n"
111 "| arp ... sends ARP packets\n"
112 "| bpdu ... sends BPDU packets (STP)\n"
113 "| cdp ... sends CDP messages\n"
114 "| ip ... sends IPv4 packets\n"
115 "| udp ... sends UDP datagrams\n"
116 "| tcp ... sends TCP segments\n"
117 "| icmp ... sends ICMP messages\n"
118 "| dns ... sends DNS messages\n"
119 "| rtp ... sends RTP datagrams\n"
120 "| syslog ... sends Syslog messages\n"
121 "| lldp ... sends LLDP datagrams\n"
122 "|\n"
123 "| raw ... raw layer 2 mode (specify whole frame in hex)\n"
124 "\n"
126 return CLI_OK;
128 else
130 cli_print(cli, "Unknown packet type '%s'\r", argv[0]);
134 if (mode)
136 strncpy(tx.arg_string, argstr, MAX_PAYLOAD_SIZE);
137 tx_switch(cli);
140 return CLI_OK;