2 tincd.c -- the main file for tincd
4 Copyright (C) 2000-2004 Guus Sliepen <guus@tinc-vpn.org>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 #include "logger/logger.h"
29 #include "support/avl.h"
30 #include "support/sockaddr.h"
31 #include "support/xalloc.h"
35 static bool vnd_recv(struct vnd *vnd, char *buf, int len) {
38 logger(LOG_DEBUG, _("Read packet of %d bytes from vnd %p"), len, vnd);
39 memcpy(b, buf + 16, 4);
40 memcpy(buf + 16, buf + 20, 4);
41 memcpy(buf + 20, b, 4);
42 vnd->send(vnd, buf, len);
46 static bool vnd_stop(event_t *event) {
49 logger(LOG_DEBUG, "i = %d", i++);
56 event_update(event, event->interval);
60 int test(int argc, char **argv) {
63 tnl_listen_t *listener;
66 if(fd_init() && tnl_init()) {
68 vnd_set(vnd, "/dev/tun", "test", VND_MODE_TUN, vnd_recv);
71 event_set(stop, (struct timeval){5, 0}, vnd_stop, NULL);
75 listener->type = SOCK_STREAM;
76 listener->protocol = IPPROTO_TCP;
77 sa(&listener->local.address)->sa_family = AF_INET;
79 if(tnl_listen(listener) && vnd_open(vnd)) {
82 listener->close(listener);
93 avl_tree_t *tinc_cfg = NULL;
94 char *tinc_netname = NULL;
96 int main(int argc, char **argv) {
97 tnl_listen_t *listener;
99 logger_init("tinc", LOGGER_MODE_STDERR);
101 tinc_cfg = cfg_tree_new();
103 if(!cfg_read_file(tinc_cfg, "tinc.conf"))
106 if(fd_init() && tnl_init()) {
107 clear(new(listener));
108 listener->type = SOCK_STREAM;
109 listener->protocol = IPPROTO_TCP;
110 sa(&listener->local.address)->sa_family = AF_INET;
111 ((struct sockaddr_in *) &listener->local.address)->sin_port = htons(655);
112 if(tnl_listen(listener)) {
114 listener->close(listener);
116 tnl_exit() && fd_exit();