int main (int argc, char **argv) { struct sigaction sa; setProgName(argv[0]); FD_ZERO(&activeSet); FD_ZERO(&readSet); FD_ZERO(&writeSet); setFdUsed(stdinfd, DATA_INPUT_STREAM); outputIdx = setFdUsed(stdoutfd, DATA_OUTPUT_STREAM); while (argc > 1) { if (strcasecmp(argv[1], "-d") == 0) { setLogLevel(LOGLEVEL_DEBUG); debug = 1; } else if (strcasecmp(argv[1], "-q") == 0) { setLogLevel(LOGLEVEL_ERROR); } else if (strcasecmp(argv[1], "-o") == 0) { outputIdx = setFdUsed(stdoutfd, DATA_OUTPUT_COPY); } else if (strcasecmp(argv[1], "-r") == 0) { outputIdx = setFdUsed(stdoutfd, DATA_OUTPUT_SINK); } else if (strcasecmp(argv[1], "--src-filter") == 0 && argc > 2) { srcFilter = argv[2]; argc--, argv++; } else if (strcasecmp(argv[1], "--rate-limit") == 0) { rateLimit = true; } else if (strcasecmp(argv[1], "-p") == 0 && argc > 2) { unsigned int uPort; if (sscanf(argv[2], "%u", &uPort)) { port = (uint16_t) uPort; } argc--, argv++; } else { fprintf(stderr, "usage: n2kd [-d] [-q] [-o] [-r] [--src-filter <srclist>] [--rate-limit] [-p <port>]\n\n" " -d debug mode\n" " -q quiet mode\n" " -o output mode, send all TCP client data to stdout (as well as stdin)\n" " -r restrict mode, send no data to stdout\n" " --src-filter <srclist> restrict NMEA0183 stream to particular N2K sources\n" " --rate-limit restrict NMEA0183 stream to one message per source per second\n" " -p <port> Start servers at <port> instead of 2597\n\n" COPYRIGHT); exit(1); } argc--, argv++; } startTcpServers(); /* Ignore SIGPIPE, this will let a write to a socket that's closed */ /* at the other end just fail instead of raising SIGPIPE */ memset( &sa, 0, sizeof( sa ) ); sa.sa_handler = SIG_IGN; sigaction( SIGPIPE, &sa, 0 ); doServerWork(); exit(0); }
int main (int argc, char **argv) { struct sigaction sa; setProgName(argv[0]); FD_ZERO(&activeSet); FD_ZERO(&readSet); FD_ZERO(&writeSet); setFdUsed(stdinfd, DATA_INPUT_STREAM); outputIdx = setFdUsed(stdoutfd, DATA_OUTPUT_STREAM); while (argc > 1) { if (strcasecmp(argv[1], "-d") == 0) { setLogLevel(LOGLEVEL_DEBUG); } else if (strcasecmp(argv[1], "-q") == 0) { setLogLevel(LOGLEVEL_ERROR); } else if (strcasecmp(argv[1], "-o") == 0) { outputIdx = setFdUsed(stdoutfd, DATA_OUTPUT_COPY); } else if (strcasecmp(argv[1], "-r") == 0) { outputIdx = setFdUsed(stdoutfd, DATA_OUTPUT_SINK); } else if (strcasecmp(argv[1], "--src-filter") == 0 && argc > 2) { srcFilter = argv[2]; argc--, argv++; } else if (strcasecmp(argv[1], "-p") == 0 && argc > 2) { unsigned int uPort; if (sscanf(argv[2], "%u", &uPort)) { port = (uint16_t) uPort; } argc--, argv++; } else { fprintf(stderr, "usage: n2kd [-d] [-q] [--src-filter <srclist>] [-o] [-p <port>] [-r]\n\n"COPYRIGHT); exit(1); } argc--, argv++; } startTcpServers(); /* Ignore SIGPIPE, this will let a write to a socket that's closed */ /* at the other end just fail instead of raising SIGPIPE */ memset( &sa, 0, sizeof( sa ) ); sa.sa_handler = SIG_IGN; sigaction( SIGPIPE, &sa, 0 ); doServerWork(); exit(0); }