netsniff-ng: nlmsg: Drop dissection of GENL_ID_GENERATE type
[netsniff-ng.git] / staging / tx_switch.c
blobb1a0d55c88331742bb16e9f69354a1277e90633c
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"
24 int tx_switch(struct cli_def *cli)
27 // These handles are only used when creating L3 and above packets.
28 libnet_t *l; // the context
29 libnet_ptag_t t2=0, t3=0, t4=0; // handles to layers
31 double cpu_time_used;
33 switch (mode)
35 case BYTE_STREAM:
36 send_eth();
37 break;
39 case ARP:
40 if (send_arp()==-1) return 0;
41 break;
43 case BPDU:
44 if (send_bpdu()==-1) return 0;
45 break;
47 case CDP:
48 if (send_cdp()==-1) return 0;
49 break;
51 case IP: // From now on a new much more modular method is used:
52 l = get_link_context();
53 t3 = create_ip_packet(l); // t3 can be used for later header changes
54 if (!quiet) complexity();
55 if (tx.packet_mode==0) // Ethernet manipulation features does NOT use ARP to determine eth_dst
56 t2 = create_eth_frame(l, t3, t4); // t2 can be used for later header changes
57 else
58 send_frame (l, t3, t4); // NOTE: send_frame also destroys context finaly
59 break;
61 case ICMP:
62 tx.ip_proto = 1;
63 l = get_link_context();
64 t4 = create_icmp_packet(l); // t4 can be used for later header changes
65 if (t4==-1) return 0;
66 t3 = create_ip_packet(l); // t3 can be used for later header changes
67 if (!quiet) complexity();
68 if (tx.packet_mode==0) // Ethernet manipulation features does NOT use ARP to determine eth_dst
69 t2 = create_eth_frame(l, t3, t4); // t2 can be used for later header changes
70 else
71 send_frame (l, t3, t4); // NOTE: send_frame also destroys context finaly
72 break;
74 case UDP:
75 tx.ip_proto = 17;
76 l = get_link_context();
77 t4 = create_udp_packet(l); // t4 can be used for later header changes
78 if (t4==-1) return 0;
79 t3 = create_ip_packet(l); // t3 can be used for later header changes
80 if (!quiet) complexity();
81 if (tx.packet_mode==0) // Ethernet manipulation features does NOT use ARP to determine eth_dst
82 t2 = create_eth_frame(l, t3, t4); // t2 can be used for later header changes
83 else
84 send_frame (l, t3, t4); // NOTE: send_frame also destroys context finaly
85 break;
87 case TCP:
88 tx.ip_proto = 6;
89 l = get_link_context();
90 t4 = create_tcp_packet(l); // t4 can be used for later header changes
91 if (t4==-1) return 0;
92 t3 = create_ip_packet(l); // t3 can be used for later header changes
93 if (!quiet) complexity();
94 if (tx.packet_mode==0) // Ethernet manipulation features does NOT use ARP to determine eth_dst
95 t2 = create_eth_frame(l, t3, t4); // t2 can be used for later header changes
96 else
97 send_frame (l, t3, t4); // NOTE: send_frame also destroys context finaly
98 break;
100 case DNS:
101 tx.ip_proto = 17;
102 l = get_link_context();
103 if (create_dns_packet()==-1) return 0;
104 t4 = create_udp_packet(l); // t4 can be used for later header changes
105 t3 = create_ip_packet(l); // t3 can be used for later header changes
106 if (!quiet) complexity();
107 if (tx.packet_mode==0) // Ethernet manipulation features does NOT use ARP to determine eth_dst
108 t2 = create_eth_frame(l, t3, t4); // t2 can be used for later header changes
109 else
110 send_frame (l, t3, t4); // NOTE: send_frame also destroys context finaly
111 break;
113 case RTP:
114 tx.ip_proto = 17;
115 l = get_link_context();
116 if (create_rtp_packet()==-1) return 0;
117 cli_print(cli, "RTP mode! (count=%u, delay=%u usec)\n", tx.count, tx.delay);
118 t4 = create_udp_packet(l); // t4 can be used for later header changes
119 t3 = create_ip_packet(l); // t3 can be used for later header changes
120 if (!quiet) complexity();
121 if (tx.packet_mode==0) // Ethernet manipulation features does NOT use ARP to determine eth_dst
122 t2 = create_eth_frame(l, t3, t4); // t2 can be used for later header changes
123 else
124 send_frame (l, t3, t4); // NOTE: send_frame also destroys context finaly
125 break;
127 case RX_RTP: // Receive RTP packets
128 rcv_rtp_init();
129 rcv_rtp();
130 break;
132 case SYSLOG:
133 tx.ip_proto = 17;
134 l = get_link_context();
135 if (create_syslog_packet()==-1) return 0;
136 t4 = create_udp_packet(l); // t4 can be used for later header changes
137 t3 = create_ip_packet(l); // t3 can be used for later header changes
138 if (!quiet) complexity();
140 if (tx.packet_mode==0) // Ethernet manipulation features does NOT use ARP to determine eth_dst
141 t2 = create_eth_frame(l, t3, t4); // t2 can be used for later header changes
142 else
143 send_frame (l, t3, t4); // NOTE: send_frame also destroys context finaly
144 break;
146 case LLDP: // start with a new concept here
147 //l = get_link_context();
148 //(void) create_lldp_packet();
149 // // // printf("SIZE=%lu\n",sizeof(struct tx_struct));
150 break;
153 default:
154 cli_print(cli,"Unknown mode!\n");
155 return (1);
159 // ***** Re-init packet functions: *****
160 tx.ip_payload_s = 0;
161 tx.udp_len = 0;
162 tx.tcp_payload_s = 0;
163 tx.icmp_payload_s = 0;
164 tx.cdp_sum = 0;
165 mode = 0;
166 // **************************************
169 mz_stop = clock();
170 cpu_time_used = ((double) (mz_stop - mz_start)) / CLOCKS_PER_SEC;
171 if (cpu_time_used > 0)
173 total_d /= cpu_time_used;
174 cli_print(cli, "%.2f seconds (%.Lf packets per second)\n",cpu_time_used,total_d);
177 return 0;