author | Markus Bröker<broeker.markus@googlemail.com> |
Sun, 10 Feb 2019 13:17:01 +0100 | |
changeset 173 | 374a86886bc5 |
parent 160 | 26414889dded |
permissions | -rw-r--r-- |
0 | 1 |
/** |
77 | 2 |
* ddos/client.c |
9
c3fecc82ade6
standard tags for git projects
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
3 |
* Copyright (C) 2008 Markus Broeker |
0 | 4 |
*/ |
5 |
||
6 |
#include <stdio.h> |
|
7 |
#include <stdlib.h> |
|
8 |
#include <string.h> |
|
9 |
#include <unistd.h> |
|
10 |
#include <sys/socket.h> |
|
11 |
#include <sys/types.h> |
|
157
e8fbd0653fda
Simplified IPv6 aware ddos demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
12 |
#include <netdb.h> |
160
26414889dded
removed unneeded includes and code cleanups
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
157
diff
changeset
|
13 |
#include <netinet/in.h> |
157
e8fbd0653fda
Simplified IPv6 aware ddos demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
14 |
|
e8fbd0653fda
Simplified IPv6 aware ddos demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
15 |
#define MAXLEN 80 |
e8fbd0653fda
Simplified IPv6 aware ddos demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
16 |
|
e8fbd0653fda
Simplified IPv6 aware ddos demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
17 |
int client_write (int client_socket, char *s) |
e8fbd0653fda
Simplified IPv6 aware ddos demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
18 |
{ |
e8fbd0653fda
Simplified IPv6 aware ddos demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
19 |
return write (client_socket, s, strlen (s)); |
e8fbd0653fda
Simplified IPv6 aware ddos demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
20 |
} |
0 | 21 |
|
22 |
int main (int argc, char **argv) |
|
23 |
{ |
|
157
e8fbd0653fda
Simplified IPv6 aware ddos demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
24 |
char message[MAXLEN + 1]; |
0 | 25 |
int client_socket; |
26 |
int status; |
|
27 |
||
157
e8fbd0653fda
Simplified IPv6 aware ddos demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
28 |
struct addrinfo hints, *result, *rp; |
e8fbd0653fda
Simplified IPv6 aware ddos demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
29 |
|
e8fbd0653fda
Simplified IPv6 aware ddos demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
30 |
memset (&hints, 0, sizeof (struct addrinfo)); |
e8fbd0653fda
Simplified IPv6 aware ddos demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
31 |
hints.ai_family = AF_UNSPEC; |
e8fbd0653fda
Simplified IPv6 aware ddos demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
32 |
hints.ai_socktype = SOCK_STREAM; |
e8fbd0653fda
Simplified IPv6 aware ddos demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
33 |
hints.ai_flags = 0; |
e8fbd0653fda
Simplified IPv6 aware ddos demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
34 |
hints.ai_protocol = IPPROTO_TCP; |
e8fbd0653fda
Simplified IPv6 aware ddos demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
35 |
|
e8fbd0653fda
Simplified IPv6 aware ddos demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
36 |
if (getaddrinfo ("localhost", "4000", &hints, &result) != 0) { |
e8fbd0653fda
Simplified IPv6 aware ddos demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
37 |
perror ("getaddrinfo"); |
e8fbd0653fda
Simplified IPv6 aware ddos demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
38 |
return -1; |
0 | 39 |
} |
40 |
||
157
e8fbd0653fda
Simplified IPv6 aware ddos demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
41 |
client_socket = -1; |
e8fbd0653fda
Simplified IPv6 aware ddos demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
42 |
for (rp = result; rp != NULL; rp = rp->ai_next) { |
e8fbd0653fda
Simplified IPv6 aware ddos demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
43 |
if ((client_socket = socket (rp->ai_family, rp->ai_socktype, rp->ai_protocol)) == -1) |
e8fbd0653fda
Simplified IPv6 aware ddos demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
44 |
continue; |
0 | 45 |
|
157
e8fbd0653fda
Simplified IPv6 aware ddos demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
46 |
if (connect (client_socket, rp->ai_addr, rp->ai_addrlen) != -1) { |
e8fbd0653fda
Simplified IPv6 aware ddos demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
47 |
break; |
e8fbd0653fda
Simplified IPv6 aware ddos demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
48 |
} |
e8fbd0653fda
Simplified IPv6 aware ddos demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
49 |
close (client_socket); |
e8fbd0653fda
Simplified IPv6 aware ddos demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
50 |
client_socket = -1; |
e8fbd0653fda
Simplified IPv6 aware ddos demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
51 |
} |
e8fbd0653fda
Simplified IPv6 aware ddos demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
52 |
|
e8fbd0653fda
Simplified IPv6 aware ddos demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
53 |
if (result != NULL) |
e8fbd0653fda
Simplified IPv6 aware ddos demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
54 |
freeaddrinfo (result); |
e8fbd0653fda
Simplified IPv6 aware ddos demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
55 |
|
e8fbd0653fda
Simplified IPv6 aware ddos demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
56 |
status = client_write (client_socket, "Hello\r\n"); |
0 | 57 |
while (client_socket > 0) { |
157
e8fbd0653fda
Simplified IPv6 aware ddos demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
58 |
status = read (client_socket, message, MAXLEN); |
0 | 59 |
if (status > 0) { |
157
e8fbd0653fda
Simplified IPv6 aware ddos demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
60 |
message[status] = '\0'; |
0 | 61 |
printf ("SERVER RESPONS: %s", message); |
62 |
} else { |
|
63 |
perror ("READ"); |
|
64 |
close (client_socket); |
|
65 |
return 1; |
|
66 |
} |
|
67 |
} |
|
68 |
||
10
f19f44e2e863
a nice connection demo from an irc user
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
69 |
return close (client_socket); |
0 | 70 |
} |