aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPhilipp Tölke <toelke@in.tum.de>2010-08-23 11:03:10 +0000
committerPhilipp Tölke <toelke@in.tum.de>2010-08-23 11:03:10 +0000
commit30308a96fff9ed1509d2dbd6fbd830ba42c475ef (patch)
tree89fca879bef9712dde6297cd8e9dc2762a452b2d /src
parent24de0a5f01cf9bb4ba061cf25c24309eeef1b3b6 (diff)
downloadgnunet-30308a96fff9ed1509d2dbd6fbd830ba42c475ef.tar.gz
gnunet-30308a96fff9ed1509d2dbd6fbd830ba42c475ef.zip
The beginning of the DNS-Service. Does not work for the moment, because
GNUNET_SERVICE_run does not give me my cls...
Diffstat (limited to 'src')
-rw-r--r--src/vpn/Makefile.am9
-rw-r--r--src/vpn/gnunet-service-dns.c129
2 files changed, 137 insertions, 1 deletions
diff --git a/src/vpn/Makefile.am b/src/vpn/Makefile.am
index 77e49e098..370528772 100644
--- a/src/vpn/Makefile.am
+++ b/src/vpn/Makefile.am
@@ -22,7 +22,7 @@ endif
22 22
23 23
24bin_PROGRAMS = \ 24bin_PROGRAMS = \
25 gnunet-daemon-vpn $(VPNBIN) $(HIJACKBIN) 25 gnunet-daemon-vpn gnunet-service-dns $(VPNBIN) $(HIJACKBIN)
26 26
27 27
28gnunet_helper_vpn_SOURCES = \ 28gnunet_helper_vpn_SOURCES = \
@@ -41,6 +41,13 @@ gnunet_daemon_vpn_LDADD = \
41 $(top_builddir)/src/util/libgnunetutil.la \ 41 $(top_builddir)/src/util/libgnunetutil.la \
42 $(GN_LIBINTL) 42 $(GN_LIBINTL)
43 43
44gnunet_service_dns_SOURCES = \
45 gnunet-service-dns.c
46gnunet_service_dns_LDADD = \
47 $(top_builddir)/src/core/libgnunetcore.la \
48 $(top_builddir)/src/statistics/libgnunetstatistics.la \
49 $(top_builddir)/src/util/libgnunetutil.la \
50 $(GN_LIBINTL)
44 51
45#check_PROGRAMS = \ 52#check_PROGRAMS = \
46# test_XXX 53# test_XXX
diff --git a/src/vpn/gnunet-service-dns.c b/src/vpn/gnunet-service-dns.c
new file mode 100644
index 000000000..c96aaca8d
--- /dev/null
+++ b/src/vpn/gnunet-service-dns.c
@@ -0,0 +1,129 @@
1/*
2 This file is part of GNUnet.
3 (C) 2009 Christian Grothoff (and other contributing authors)
4
5 GNUnet 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 3, or (at your
8 option) any later version.
9
10 GNUnet 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 GNUnet; 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 vpn/gnunet-service-dns.c
23 * @author Philipp Tölke
24 */
25#include "platform.h"
26#include "gnunet_getopt_lib.h"
27#include "gnunet_service_lib.h"
28#include "gnunet_network_lib.h"
29#include "gnunet_os_lib.h"
30
31struct dns_cls {
32 struct GNUNET_SCHEDULER_Handle *sched;
33
34 struct GNUNET_NETWORK_Handle *dnsout;
35
36 unsigned short dnsoutport;
37};
38
39void hijack(unsigned short port) {
40 char* port_s = "12345";
41
42 snprintf(port_s, 6, "%d", port);
43 GNUNET_OS_start_process(NULL, NULL, "gnunet-helper-hijack-dns", "gnunet-hijack-dns", port_s, NULL);
44}
45
46void unhijack(unsigned short port) {
47 char* port_s = "12345";
48
49 snprintf(port_s, 6, "%d", port);
50 GNUNET_OS_start_process(NULL, NULL, "gnunet-helper-hijack-dns", "gnunet-hijack-dns", "-d", port_s, NULL);
51}
52
53/**
54 * Task run during shutdown.
55 *
56 * @param cls unused
57 * @param tc unused
58 */
59static void
60cleanup_task (void *cls,
61 const struct GNUNET_SCHEDULER_TaskContext *tc)
62{
63 unhijack(((struct dns_cls*)cls)->dnsoutport);
64}
65
66/**
67 * @param cls closure
68 * @param sched scheduler to use
69 * @param server the initialized server
70 * @param cfg configuration to use
71 */
72static void
73run (void *cls,
74 struct GNUNET_SCHEDULER_Handle *sched,
75 struct GNUNET_SERVER_Handle *server,
76 const struct GNUNET_CONFIGURATION_Handle *cfg)
77{
78 static const struct GNUNET_SERVER_MessageHandler handlers[] = {
79 {NULL, NULL, 0, 0}
80 };
81
82 fprintf(stderr, "%x\n", cls);
83
84 struct dns_cls* mycls = (struct dns_cls*)cls;
85
86 mycls->sched = sched;
87
88 mycls->dnsout = GNUNET_NETWORK_socket_create (AF_INET, SOCK_DGRAM, 0);
89
90 struct sockaddr_in * addr = alloca(sizeof(struct sockaddr_in));
91 memset(addr, 0, sizeof(struct sockaddr_in));
92
93 int err = GNUNET_NETWORK_socket_bind (mycls->dnsout, addr, sizeof(struct sockaddr_in));
94 err = getsockname(GNUNET_NETWORK_get_fd(mycls->dnsout), addr, (unsigned int[]){sizeof(struct sockaddr_in)});
95
96 mycls->dnsoutport = htons(addr->sin_port);
97
98 hijack(htons(addr->sin_port));
99
100 GNUNET_SERVER_add_handlers (server, handlers);
101 GNUNET_SCHEDULER_add_delayed (sched,
102 GNUNET_TIME_UNIT_FOREVER_REL,
103 &cleanup_task,
104 NULL);
105}
106
107/**
108 * The main function for the dns service.
109 *
110 * @param argc number of arguments from the command line
111 * @param argv command line arguments
112 * @return 0 ok, 1 on error
113 */
114int
115main (int argc, char *const *argv)
116{
117 struct dns_cls* cls = GNUNET_malloc(sizeof(struct dns_cls));
118
119 fprintf(stderr, "%x\n", cls);
120
121 return (GNUNET_OK ==
122 GNUNET_SERVICE_run (argc,
123 argv,
124 "gnunet-service-dns",
125 GNUNET_SERVICE_OPTION_NONE,
126 &run, cls)) ? 0 : 1;
127
128 GNUNET_free(cls); // Make clang happy
129}