aboutsummaryrefslogtreecommitdiff
path: root/src/vpn/gnunet-vpn.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-01-07 19:36:34 +0000
committerChristian Grothoff <christian@grothoff.org>2012-01-07 19:36:34 +0000
commit9accb73ff8df685cae8adb1d4dc5c84c4c7ea1dd (patch)
tree78dd3a7036fbf97128253d215e0fcd60416ec624 /src/vpn/gnunet-vpn.c
parent2b10e1f8373f14ffdeb40e735340fd467dee0b0d (diff)
downloadgnunet-9accb73ff8df685cae8adb1d4dc5c84c4c7ea1dd.tar.gz
gnunet-9accb73ff8df685cae8adb1d4dc5c84c4c7ea1dd.zip
-skeleton code for gnunet-vpn command
Diffstat (limited to 'src/vpn/gnunet-vpn.c')
-rw-r--r--src/vpn/gnunet-vpn.c149
1 files changed, 149 insertions, 0 deletions
diff --git a/src/vpn/gnunet-vpn.c b/src/vpn/gnunet-vpn.c
new file mode 100644
index 000000000..3be830a6a
--- /dev/null
+++ b/src/vpn/gnunet-vpn.c
@@ -0,0 +1,149 @@
1/*
2 This file is part of GNUnet.
3 (C) 2012 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 src/vpn/gnunet-vpn.c
23 * @brief Tool to manually request VPN tunnels to be created
24 * @author Christian Grothoff
25 */
26
27#include "platform.h"
28#include "gnunet_util_lib.h"
29#include "gnunet_vpn_service.h"
30
31
32/**
33 * Handle to vpn service.
34 */
35static struct GNUNET_VPN_Handle *handle;
36
37/**
38 * Opaque redirection request handle.
39 */
40static struct GNUNET_VPN_RedirectionRequest *request;
41
42/**
43 * Option -p: destination peer identity for service
44 */
45static char *peer_id;
46
47/**
48 * Option -s: service name (hash to get service descriptor)
49 */
50static char *service_name;
51
52/**
53 * Option -i: target IP
54 */
55static char *target_ip;
56
57/**
58 * Option -4: IPv4 requested.
59 */
60static int ipv4;
61
62/**
63 * Option -6: IPv6 requested.
64 */
65static int ipv6;
66
67/**
68 * Selected level of verbosity.
69 */
70static int verbosity;
71
72/**
73 * Global return value.
74 */
75static int ret;
76
77
78/**
79 * Shutdown.
80 */
81static void
82do_disconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
83{
84 if (NULL != request)
85 {
86 GNUNET_VPN_cancel_request (request);
87 request = NULL;
88 }
89 if (NULL != handle)
90 {
91 GNUNET_VPN_disconnect (handle);
92 handle = NULL;
93 }
94 GNUNET_free_non_null (peer_id);
95 GNUNET_free_non_null (service_name);
96 GNUNET_free_non_null (target_ip);
97}
98
99
100/**
101 * Main function that will be run by the scheduler.
102 *
103 * @param cls closure
104 * @param args remaining command-line arguments
105 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
106 * @param cfg configuration
107 */
108static void
109run (void *cls, char *const *args, const char *cfgfile,
110 const struct GNUNET_CONFIGURATION_Handle *cfg)
111{
112 handle = GNUNET_VPN_connect (cfg);
113
114 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
115 &do_disconnect, NULL);
116}
117
118
119int
120main (int argc, char *const *argv)
121{
122 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
123 {'4', "ipv4", NULL,
124 gettext_noop ("request that result should be an IPv4 address"),
125 0, &GNUNET_GETOPT_set_one, &ipv4},
126 {'6', "ipv6", NULL,
127 gettext_noop ("request that result should be an IPv6 address"),
128 0, &GNUNET_GETOPT_set_one, &ipv6},
129 {'i', "ip", "IP",
130 gettext_noop ("destination IP for the tunnel"),
131 1, &GNUNET_GETOPT_set_string, &target_ip},
132 {'p', "peer", "PEERID",
133 gettext_noop ("peer offering the service we would like to access"),
134 1, &GNUNET_GETOPT_set_string, &peer_id},
135 {'s', "service", "NAME",
136 gettext_noop ("name of the service we would like to access"),
137 1, &GNUNET_GETOPT_set_string, &peer_id},
138 GNUNET_GETOPT_OPTION_VERBOSE (&verbosity),
139 GNUNET_GETOPT_OPTION_END
140 };
141 return (GNUNET_OK ==
142 GNUNET_PROGRAM_run (argc, argv, "gnunet-vpn",
143 gettext_noop
144 ("Setup tunnels via VPN."), options,
145 &run, NULL)) ? ret : 1;
146}
147
148
149/* end of gnunet-vpn.c */