-int
-main(int argc, char **argv, char **envp)
-{
- program_name = argv[0];
-
- setlocale (LC_ALL, "");
- bindtextdomain (PACKAGE, LOCALEDIR);
- textdomain (PACKAGE);
-
- /* Do some intl stuff right now */
-
- unknown = _("unknown");
-
- environment = envp;
- parse_options(argc, argv, envp);
-
- if(show_version)
- {
- printf(_("%s version %s (built %s %s, protocol %d)\n"), PACKAGE, VERSION, __DATE__, __TIME__, PROT_CURRENT);
- printf(_("Copyright (C) 1998,1999,2000 Ivo Timmermans, Guus Sliepen and others.\n"
- "See the AUTHORS file for a complete list.\n\n"
- "tinc comes with ABSOLUTELY NO WARRANTY. This is free software,\n"
- "and you are welcome to redistribute it under certain conditions;\n"
- "see the file COPYING for details.\n"));
-
- return 0;
- }
-
- if(show_help)
- usage(0);
-
- if(geteuid())
- {
- fprintf(stderr, _("You must be root to run this program. Sorry.\n"));
- return 1;
- }
-
- g_argv = argv;
-
- make_names();
-
- /* Slllluuuuuuurrrrp! */
-
- RAND_load_file("/dev/urandom", 1024);
-
- if(generate_keys)
- exit(keygen(generate_keys));
-
- if(kill_tincd)
- exit(kill_other());
-
- if(read_server_config())
- return 1;
-
- if(detach())
- exit(0);
-
- if(debug_lvl >= DEBUG_ERROR)
- ERR_load_crypto_strings();
-
- for(;;)
- {
- if(!setup_network_connections())
- {
- main_loop();
- cleanup_and_exit(1);
- }
-
- syslog(LOG_ERR, _("Unrecoverable error"));
- cp_trace();
-
- if(do_detach)
- {
- syslog(LOG_NOTICE, _("Restarting in %d seconds!"), MAXTIMEOUT);
- sleep(MAXTIMEOUT);
- }
- else
- {
- syslog(LOG_ERR, _("Not restarting."));
- exit(0);
- }
- }
-}
+ g_argv = argv;
+
+ init_configuration(&config_tree);
+
+ /* Slllluuuuuuurrrrp! */
+
+ gettimeofday(&now, NULL);
+ srand(now.tv_sec + now.tv_usec);
+ crypto_init();
+
+ if(!read_server_config())
+ return 1;
+
+ char *priority = NULL;
+
+ /* Setup sockets. */
+
+ if(!setup_network())
+ goto end;