Added php based registration web for Tunnel6 server - especially for free hosting...
[tunnel6.git] / client / src / main.c
blob9127f6f06cea43e7a09d77bbbcfdc124d15b9da3
1 /*
2 * tunnel6
3 * Copyright (C) 2010 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include <stdlib.h>
21 #include <unistd.h>
22 #include <stdio.h>
23 #include "sig.h"
24 #include "ipv6.h"
25 #include "poll.h"
26 #include "proto.h"
27 #include "config.h"
28 #include "tunnel.h"
29 #include "tundev.h"
30 #include "defaults.h"
31 #include "heartbeat.h"
32 #ifdef __WIN32__
33 # include <windows.h>
34 #endif
36 int cont; /* Continue in tunnel processing ? 1 - yes / 0 - no */
38 int init (char *addr, unsigned short port, char *name, char *pwd)
40 if (tundev_init () == -1)
41 return -1;
43 if (tunnel_init (addr, port, name, pwd) == -1)
44 return -1;
46 if (ipv6_init () == -1)
47 return -1;
49 if (tundev_setup () == -1)
50 return -1;
52 if (heartbeat_init () == -1)
53 return -1;
55 if (poll_init () == -1)
56 return -1;
58 if (sig_init () == -1)
59 return -1;
61 cont = 1;
63 return 0;
66 int loop ()
68 /* loop until cont is non-zero */
69 for (; cont;) {
70 poll_loop (); /* check socket events */
72 heartbeat_loop (); /* send heartbeat packets in interval */
75 return 0;
78 int syntax (char *bin)
80 printf ("Syntax error\n\t%s: name password tunnel6server\n", bin);
82 return -1;
85 int main (int argc, char **argv)
87 printf ("TUNNEL6 client v%s by ZeXx86\n", DEFAULT_VERSION);
89 /* login name */
90 char *name = 0;
91 /* login password */
92 char *pwd = 0;
93 /* tunnel server address */
94 char *server = 0;
95 /* listen port */
96 unsigned short port = DEFAULT_PORT;
98 /* we've found config */
99 if (argc < 4) {
100 if (config_init () == -1) {
101 syntax (argv[0]);
103 return -1;
106 /* set config values */
107 name = config.name;
108 pwd = config.pwd;
109 server = config.server;
111 if (config.port)
112 port = config.port;
113 } else {
114 /* set values from parameters */
115 name = argv[1];
116 pwd = argv[2];
117 server = argv[3];
119 if (argc > 4)
120 port = (unsigned short) atoi (argv[4]);
123 printf ("User name: %s\n"
124 "Server: %s\n"
125 "Port: %u\n", name, server, port);
127 /* Initialize routines */
128 if (init (server, port, name, pwd) == -1)
129 return -1;
131 loop ();
133 printf ("> closing tunnel\n");
135 /* disconnect from server */
136 proto_cmd_disconnect2 ();
138 return 0;