Added version to server
[tunnel6.git] / server / src / main.c
blob8f9a3a5aae83aef93c19d0b5efcb34e421886af0
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 <stdio.h>
22 #include "db.h"
23 #include "poll.h"
24 #include "sniff.h"
25 #include "tunnel.h"
26 #include "packet.h"
27 #include "signal.h"
28 #include "defaults.h"
29 #include "heartbeat.h"
31 int cont;
33 int init (char *dev, unsigned short port)
35 if (heartbeat_init () == -1)
36 return -1;
38 if (db_init () == -1)
39 return -1;
41 if (packet_init () == -1)
42 return -1;
44 if (tunnel_init (port) == -1)
45 return -1;
47 if (sniff_init (dev) == -1)
48 return -1;
50 if (poll_init () == -1)
51 return -1;
53 if (signal_init () == -1)
54 return -1;
56 cont = 1;
58 return 0;
61 int loop ()
63 for (; cont;) {
64 if (db_reload () == -1)
65 return -1;
67 if (poll_loop () == -1)
68 return -1;
70 if (heartbeat_loop () == -1)
71 return -1;
74 return 0;
77 int main (int argc, char **argv)
79 printf ("TUNNEL6 server v%s by ZeXx86\n", DEFAULT_VERSION);
81 /* ethernet device */
82 char *dev = DEFAULT_ETHDEV;
83 /* listen port */
84 unsigned short port = DEFAULT_PORT;
86 if (argc > 1)
87 dev = argv[1];
88 if (argc > 2)
89 port = (unsigned short) atoi (argv[2]);
91 printf ("Device: %s\n"
92 "Port: %u\n", dev, port);
94 if (init (dev, port) == -1)
95 return -1;
97 loop ();
99 printf ("> tunnel closed\n");
101 db_disconnect_all ();
103 return 0;