author | Markus Bröker <mbroeker@largo.dyndns.tv> |
Fri, 19 Nov 2010 14:49:47 +0100 | |
changeset 159 | 44823a881da1 |
parent 157 | e8fbd0653fda |
child 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 <netinet/in.h> |
|
12 |
#include <arpa/inet.h> |
|
13 |
#include <sys/types.h> |
|
157
e8fbd0653fda
Simplified IPv6 aware ddos demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
14 |
#include <netdb.h> |
e8fbd0653fda
Simplified IPv6 aware ddos demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
15 |
|
e8fbd0653fda
Simplified IPv6 aware ddos demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
16 |
#define MAXLEN 80 |
e8fbd0653fda
Simplified IPv6 aware ddos demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
17 |
|
e8fbd0653fda
Simplified IPv6 aware ddos demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
18 |
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
|
19 |
{ |
e8fbd0653fda
Simplified IPv6 aware ddos demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
20 |
return write (client_socket, s, strlen (s)); |
e8fbd0653fda
Simplified IPv6 aware ddos demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
21 |
} |
0 | 22 |
|
23 |
int main (int argc, char **argv) |
|
24 |
{ |
|
157
e8fbd0653fda
Simplified IPv6 aware ddos demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
25 |
char message[MAXLEN + 1]; |
0 | 26 |
int client_socket; |
27 |
int status; |
|
28 |
||
157
e8fbd0653fda
Simplified IPv6 aware ddos demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
29 |
struct addrinfo hints, *result, *rp; |
e8fbd0653fda
Simplified IPv6 aware ddos demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
30 |
|
e8fbd0653fda
Simplified IPv6 aware ddos demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
31 |
memset (&hints, 0, sizeof (struct addrinfo)); |
e8fbd0653fda
Simplified IPv6 aware ddos demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
32 |
hints.ai_family = AF_UNSPEC; |
e8fbd0653fda
Simplified IPv6 aware ddos demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
33 |
hints.ai_socktype = SOCK_STREAM; |
e8fbd0653fda
Simplified IPv6 aware ddos demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
34 |
hints.ai_flags = 0; |
e8fbd0653fda
Simplified IPv6 aware ddos demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
35 |
hints.ai_protocol = IPPROTO_TCP; |
e8fbd0653fda
Simplified IPv6 aware ddos demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
36 |
|
e8fbd0653fda
Simplified IPv6 aware ddos demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
37 |
if (getaddrinfo ("localhost", "4000", &hints, &result) != 0) { |
e8fbd0653fda
Simplified IPv6 aware ddos demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
38 |
perror ("getaddrinfo"); |
e8fbd0653fda
Simplified IPv6 aware ddos demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
39 |
return -1; |
0 | 40 |
} |
41 |
||
157
e8fbd0653fda
Simplified IPv6 aware ddos demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
42 |
client_socket = -1; |
e8fbd0653fda
Simplified IPv6 aware ddos demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
43 |
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
|
44 |
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
|
45 |
continue; |
0 | 46 |
|
157
e8fbd0653fda
Simplified IPv6 aware ddos demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
47 |
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
|
48 |
break; |
e8fbd0653fda
Simplified IPv6 aware ddos demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
49 |
} |
e8fbd0653fda
Simplified IPv6 aware ddos demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
50 |
close (client_socket); |
e8fbd0653fda
Simplified IPv6 aware ddos demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
51 |
client_socket = -1; |
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 |
|
e8fbd0653fda
Simplified IPv6 aware ddos demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
54 |
if (result != NULL) |
e8fbd0653fda
Simplified IPv6 aware ddos demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
55 |
freeaddrinfo (result); |
e8fbd0653fda
Simplified IPv6 aware ddos demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
56 |
|
e8fbd0653fda
Simplified IPv6 aware ddos demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
57 |
status = client_write (client_socket, "Hello\r\n"); |
0 | 58 |
while (client_socket > 0) { |
157
e8fbd0653fda
Simplified IPv6 aware ddos demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
59 |
status = read (client_socket, message, MAXLEN); |
0 | 60 |
if (status > 0) { |
157
e8fbd0653fda
Simplified IPv6 aware ddos demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
61 |
message[status] = '\0'; |
0 | 62 |
printf ("SERVER RESPONS: %s", message); |
63 |
} else { |
|
64 |
perror ("READ"); |
|
65 |
close (client_socket); |
|
66 |
return 1; |
|
67 |
} |
|
68 |
} |
|
69 |
||
10
f19f44e2e863
a nice connection demo from an irc user
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
70 |
return close (client_socket); |
0 | 71 |
} |