ddos/client.c
changeset 0 af501b0c1716
child 9 c3fecc82ade6
equal deleted inserted replaced
-1:000000000000 0:af501b0c1716
       
     1 /**
       
     2  *     $Id: client.c,v 1.1.1.1 2008-04-28 17:32:53 mbroeker Exp $
       
     3  * $Source: /development/c/demos/ddos/client.c,v $
       
     4  *
       
     5  */
       
     6 
       
     7 #include <stdio.h>
       
     8 #include <stdlib.h>
       
     9 #include <string.h>
       
    10 #include <unistd.h>
       
    11 #include <sys/socket.h>
       
    12 #include <netinet/in.h>
       
    13 #include <arpa/inet.h>
       
    14 #include <sys/types.h>
       
    15 
       
    16 int main (int argc, char **argv)
       
    17 {
       
    18     char message[81];
       
    19     int client_socket;
       
    20     struct sockaddr_in ca;
       
    21     socklen_t size;
       
    22     int status;
       
    23 
       
    24     client_socket = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
       
    25     if (client_socket == -1) {
       
    26         perror ("socket");
       
    27         return EXIT_FAILURE;
       
    28     }
       
    29 
       
    30     ca.sin_family = AF_INET;
       
    31     ca.sin_port = htons (4000);
       
    32     ca.sin_addr.s_addr = inet_addr ("127.0.0.1");
       
    33 
       
    34     size = sizeof (ca);
       
    35 
       
    36     status = connect (client_socket, (struct sockaddr *)&ca, size);
       
    37     status = write (client_socket, "Hello\r\n", 8);
       
    38     while (client_socket > 0) {
       
    39         status = read (client_socket, message, 80);
       
    40         if (status > 0) {
       
    41             message[status] = 0;
       
    42             printf ("SERVER RESPONS: %s", message);
       
    43         } else {
       
    44             perror ("READ");
       
    45             close (client_socket);
       
    46             return 1;
       
    47         }
       
    48     }
       
    49 
       
    50     close (client_socket);
       
    51     return 0;
       
    52 }