// // Stdio Daemon // Neal Probert // #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "StdioDaemon.h" #include "netlib.h" extern int optind, opterr, optopt; // // any port // static const char *helptext = "stdiod [options]\n" "\t-d debug (foreground with stdio)\n" "\t-h help\n" "\t-l UDP listen for data\n" "\t-m network broadcast data\n" "\t-S service TCP service\n"; int main(int argc, char **argv) { char c; /* we have character */ StdioDaemon Std; /* options */ int debug = 0; // run in foreground, leaves stdio open /* dgpsip server */ char *host = NULL; /* udp broadcast */ char *mcast = NULL; /* udp listener */ char *listen = NULL; /* server */ char *service = (char *)STDIOD_PORT; // add command line args while ( (c = getopt( argc, argv, "dhm:l:r:S:" )) > 0 ) { switch ( c ) { case 'd': debug = 1; break; case 'h': puts( helptext ); return 0; case 'l': // udp listen listen = optarg; break; case 'm': // udp broadcast mcast = optarg; break; case 'r': // remote host host = optarg; break; case 'S': service = optarg; break; default: fprintf( stderr, "Unknown option -%c\n", c ); exit(1); } } // check options if ( mcast && listen ) { fprintf( stderr, "Cannot do both UDP broadcast/multicast and listening!\n" ); exit(1); } // input // corrections if ( host ) { // RTCM server int remote = Std.TcpConnect( host ); if ( remote < 0 ) { fprintf( stderr, "Unable to connect to remote host: %s\n", host ); exit(1); } } else if ( listen ) { // listen on UDP broadcasts for RTCM corrrections int dgram = Std.UdpListen( listen ); if ( dgram < 0 ) { fprintf( stderr, "Unable to listen on UDP broadcast!\n" ); exit(1); } } // output if ( mcast ) { int bcast = Std.UdpBroadcast( mcast ); if ( bcast < 0 ) { fprintf( stderr, "Unable to create UDP broadcast!\n" ); exit(1); } } // TCP listener if ( Std.StartService( STDIOD_NAME, NULL, service, debug ) >= 0 ) return Std.RunService(); return 1; }