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/>.
34 #include "heartbeat.h"
40 if (heartbeat_init () == -1)
46 if (packet_init () == -1)
49 if (tunnel_init (config
.port
) == -1)
52 if (sniff_init (config
.interface
, config
.ipv6
) == -1)
55 if (poll_init () == -1)
58 if (signal_init () == -1)
69 if (db_reload () == -1)
72 if (poll_loop () == -1)
75 if (heartbeat_loop () == -1)
84 printf ("TUNNEL6 server\nUsage:\n"
87 "\t-d : start as daemon\n"
88 "\t-f pidfile : specify pid file\n"
89 "\t-p port : specify listening port\n"
90 "\t-i interface : specify interface\n"
91 "\t-l stdout : remap stdout to specified file\n"
92 "\t-a ipv6 : specify listening address\n"
93 "\t-A name password ipv6 [routedprefix/len] : add DB record\n"
94 "\t-U name p;i;r value : update DB record\n"
95 "\t-G name : show DB record\n");
98 void parseargs (int argc
, char **argv
)
102 while ((opt
= getopt (argc
, argv
, "hvdp:f:i:l:a:A:U:G:")) > 0) {
109 printf ("TUNNEL6 server - version " DEFAULT_VERSION
"\n");
115 config
.port
= (unsigned short) atoi (optarg
);
118 config
.pidfile
= strdup (optarg
);
121 config
.interface
= strdup (optarg
);
124 stdout
= fopen (optarg
, "a+");
127 perror ("> ERROR -> Log file");
133 config
.ipv6
= strdup (optarg
);
136 exit (admin_db_add (argc
, argv
));
138 exit (admin_db_update (argc
, argv
));
140 exit (admin_db_get (argc
, argv
));
145 int main (int argc
, char **argv
)
147 /* not an daemon by default */
149 /* set default pid file */
150 config
.pidfile
= DEFAULT_PIDFILE
;
151 /* network interface */
152 config
.interface
= DEFAULT_ETHDEV
;
154 config
.port
= DEFAULT_PORT
;
155 /* set automatic ipv6 selection */
157 /* set default backend */
162 parseargs (argc
, argv
);
164 /* unbuffer stdout */
165 setvbuf (stdout
, (char *) NULL
, _IOLBF
, 0);
167 printf ("TUNNEL6 server v%s by ZeXx86\n", DEFAULT_VERSION
);
170 daemonize (config
.pidfile
);
172 printf ("Device: %s\n"
173 "Port: %u\n", config
.interface
, config
.port
);
180 printf ("> tunnel closed\n");
182 db_disconnect_all ();