author | Markus Bröker <mbroeker@largo.dyndns.tv> |
Thu, 16 Apr 2009 12:50:28 +0200 | |
changeset 66 | 2b4f786d9073 |
parent 10 | f19f44e2e863 |
child 77 | 49e0babccb23 |
permissions | -rw-r--r-- |
0 | 1 |
/** |
9
c3fecc82ade6
standard tags for git projects
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
2 |
* test/demos/ddos/client.c |
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> |
|
14 |
||
15 |
int main (int argc, char **argv) |
|
16 |
{ |
|
17 |
char message[81]; |
|
18 |
int client_socket; |
|
19 |
struct sockaddr_in ca; |
|
20 |
socklen_t size; |
|
21 |
int status; |
|
22 |
||
23 |
client_socket = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP); |
|
24 |
if (client_socket == -1) { |
|
25 |
perror ("socket"); |
|
26 |
return EXIT_FAILURE; |
|
27 |
} |
|
28 |
||
29 |
ca.sin_family = AF_INET; |
|
30 |
ca.sin_port = htons (4000); |
|
31 |
ca.sin_addr.s_addr = inet_addr ("127.0.0.1"); |
|
32 |
||
33 |
size = sizeof (ca); |
|
34 |
||
35 |
status = connect (client_socket, (struct sockaddr *)&ca, size); |
|
36 |
status = write (client_socket, "Hello\r\n", 8); |
|
37 |
while (client_socket > 0) { |
|
38 |
status = read (client_socket, message, 80); |
|
39 |
if (status > 0) { |
|
40 |
message[status] = 0; |
|
41 |
printf ("SERVER RESPONS: %s", message); |
|
42 |
} else { |
|
43 |
perror ("READ"); |
|
44 |
close (client_socket); |
|
45 |
return 1; |
|
46 |
} |
|
47 |
} |
|
48 |
||
10
f19f44e2e863
a nice connection demo from an irc user
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
49 |
return close (client_socket); |
0 | 50 |
} |