1 : /*
2 : * init.c
3 : * $Id: init.c 1831 2006-12-12 17:06:40Z remi $
4 : */
5 :
6 : /***********************************************************************
7 : * Copyright © 2005-2006 Rémi Denis-Courmont. *
8 : * This program is free software; you can redistribute and/or modify *
9 : * it under the terms of the GNU General Public License as published *
10 : * by the Free Software Foundation; version 2 of the license. *
11 : * *
12 : * This program is distributed in the hope that it will be useful, *
13 : * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
15 : * See the GNU General Public License for more details. *
16 : * *
17 : * You should have received a copy of the GNU General Public License *
18 : * along with this program; if not, you can get it from: *
19 : * http://www.gnu.org/copyleft/gpl.html *
20 : ***********************************************************************/
21 :
22 : #ifdef HAVE_CONFIG_H
23 : # include <config.h>
24 : #endif
25 :
26 : #include <stdbool.h>
27 : #include <gettext.h>
28 :
29 : #include <assert.h>
30 :
31 : #include <inttypes.h>
32 : #include "security.h"
33 : #include "tunnel.h"
34 : #include "clock.h"
35 :
36 : /**
37 : * Initializes libteredo. That function must be called before any other
38 : * libteredo functions. It can safely be called multiple times and is
39 : * thread-safe. If the process is to be chrooted(), it should be called
40 : * before chroot().
41 : *
42 : * @param use_client true if libteredo is to be used in client-mode
43 : *
44 : * @return 0 on success, -1 on failure.
45 : * -1 is also returned when use_client is true while libteredo was
46 : * compiled without client support.
47 : */
48 : int teredo_startup (bool use_client)
49 4 : {
50 : (void)bindtextdomain (PACKAGE_NAME, LOCALEDIR);
51 :
52 : #ifdef MIREDO_TEREDO_CLIENT
53 : (void)use_client;
54 : #else
55 : if (use_client)
56 : return -1;
57 : #endif
58 :
59 4 : if (teredo_init_HMAC () == 0)
60 : {
61 4 : if (teredo_clock_create () == 0)
62 4 : return 0;
63 0 : teredo_deinit_HMAC ();
64 : }
65 0 : return -1;
66 : }
67 :
68 :
69 : /**
70 : * Releases resources allocated with teredo_startup().
71 : * Should be called as many times as teredo_startup() was called.
72 : * Thread-safe.
73 : *
74 : * @param use_client true if the matching teredo_preinit call
75 : * had the use_client parameter set.
76 : */
77 : void teredo_cleanup (bool use_client)
78 4 : {
79 : (void)use_client;
80 : #ifndef MIREDO_TEREDO_CLIENT
81 : assert (!use_client);
82 : #endif
83 :
84 4 : teredo_clock_destroy ();
85 4 : teredo_deinit_HMAC ();
86 4 : }
|