use Net::Ping;
use Socket;
use POSIX;
+use Getopt::Long;
use Spong::Daemon;
use Spong::Status qw(status);
srand( time() ^ ($$ + ($$ << 15 )) );
-if( $ARGV[0] eq "--debug" ) { $debug = 1; shift; }
-if( $ARGV[0] eq "--restart" ) { $restart = 1; shift; }
-if( $ARGV[0] eq "--kill" ) { $kill = 1; shift; }
-if( $ARGV[0] eq "--nosleep" ) { $nosleep = 1; shift; }
-if( $ARGV[0] eq "--refresh" ) { $nosleep = 1; shift; }
+$debug = $restart = $kill = 0;
+
+Getopt::Long::Configure('pass_through');
+if ( ! GetOptions("debug:i" => \$debuglevel, "restart" => \$restart,
+ "kill" => \$kill, "nosleep|refresh" => \$nosleep ) ) {
+ &usage();
+ exit 1;
+}
+
+$debug = $debuglevel;
+
+#if( $ARGV[0] eq "--debug" ) { $debug = 1; shift; }
+#if( $ARGV[0] eq "--restart" ) { $restart = 1; shift; }
+#if( $ARGV[0] eq "--kill" ) { $kill = 1; shift; }
+#if( $ARGV[0] eq "--nosleep" ) { $nosleep = 1; shift; }
+#if( $ARGV[0] eq "--refresh" ) { $nosleep = 1; shift; }
$me = "@@BINDIR@@/spong-network";
$conf_file = $ARGV[0] || "@@ETCDIR@@/spong.conf";
# Utility functions, and signal handlers...
# ===========================================================================
+# Print out the usage for the program
+
+sub usage {
+
+ print qq
+(Usage:
+ $0 [--debug n] [--nosleep|--refresh] [config_file]
+ $0 --kill | --restart
+
+ --debug n
+ Run in the foreround and print debugging output
+ --nosleep
+ --refresh
+ Run one cycle of checks in the foreground and exit
+ --restart
+ Signal a running spong-network to restart.
+ --kill
+ Signal a running spong-network to terminate.
+ config_file
+ Use the named file as the configuration file
+);
+
+}
+
+
# Load our configuration variables, including anything specific to the host
# that we are running on.