Browse code

- created udp_flood_disc (same as udp_flood but uses unconnected sockets)

Andrei Pelinescu-Onciul authored on 01/03/2002 15:49:53
Showing 4 changed files
... ...
@@ -149,6 +149,7 @@ int main (int argc, char** argv)
149 149
 	address=0;
150 150
 
151 151
 
152
+
152 153
 	opterr=0;
153 154
 	while ((c=getopt(argc,argv, "c:vhV"))!=-1){
154 155
 		switch(c){
... ...
@@ -187,6 +188,7 @@ int main (int argc, char** argv)
187 187
 					abort();
188 188
 		}
189 189
 	}
190
+
190 191
 	
191 192
 	/* check if all the required params are present */
192 193
 	if(count==0){
... ...
@@ -197,6 +199,7 @@ int main (int argc, char** argv)
197 197
 		exit(-1);
198 198
 	}
199 199
 
200
+
200 201
 #ifdef SYSV_SEM
201 202
 	/*init*/
202 203
 	puts("Initializing SYS V semaphores\n");
... ...
@@ -8,19 +8,19 @@
8 8
 debug=3          # debug level (cmd line: -dddddddddd)
9 9
 #fork=yes          # (cmd. line: -D)
10 10
 fork=yes
11
-fork=no
11
+#fork=no
12 12
 log_stderror=yes # (cmd line: -E)
13 13
 #log_stderror=no	# (cmd line: -E)
14 14
 
15 15
 
16
-children=2
16
+children=1
17 17
 check_via=no     # (cmd. line: -v)
18 18
 dns=off           # (cmd. line: -r)
19 19
 rev_dns=off      # (cmd. line: -R)
20 20
 #port=5070
21
-#listen=10.0.0.179
21
+listen=10.0.0.179
22 22
 #listen=127.0.0.1
23
-listen=192.168.57.33
23
+#listen=192.168.57.33
24 24
 loop_checks=0
25 25
 # for more info: sip_router -h
26 26
 
... ...
@@ -15,14 +15,14 @@ log_stderror=yes # (cmd line: -E)
15 15
 #log_stderror=no	# (cmd line: -E)
16 16
 
17 17
 
18
-children=2
18
+children=4
19 19
 check_via=no     # (cmd. line: -v)
20 20
 dns=on           # (cmd. line: -r)
21 21
 rev_dns=yes      # (cmd. line: -R)
22 22
 #port=5070
23 23
 #listen=127.0.0.1
24
-listen=192.168.57.33
25
-#listen=10.0.0.179
24
+#listen=192.168.57.33
25
+listen=10.0.0.179
26 26
 loop_checks=0
27 27
 # for more info: sip_router -h
28 28
 
29 29
new file mode 100644
... ...
@@ -0,0 +1,192 @@
0
+/* $Id$ */
1
+
2
+
3
+#include <stdio.h>
4
+#include <stdlib.h>
5
+#include <errno.h>
6
+#include <string.h>
7
+#include <ctype.h>
8
+#include <netdb.h>
9
+#include <unistd.h>
10
+#include <sys/types.h>
11
+#include <fcntl.h>
12
+#include <sys/socket.h>
13
+#include <netinet/in.h>
14
+#include <arpa/inet.h>
15
+
16
+
17
+static char *id="$Id$";
18
+static char *version="udp_flood_disc 0.1";
19
+static char* help_msg="\
20
+Usage: udp_flood -f file -d address -p port -c count [-v]\n\
21
+Options:\n\
22
+    -f file       file with the content of the udp packet (max 65k)\n\
23
+    -d address    destination address\n\
24
+    -p port       destination port\n\
25
+    -c count      number of packets to be sent\n\
26
+    -v            increase verbosity level\n\
27
+    -V            version number\n\
28
+    -h            this help message\n\
29
+";
30
+
31
+#define BUF_SIZE 65535
32
+
33
+
34
+int main (int argc, char** argv)
35
+{
36
+	int fd;
37
+	int sock;
38
+	char c;
39
+	int n,r;
40
+	char* tmp;
41
+	char* buf[BUF_SIZE];
42
+	struct hostent* he;
43
+	struct sockaddr_in addr;
44
+	
45
+	int count;
46
+	int verbose;
47
+	char *fname;
48
+	char *dst;
49
+	int port;
50
+	
51
+	/* init */
52
+	count=0;
53
+	verbose=0;
54
+	fname=0;
55
+	dst=0;
56
+	port=0;
57
+
58
+	opterr=0;
59
+	while ((c=getopt(argc,argv, "f:c:d:p:vhV"))!=-1){
60
+		switch(c){
61
+			case 'f':
62
+				fname=optarg;
63
+				break;
64
+			case 'v':
65
+				verbose++;
66
+				break;
67
+			case 'd':
68
+				dst=optarg;
69
+				break;
70
+			case 'p':
71
+				port=strtol(optarg, &tmp, 10);
72
+				if ((tmp==0)||(*tmp)){
73
+					fprintf(stderr, "bad port number: -p %s\n", optarg);
74
+					goto error;
75
+				}
76
+				break;
77
+			case 'c':
78
+				count=strtol(optarg, &tmp, 10);
79
+				if ((tmp==0)||(*tmp)){
80
+					fprintf(stderr, "bad count: -c %s\n", optarg);
81
+					goto error;
82
+				}
83
+				break;
84
+			case 'V':
85
+				printf("version: %s\n", version);
86
+				printf("%s\n",id);
87
+				exit(0);
88
+				break;
89
+			case 'h':
90
+				printf("version: %s\n", version);
91
+				printf("%s", help_msg);
92
+				exit(0);
93
+				break;
94
+			case '?':
95
+				if (isprint(optopt))
96
+					fprintf(stderr, "Unknown option `-%c�\n", optopt);
97
+				else
98
+					fprintf(stderr, "Unknown character `\\x%x�\n", optopt);
99
+				goto error;
100
+			case ':':
101
+				fprintf(stderr, "Option `-%c� requires an argument.\n",
102
+						optopt);
103
+				goto error;
104
+				break;
105
+			default:
106
+					abort();
107
+		}
108
+	}
109
+	
110
+	/* check if all the required params are present */
111
+	if (fname==0){
112
+		fprintf(stderr, "Missing -f file\n");
113
+		exit(-1);
114
+	}
115
+	if (dst==0){
116
+		fprintf(stderr, "Missing destination (-d ...)\n");
117
+		exit(-1);
118
+	}
119
+	if(port==0){
120
+		fprintf(stderr, "Missing port number (-p port)\n");
121
+		exit(-1);
122
+	}else if(port<0){
123
+		fprintf(stderr, "Invalid port number (-p %d)\n", port);
124
+		exit(-1);
125
+	}
126
+	if(count==0){
127
+		fprintf(stderr, "Missing packet count (-c number)\n");
128
+		exit(-1);
129
+	}else if(count<0){
130
+		fprintf(stderr, "Invalid packet count (-c %d)\n", count);
131
+		exit(-1);
132
+	}
133
+	
134
+	/* open packet file */
135
+	fd=open(fname, O_RDONLY);
136
+	if (fd<0){
137
+		fprintf(stderr, "ERROR: loading packet-file(%s): %s\n", fname,
138
+				strerror(errno));
139
+		goto error;
140
+	}
141
+	n=read(fd, buf, BUF_SIZE);
142
+	if (n<0){
143
+		fprintf(stderr, "ERROR: reading file(%s): %s\n", fname,
144
+				strerror(errno));
145
+		goto error;
146
+	}
147
+	if (verbose) printf("read %d bytes from file %s\n", n, fname);
148
+	close(fd);
149
+
150
+	/* resolve destination */
151
+	he=gethostbyname(dst);
152
+	if (he==0){
153
+		fprintf(stderr, "ERROR: could not resolve %s\n", dst);
154
+		goto error;
155
+	}
156
+	/* open socket*/
157
+	addr.sin_family=he->h_addrtype;
158
+	addr.sin_port=htons(port);
159
+	memcpy(&addr.sin_addr.s_addr, he->h_addr_list[0], he->h_length);
160
+	
161
+	sock = socket(he->h_addrtype, SOCK_DGRAM, 0);
162
+	if (sock==-1){
163
+		fprintf(stderr, "ERROR: socket: %s\n", strerror(errno));
164
+		goto error;
165
+	}
166
+/*
167
+	if (connect(sock, (struct sockaddr*) &addr, sizeof(struct sockaddr))!=0){
168
+		fprintf(stderr, "ERROR: connect: %s\n", strerror(errno));
169
+		goto error;
170
+	}
171
+*/
172
+
173
+
174
+	/* flood loop */
175
+	for (r=0; r<count; r++){
176
+		if ((verbose>1)&&(r%1000))  putchar('.');
177
+		if (sendto(sock,buf, n, 0, (struct sockaddr*) &addr, sizeof(addr))==-1)
178
+		{
179
+			fprintf(stderr, "Error: send: %s\n",  strerror(errno));
180
+			exit(1);
181
+		}
182
+	}
183
+	printf("\n%d packets sent, %d bytes each => total %d bytes\n",
184
+			count, n, n*count);
185
+
186
+	close(sock);
187
+	exit(0);
188
+
189
+error:
190
+	exit(-1);
191
+}