netsniff-ng: nlmsg: Print generic netlink ctrl family info
[netsniff-ng.git] / staging / cli_launch.c
blob19b6ba01f2880d3d2533f99e02f144273c7a29c5
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"
27 int launch_bpdu (struct cli_def *cli, const char *command, char *argv[], int argc)
29 int conf=0;
30 struct mops_ext_bpdu * pd;
32 if ( (strncmp(argv[argc-1],"?",2)==0) || (argc>1) ) {
33 cli_print(cli, "Launch a(nother) BPDU process:\n");
34 cli_print(cli, "<CR> Per default a TCN-BPDU is sent.\r");
35 cli_print(cli, "conf Use this keyword to emit configuration BPDUs\r");
36 cli_print(cli, " (with this host as root bridge)\n");
37 return CLI_OK;
40 if (argc==1) {
41 if (mz_strcmp(argv[0], "conf", 1)==0) conf=1;
44 if ((clipkt = mops_alloc_packet(mp_head)) == NULL) { // Problem, memory full?
45 cli_print(cli, "Cannot allocate additional memory!\n");
46 return CLI_OK;
49 strncpy (clipkt->packet_name, "sysBPDU", 7);
50 // OK, created a new packet
51 cli_print(cli, "Allocated new packet %s at slot %i",clipkt->packet_name, clipkt->id);
52 mops_set_defaults(clipkt);
53 if (mops_ext_add_pdesc (clipkt, MOPS_BPDU))
54 cli_print(cli, "Cannot configure BPDU parameters!?\n");
55 else {
56 clipkt->use_ETHER = 1;
57 clipkt->use_SNAP = 1;
58 clipkt->count = 0;
59 clipkt->ndelay.tv_sec = 2;
60 clipkt->ndelay.tv_nsec = 0;
61 pd = clipkt->p_desc;
62 if (conf)
63 pd->bpdu_type = 0x00;
64 else
65 pd->bpdu_type = 0x80;
66 mops_set_conf(clipkt);
67 if (mops_tx_simple (clipkt)) {
68 cli_print(cli, "Cannot create sending process.\r");
72 return CLI_OK;
77 int launch_synflood (struct cli_def *cli, const char *command, char *argv[], int argc)
79 u_int8_t IP[4];
80 int valid_ip=0, valid_port=0;
82 if ( (strncmp(argv[argc-1],"?",2)==0) || (argc>2) || (argc==0)) {
83 cli_print(cli, "Launch a(nother) TCP SYN-Flood process:\n");
84 cli_print(cli, "<dst-ip-addr> At least you must specify the destination IP address\r");
85 cli_print(cli, "<dst-ip-addr> <port-nr> Optionally specify the destination port (default: range from 1-1023)\n");
86 return CLI_OK;
89 if (mops_pdesc_ip (IP, argv[0])==0) { // check if format is really an IP address
90 valid_ip=1;
91 } else {
92 cli_print(cli, "Invalid IP address\n");
93 return CLI_OK;
96 if (argc==2) {
97 if (mz_strisnum(argv[1])==0) {
98 cli_print(cli, "Invalid port number\n");
99 return CLI_OK;
101 valid_port = (int) str2int(argv[1]);
102 if (valid_port>65535) {
103 cli_print(cli, "Invalid port number\n");
104 return CLI_OK;
109 if ((clipkt = mops_alloc_packet(mp_head)) == NULL) { // Problem, memory full?
110 cli_print(cli, "Cannot allocate additional memory!\n");
111 return CLI_OK;
114 strncpy (clipkt->packet_name, "sysFlood_TCPSYN", 15);
115 // OK, created a new packet
116 cli_print(cli, "Allocated new packet %s at slot %i",clipkt->packet_name, clipkt->id);
117 mops_set_defaults(clipkt);
118 clipkt->use_ETHER = 1;
119 clipkt->use_IP = 1;
120 clipkt->use_TCP = 1;
121 clipkt->ip_proto = 6;
122 clipkt->count = 0;
123 clipkt->ip_dst = str2ip32(argv[0]);
124 clipkt->ip_src_israndom=1;
125 if (valid_port) {
126 clipkt->dp = valid_port;
127 } else {
128 clipkt->dp_isrange=1;
129 clipkt->dp_start=1;
130 clipkt->dp_stop=1023;
132 clipkt->ndelay.tv_sec = 0;
133 clipkt->ndelay.tv_nsec = 0;
134 mops_set_conf(clipkt);
135 mops_tcp_add_option (clipkt,64,0,0,0,0);
136 if (mops_tx_simple (clipkt)) {
137 cli_print(cli, "Cannot create sending process.\r");
140 return CLI_OK;