+ extern char *optarg;
+ int pid;
+ int arg;
+ int port = 0, out_port = 0;
+
+ /* Default: daemon mode, no other options */
+ run_mode = 0;
+
+ /* Set the basename */
+ if ((name_p = strrchr(argv[0],'/')) != NULL) {
+ name_p ++;
+ } else {
+ name_p = argv[0];
+ }
+
+ /* Get the version */
+ if ((version_p = strrchr(VERSION,' ')) != NULL) {
+ version_p++;
+ } else {
+ version_p = VERSION;
+ }
+
+ /* Set hostname */
+ MY_NAME = NULL;
+
+ /* Process command line switches */
+ while ((arg = getopt_long(argc, argv, "h?vVFNdn:p:o:P:", longopts, NULL)) != EOF) {
+ switch (arg) {
+ case 'V': /* Version */
+ case 'v':
+ printf("%s version %s\n",name_p,version_p);
+ exit(0);
+ case 'F': /* Foreground/nodaemon mode */
+ run_mode |= MODE_NODAEMON;
+ break;
+ case 'N':
+ run_mode |= MODE_NOTIFY_ONLY;
+ break;
+ case 'd': /* No daemon only - log to stderr */
+ run_mode |= MODE_LOG_STDERR;
+ break;
+ case 'o':
+ out_port = atoi(optarg);
+ if (out_port < 1 || out_port > 65535) {
+ fprintf(stderr, "%s: bad port number: %s\n",
+ argv[0], optarg);
+ usage();
+ exit(1);
+ }
+ break;
+ case 'p':
+ port = atoi(optarg);
+ if (port < 1 || port > 65535) {
+ fprintf(stderr, "%s: bad port number: %s\n",
+ argv[0], optarg);
+ usage();
+ exit(1);
+ }
+ break;
+ case 'n': /* Specify local hostname */
+ MY_NAME = xstrdup(optarg);
+ break;
+ case 'P':
+
+ if ((DIR_BASE = xstrdup(optarg)) == NULL) {
+ fprintf(stderr, "%s: xstrdup(%s) failed!\n",
+ argv[0], optarg);
+ exit(1);
+ }