+#ifdef HAVE_LZ4
+#include <lz4.h>
+#endif
+
+#ifndef HAVE_WINDOWS
+#include <pwd.h>
+#include <grp.h>
+#include <time.h>
+#endif
+
+#include "conf.h"
+#include "crypto.h"
+#include "event.h"
+#include "logger.h"
+#include "names.h"
+#include "net.h"
+#include "process.h"
+#include "protocol.h"
+#include "utils.h"
+#include "xalloc.h"
+#include "version.h"
+#include "random.h"
+#include "sandbox.h"
+#include "watchdog.h"
+
+/* If nonzero, display usage information and exit. */
+static bool show_help = false;
+
+/* If nonzero, print the version on standard output and exit. */
+static bool show_version = false;
+
+#ifdef HAVE_MLOCKALL
+/* If nonzero, disable swapping for this process. */
+static bool do_mlock = false;
+#endif
+
+#ifndef HAVE_WINDOWS
+/* If nonzero, chroot to netdir after startup. */
+static bool do_chroot = false;
+
+/* If !NULL, do setuid to given user after startup */
+static const char *switchuser = NULL;
+#endif
+
+char **g_argv; /* a copy of the cmdline arguments */
+
+static int status = 1;
+
+typedef enum option_t {
+ OPT_BAD_OPTION = '?',
+ OPT_LONG_OPTION = 0,
+
+ // Short options
+ OPT_CONFIG_FILE = 'c',
+ OPT_NETNAME = 'n',
+ OPT_NO_DETACH = 'D',
+ OPT_DEBUG = 'd',
+ OPT_MLOCK = 'L',
+ OPT_CHROOT = 'R',
+ OPT_CHANGE_USER = 'U',
+ OPT_SYSLOG = 's',
+ OPT_OPTION = 'o',
+
+ // Long options
+ OPT_HELP = 255,
+ OPT_VERSION,
+ OPT_NO_SECURITY,
+ OPT_LOGFILE,
+ OPT_PIDFILE,
+} option_t;
+
+static struct option const long_options[] = {
+ {"config", required_argument, NULL, OPT_CONFIG_FILE},
+ {"net", required_argument, NULL, OPT_NETNAME},
+ {"no-detach", no_argument, NULL, OPT_NO_DETACH},
+ {"debug", optional_argument, NULL, OPT_DEBUG},
+ {"mlock", no_argument, NULL, OPT_MLOCK},
+ {"chroot", no_argument, NULL, OPT_CHROOT},
+ {"user", required_argument, NULL, OPT_CHANGE_USER},
+ {"syslog", no_argument, NULL, OPT_SYSLOG},
+ {"option", required_argument, NULL, OPT_OPTION},
+ {"help", no_argument, NULL, OPT_HELP},
+ {"version", no_argument, NULL, OPT_VERSION},
+ {"bypass-security", no_argument, NULL, OPT_NO_SECURITY},
+ {"logfile", optional_argument, NULL, OPT_LOGFILE},
+ {"pidfile", required_argument, NULL, OPT_PIDFILE},
+ {NULL, 0, NULL, 0},
+};
+
+#ifdef HAVE_WINDOWS
+static struct WSAData wsa_state;
+int main2(int argc, char **argv);