ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/gvpe/src/vped.C
(Generate patch)

Comparing gvpe/src/vped.C (file contents):
Revision 1.7 by pcg, Tue Apr 15 03:48:40 2003 UTC vs.
Revision 1.14 by pcg, Sat Jan 17 14:50:40 2004 UTC

1/* 1/*
2 vped.C -- the main file for vped 2 vped.C -- the main file for vped
3 Copyright (C) 1998-2002 Ivo Timmermans <ivo@o2w.nl> 3 Copyright (C) 1998-2002 Ivo Timmermans <ivo@o2w.nl>
4 2000-2002 Guus Sliepen <guus@sliepen.eu.org> 4 2000-2002 Guus Sliepen <guus@sliepen.eu.org>
5 2003 Marc Lehmannn <pcg@goof.com> 5 2003 Marc Lehmann <pcg@goof.com>
6 6
7 This program is free software; you can redistribute it and/or modify 7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by 8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or 9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version. 10 (at your option) any later version.
21 21
22#include "config.h" 22#include "config.h"
23 23
24#include <cstdio> 24#include <cstdio>
25#include <cstring> 25#include <cstring>
26#include <clocale>
26 27
27#include <errno.h> 28#include <errno.h>
28#include <fcntl.h> 29#include <fcntl.h>
29#include <getopt.h> 30#include <getopt.h>
30#include <signal.h> 31#include <signal.h>
31#include <sys/types.h> 32#include <sys/types.h>
32#include <unistd.h> 33#include <unistd.h>
33#include <signal.h> 34#include <signal.h>
34#include <termios.h> 35#include <termios.h>
35 36
37#if HAVE_SYS_MMAN_H
36#include <sys/mman.h> 38# include <sys/mman.h>
39#endif
37 40
41#include <openssl/err.h>
38#include <openssl/rand.h> 42#include <openssl/rand.h>
39 43
40#include "gettext.h" 44#include "gettext.h"
41#include "pidfile.h" 45#include "pidfile.h"
42 46
44#include "slog.h" 48#include "slog.h"
45#include "util.h" 49#include "util.h"
46#include "vpn.h" 50#include "vpn.h"
47#include "iom.h" 51#include "iom.h"
48 52
49vpn network;
50
51static loglevel llevel = L_NONE; 53static loglevel llevel = L_NONE;
52 54
53/* If nonzero, display usage information and exit. */ 55/* If nonzero, display usage information and exit. */
54static int show_help; 56static int show_help;
55 57
56/* If nonzero, print the version on standard output and exit. */ 58/* If nonzero, print the version on standard output and exit. */
57static int show_version; 59static int show_version;
58 60
59#if HAVE_MLOCKALL
60/* If nonzero, disable swapping for this process. */ 61/* If nonzero, disable swapping for this process. */
61static int do_mlock = 0; 62static int do_mlock = 0;
62#endif
63 63
64/* If zero, don't detach from the terminal. */ 64/* If zero, don't detach from the terminal. */
65static int do_detach = 1; 65static int do_detach = 1;
66 66
67static struct option const long_options[] = 67static struct option const long_options[] =
69 {"config", required_argument, NULL, 'c'}, 69 {"config", required_argument, NULL, 'c'},
70 {"help", no_argument, &show_help, 1}, 70 {"help", no_argument, &show_help, 1},
71 {"version", no_argument, &show_version, 1}, 71 {"version", no_argument, &show_version, 1},
72 {"no-detach", no_argument, &do_detach, 0}, 72 {"no-detach", no_argument, &do_detach, 0},
73 {"log-level", required_argument, NULL, 'l'}, 73 {"log-level", required_argument, NULL, 'l'},
74#if HAVE_MLOCKALL
75 {"mlock", no_argument, &do_mlock, 1}, 74 {"mlock", no_argument, &do_mlock, 1},
76#endif
77 {NULL, 0, NULL, 0} 75 {NULL, 0, NULL, 0}
78 }; 76 };
79 77
80static void 78static void
81usage (int status) 79usage (int status)
121 119
122 case 'D': /* no detach */ 120 case 'D': /* no detach */
123 do_detach = 0; 121 do_detach = 0;
124 break; 122 break;
125 123
126#if HAVE_MLOCKALL
127 case 'L': /* lock into memory */ 124 case 'L': /* lock into memory */
128 do_mlock = 1; 125 do_mlock = 1;
129 break; 126 break;
130#endif
131 127
132 case 'l': /* inc debug level */ 128 case 'l': /* inc debug level */
133 { 129 {
134 llevel = string_to_loglevel (optarg); 130 llevel = string_to_loglevel (optarg);
135 131
209} 205}
210 206
211int 207int
212main (int argc, char **argv, char **envp) 208main (int argc, char **argv, char **envp)
213{ 209{
210 ERR_load_crypto_strings (); // we have the RAM
211
214 set_loglevel (L_INFO); 212 set_loglevel (L_INFO);
215 set_identity (argv[0]); 213 set_identity (argv[0]);
216 log_to (LOGTO_SYSLOG | LOGTO_STDERR); 214 log_to (LOGTO_SYSLOG | LOGTO_STDERR);
217 215
218 setlocale (LC_ALL, ""); 216 setlocale (LC_ALL, "");
223 221
224 if (show_version) 222 if (show_version)
225 { 223 {
226 printf (_("%s version %s (built %s %s, protocol %d.%d)\n"), get_identity (), 224 printf (_("%s version %s (built %s %s, protocol %d.%d)\n"), get_identity (),
227 VERSION, __DATE__, __TIME__, PROTOCOL_MAJOR, PROTOCOL_MINOR); 225 VERSION, __DATE__, __TIME__, PROTOCOL_MAJOR, PROTOCOL_MINOR);
226 printf (_("Built with kernel interface %s/%s.\n"), IFTYPE, IFSUBTYPE);
228 printf (_ 227 printf (_
229 ("Copyright (C) 2003 Marc Lehmann <vpe@plan9.de> and others.\n" 228 ("Copyright (C) 2003 Marc Lehmann <vpe@plan9.de> and others.\n"
230 "See the AUTHORS file for a complete list.\n\n" 229 "See the AUTHORS file for a complete list.\n\n"
231 "tinc comes with ABSOLUTELY NO WARRANTY. This is free software,\n" 230 "tinc comes with ABSOLUTELY NO WARRANTY. This is free software,\n"
232 "and you are welcome to redistribute it under certain conditions;\n" 231 "and you are welcome to redistribute it under certain conditions;\n"
240 239
241 log_to (LOGTO_SYSLOG | LOGTO_STDERR); 240 log_to (LOGTO_SYSLOG | LOGTO_STDERR);
242 241
243 /* Lock all pages into memory if requested */ 242 /* Lock all pages into memory if requested */
244 243
245#if HAVE_MLOCKALL 244#if HAVE_MLOCKALL && HAVE_SYS_MMAN_H && _POSIX_MEMLOCK
246 if (do_mlock) 245 if (do_mlock)
247 if (mlockall (MCL_CURRENT | MCL_FUTURE)) 246 if (mlockall (MCL_CURRENT | MCL_FUTURE))
248 slog (L_ERR, _("system call `%s' failed: %s"), "mlockall", strerror (errno)); 247 slog (L_ERR, _("system call `%s' failed: %s"), "mlockall", strerror (errno));
249#endif 248#endif
250 249

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines