aboutsummaryrefslogtreecommitdiff
path: root/src/examples/tor_dos_server.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/examples/tor_dos_server.c')
-rw-r--r--src/examples/tor_dos_server.c109
1 files changed, 0 insertions, 109 deletions
diff --git a/src/examples/tor_dos_server.c b/src/examples/tor_dos_server.c
deleted file mode 100644
index dba98c41..00000000
--- a/src/examples/tor_dos_server.c
+++ /dev/null
@@ -1,109 +0,0 @@
1/*
2 This file is part of libmicrohttpd
3 (C) 2007 Christian Grothoff
4
5 libmicrohttpd is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 2, or (at your
8 option) any later version.
9
10 libmicrohttpd is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with libmicrohttpd; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/**
22 * @file tor_dos_server.c
23 * @brief serve up random data forever
24 * @author Meh
25 */
26
27#include "config.h"
28#include <microhttpd.h>
29#include <stdlib.h>
30#include <sys/types.h>
31#include <sys/stat.h>
32#ifndef MINGW
33#include <unistd.h>
34#endif
35#include <string.h>
36#include <stdio.h>
37#include <sys/time.h>
38
39#define PAGE "<html><head><title>File not found</title></head><body>File not found</body></html>"
40
41static int
42random_data_feeder (void *cls, size_t pos, char *buf, int max)
43{
44
45 memset(buf,'d',max);
46
47 return 1;
48}
49
50static int
51ahc_echo (void *cls,
52 struct MHD_Connection *connection,
53 const char *url,
54 const char *method,
55 const char *upload_data,
56 const char *version, unsigned int *upload_data_size, void **ptr)
57{
58 static int aptr;
59 struct MHD_Response *response;
60 int ret;
61 struct stat buf;
62
63 fprintf(stderr,"received request!\n");
64 if (0 != strcmp (method, MHD_HTTP_METHOD_GET))
65 {
66 fprintf(stderr,"Unknown method! %s\n",method);
67 return MHD_NO; /* unexpected method */
68 }
69 if (&aptr != *ptr)
70 {
71 /* do never respond on first call */
72 *ptr = &aptr;
73 return MHD_YES;
74 }
75
76 response = MHD_create_response_from_callback (-1, 32 * 1024, /* 32k page size */
77 &random_data_feeder,
78 NULL,
79 (MHD_ContentReaderFreeCallback)
80 & fclose);
81 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
82 MHD_destroy_response (response);
83
84
85 return ret;
86}
87
88int
89main (int argc, char *const *argv)
90{
91 struct MHD_Daemon *d;
92
93 if (argc != 3)
94 {
95 printf ("%s PORT SECONDS-TO-RUN\n", argv[0]);
96 return 1;
97 }
98 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_DEBUG,
99 atoi (argv[1]),
100 NULL, NULL, &ahc_echo, PAGE, MHD_OPTION_CONNECTION_MEMORY_LIMIT, 1024 * 1024 * 10, MHD_OPTION_END);
101 if (d == NULL)
102 return 1;
103
104 sleep(atoi(argv[2]));
105
106
107 MHD_stop_daemon (d);
108 return 0;
109}