ddos/client.c
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--
Common Makefile Style NAME += OBJECT committer: Markus Bröker <mbroeker@largo.homelinux.org>

/**
 * test/demos/ddos/client.c
 * Copyright (C) 2008 Markus Broeker
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/types.h>

int main (int argc, char **argv)
{
    char message[81];
    int client_socket;
    struct sockaddr_in ca;
    socklen_t size;
    int status;

    client_socket = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
    if (client_socket == -1) {
        perror ("socket");
        return EXIT_FAILURE;
    }

    ca.sin_family = AF_INET;
    ca.sin_port = htons (4000);
    ca.sin_addr.s_addr = inet_addr ("127.0.0.1");

    size = sizeof (ca);

    status = connect (client_socket, (struct sockaddr *)&ca, size);
    status = write (client_socket, "Hello\r\n", 8);
    while (client_socket > 0) {
        status = read (client_socket, message, 80);
        if (status > 0) {
            message[status] = 0;
            printf ("SERVER RESPONS: %s", message);
        } else {
            perror ("READ");
            close (client_socket);
            return 1;
        }
    }

    return close (client_socket);
}