/* * appSetup(argc, argv); * * Perform all the setup for this application include setting up * required modules, parsing options, etc. This function should be * passed the same arguments that were passed into main(). * * Returns to the caller if all setup succeeds. If anything fails, * this function will cause the application to exit with a FAILURE * exit status. */ static void appSetup( int argc, char **argv) { SILK_FEATURES_DEFINE_STRUCT(features); int arg_index; /* verify same number of options and help strings */ assert((sizeof(appHelp)/sizeof(char *)) == (sizeof(appOptions)/sizeof(struct option))); /* register the application */ skAppRegister(argv[0]); skAppVerifyFeatures(&features, NULL); skOptionsSetUsageCallback(&appUsageLong); /* register the options */ if (skOptionsRegister(appOptions, &appOptionsHandler, NULL)) { skAppPrintErr("Unable to register options"); exit(EXIT_FAILURE); } /* parse the options */ arg_index = skOptionsParse(argc, argv); if (arg_index < 0) { /* options parsing should print error */ skAppUsage(); /* never returns */ } /* check for extraneous arguments */ if (arg_index != argc) { skAppPrintErr("Too many arguments or unrecognized switch '%s'", argv[arg_index]); skAppUsage(); /* never returns */ } /* verify logging */ if (sklogOptionsVerify()) { exit(EXIT_FAILURE); } /* write command line */ sklogCommandLine(argc, argv); /* register the teardown handler */ if (atexit(appTeardown) < 0) { skAppPrintErr("Unable to register appTeardown() with atexit()"); appTeardown(); exit(EXIT_FAILURE); } return; /* OK */ }
int main(int argc, char **argv) { SILK_FEATURES_DEFINE_STRUCT(features); int arg_index; /* verify same number of options and help strings */ assert((sizeof(appHelp)/sizeof(char *)) == (sizeof(appOptions)/sizeof(struct option))); /* register the application */ skAppRegister(argv[0]); skAppVerifyFeatures(&features, NULL); skOptionsSetUsageCallback(&appUsageLong); /* register the options */ if (skOptionsRegister(appOptions, &appOptionsHandler, NULL) || sksiteOptionsRegister(SK_SITE_FLAG_CONFIG_FILE)) { skAppPrintErr("Unable to register options"); exit(EXIT_FAILURE); } /* parse the options */ arg_index = skOptionsParse(argc, argv); if (arg_index < 0) { /* options parsing should print error */ skAppUsage(); /* never returns */ } /* ensure the site config is available */ if (sksiteConfigure(1)) { exit(EXIT_FAILURE); } /* if we are printing more than one sensor and a --print-* switch * was given, set the width of the sensor name fields so the * values align */ if ((argc != arg_index + 1) && (print_descriptions || print_classes)) { sensor_name_width = -1 * (int)sksiteSensorGetMaxNameStrLen(); } if (argc > arg_index) { for ( ; arg_index < argc; ++arg_index) { printByNameOrNumber(argv[arg_index]); } } else { /* no args. print all */ printAllSensors(); } skAppUnregister(); return 0; }
/* * appSetup(argc, argv); * * Perform all the setup for this application include setting up * required modules, parsing options, etc. This function should be * passed the same arguments that were passed into main(). * * Returns to the caller if all setup succeeds. If anything fails, * this function will cause the application to exit with a FAILURE * exit status. */ static void appSetup( int argc, char **argv) { SILK_FEATURES_DEFINE_STRUCT(features); int arg_index; /* verify same number of options and help strings */ assert((sizeof(appHelp)/sizeof(char *)) == (sizeof(appOptions)/sizeof(struct option))); /* register the application */ skAppRegister(argv[0]); skAppVerifyFeatures(&features, NULL); skOptionsSetUsageCallback(&appUsageLong); memset(&prefixmap_test_opt, 0, sizeof(prefixmap_test_opt)); /* register the teardown handler */ if (atexit(appTeardown) < 0) { skAppPrintErr("Unable to register appTeardown() with atexit()"); appTeardown(); exit(EXIT_FAILURE); } /* register the options */ if (skOptionsRegister(appOptions, &appOptionsHandler, NULL)) { skAppPrintErr("Unable to register options"); exit(EXIT_FAILURE); } /* parse the options */ arg_index = skOptionsParse(argc, argv); if (arg_index < 0) { /* options parsing should print error */ skAppUsage(); /* never returns */ } if ( (NULL == prefixmap_test_opt.map_file) || (0 == prefixmap_test_opt.have_address) ) { if ( NULL == prefixmap_test_opt.map_file ) { skAppPrintErr("Required argument map-file not provided."); } if ( 0 == prefixmap_test_opt.have_address ) { skAppPrintErr("Required argument address not provided."); } exit(EXIT_FAILURE); } return; /* OK */ }
/* * appSetup(argc, argv); * * Perform all the setup for this application include setting up * required modules, parsing options, etc. This function should be * passed the same arguments that were passed into main(). * * Returns to the caller if all setup succeeds. If anything fails, * this function will cause the application to exit with a FAILURE * exit status. */ static void appSetup( int argc, char **argv) { SILK_FEATURES_DEFINE_STRUCT(features); /* verify same number of options and help strings */ assert((sizeof(appHelp) / sizeof(char *)) == (sizeof(appOptions) / sizeof(struct option))); /* register the application */ skAppRegister(argv[0]); skAppVerifyFeatures(&features, NULL); skOptionsSetUsageCallback(&appUsageLong); /* register the options */ if (skOptionsRegister(appOptions, & appOptionsHandler, NULL)) { skAppPrintErr("Unable to register options"); exit(EXIT_FAILURE); } /* register the teardown hanlder */ if (atexit(appTeardown) < 0) { skAppPrintErr("Unable to register appTeardown() with atexit()"); appTeardown(); exit(EXIT_FAILURE); } /* parse options */ arg_index = skOptionsParse(argc, argv); if (arg_index < 0) { skAppUsage(); /* never returns */ } /* get the pattern */ pattern = argv[arg_index++]; if (NULL == pattern) { skAppPrintErr("No pattern specified"); skAppUsage(); } /* either need name of set file(s) after options or a set file on stdin */ if ((arg_index == argc) && (FILEIsATty(stdin))) { skAppPrintErr("No files on the command line and" " stdin is connected to a terminal"); skAppUsage(); } return; /* OK */ }
/* * appSetup(argc, argv); * * Perform all the setup for this application include setting up * required modules, parsing options, etc. This function should be * passed the same arguments that were passed into main(). * * Returns to the caller if all setup succeeds. If anything fails, * this function will cause the application to exit with a FAILURE * exit status. */ static void appSetup( int argc, char **argv) { SILK_FEATURES_DEFINE_STRUCT(features); /* verify same number of options and help strings */ assert((sizeof(appHelp)/sizeof(char *)) == (sizeof(appOptions)/sizeof(struct option))); /* register the application */ skAppRegister(argv[0]); skAppVerifyFeatures(&features, NULL); skOptionsSetUsageCallback(&appUsageLong); /* register the options */ if (skOptionsRegister(appOptions, &appOptionsHandler, NULL) || sksiteOptionsRegister(SK_SITE_FLAG_CONFIG_FILE)) { skAppPrintErr("Unable to register options"); exit(EXIT_FAILURE); } /* register the teardown handler */ if (atexit(appTeardown) < 0) { skAppPrintErr("Unable to register appTeardown() with atexit()"); appTeardown(); exit(EXIT_FAILURE); } /* parse the options */ arg_index = skOptionsParse(argc, argv); if (arg_index < 0) { /* options parsing should print error */ skAppUsage(); /* never returns */ } /* try to load site config file; if it fails, we will not be able * to resolve flowtype and sensor from input file names */ sksiteConfigure(0); /* arg_index is looking at first file name to process */ if (arg_index + 2 != argc) { skAppPrintErr("Expected two file names on the command line"); skAppUsage(); /* never returns */ } return; /* OK */ }
/* * appSetup(argc, argv); * * Perform all the setup for this application include setting up * required modules, parsing options, etc. This function should be * passed the same arguments that were passed into main(). * * Returns to the caller if all setup succeeds. If anything fails, * this function will cause the application to exit with a FAILURE * exit status. */ static void appSetup( int argc, char **argv) { SILK_FEATURES_DEFINE_STRUCT(features); int arg_index; int rv; /* check that we have the same number of options entries and help*/ assert((sizeof(appHelp)/sizeof(char *)) == (sizeof(appOptions)/sizeof(struct option))); /* register the application */ skAppRegister(argv[0]); skAppVerifyFeatures(&features, NULL); skOptionsSetUsageCallback(&appUsageLong); /* initialize globals */ shuttingdown = 0; destination_dir = NULL; duplicate_dirs = skDLListCreate(NULL); if (duplicate_dirs == NULL) { skAppPrintOutOfMemory("duplicate directory list"); exit(EXIT_FAILURE); } open_file_list = skDLListCreate(NULL); if (open_file_list == NULL) { skAppPrintOutOfMemory("open file list"); exit(EXIT_FAILURE); } transfers = transferIdentTreeCreate(); if (transfers == NULL) { skAppPrintOutOfMemory("receiver data structure"); exit(EXIT_FAILURE); } #ifdef SK_HAVE_STATVFS { uint64_t tmp_64; rv = skStringParseHumanUint64(&tmp_64, DEFAULT_FREESPACE_MINIMUM, SK_HUMAN_NORMAL); if (rv) { skAppPrintErr("Bad default value for freespace_minimum: '%s': %s", DEFAULT_FREESPACE_MINIMUM,skStringParseStrerror(rv)); exit(EXIT_FAILURE); } freespace_minimum = (int64_t)tmp_64; } #endif /* SK_HAVE_STATVFS */ /* register the options and handler */ if (skOptionsRegister(appOptions, &appOptionsHandler, NULL)) { skAppPrintErr("Unable to register application options"); exit(EXIT_FAILURE); } /* Register the other transfer options */ if (transferSetup()) { exit(EXIT_FAILURE); } /* rwreceiver runs as a daemon */ if (skdaemonSetup((SKLOG_FEATURE_LEGACY | SKLOG_FEATURE_SYSLOG), argc, argv)) { exit(EXIT_FAILURE); } /* register the teardown handler */ if (atexit(appTeardown) < 0) { skAppPrintErr("Unable to register appTeardown() with atexit()"); appTeardown(); exit(EXIT_FAILURE); } /* parse the options */ arg_index = skOptionsParse(argc, argv); if (arg_index < 0) { /* options parsing should print error */ skAppUsage(); /* never returns */ } /* Verify the options */ rv = rwreceiverVerifyOptions(); /* verify the required options for logging */ if (skdaemonOptionsVerify()) { rv = -1; } if (rv) { skAppUsage(); /* never returns */ } /* check for extraneous arguments */ if (arg_index != argc) { skAppPrintErr("Too many arguments or unrecognized switch --%s", argv[arg_index]); skAppUsage(); /* never returns */ } /* Identify the main thread */ skthread_init("main"); return; /* OK */ }
/* * appSetup(argc, argv); * * Perform all the setup for this application include setting up * required modules, parsing options, etc. This function should be * passed the same arguments that were passed into main(). * * Returns to the caller if all setup succeeds. If anything fails, * this function will cause the application to exit with a FAILURE * exit status. */ static void appSetup( int argc, char **argv) { SILK_FEATURES_DEFINE_STRUCT(features); int rv; /* verify same number of options and help strings */ assert((sizeof(appHelp)/sizeof(char *)) == (sizeof(appOptions)/sizeof(struct option))); /* register the application */ skAppRegister(argv[0]); skAppVerifyFeatures(&features, NULL); skOptionsSetUsageCallback(&appUsageLong); /* initialize globals */ #error "Initialize any global variables here" /* for example: set global output to NULL */ out_stream = NULL; /* register the options */ if (skOptionsRegister(appOptions, &appOptionsHandler, NULL) || sksiteOptionsRegister(SK_SITE_FLAG_CONFIG_FILE)) { skAppPrintErr("Unable to register options"); exit(EXIT_FAILURE); } #error "Do any other module setup here" /* register the teardown handler */ if (atexit(appTeardown) < 0) { skAppPrintErr("Unable to register appTeardown() with atexit()"); appTeardown(); exit(EXIT_FAILURE); } /* parse the options */ arg_index = skOptionsParse(argc, argv); if (arg_index < 0) { /* options parsing should print error */ skAppUsage(); /* never returns */ } /* try to load site config file; if it fails, we will not be able * to resolve flowtype and sensor from input file names */ sksiteConfigure(0); #error "Do any options validation here" #error "If you expect filenames on command line keep this:" /* arg_index is looking at first file name to process */ if (arg_index == argc) { if (FILEIsATty(stdin)) { skAppPrintErr("No input files on command line and" " stdin is connected to a terminal"); skAppUsage(); /* never returns */ } } #error "If you do NOT expect filenames on command line, keep this:" /* check for extraneous arguments */ if (arg_index != argc) { skAppPrintErr("Too many arguments or unrecognized switch '%s'", argv[arg_index]); skAppUsage(); /* never returns */ } #error "Once all options are set, open input and output" /* for example, open a SiLK flow file as an output file */ rv = skStreamOpenSilkFlow(&out_stream, output_path, SK_IO_WRITE); if (rv) { skStreamPrintLastErr(out_stream, rv, &skAppPrintErr); skAppPrintErr("Unable to open output file. Exiting"); skStreamDestroy(&out_stream); exit(EXIT_FAILURE); } return; /* OK */ }
/* * appSetup(argc, argv); * * Perform all the setup for this application include setting up * required modules, parsing options, etc. This function should be * passed the same arguments that were passed into main(). * * Returns to the caller if all setup succeeds. If anything fails, * this function will cause the application to exit with a FAILURE * exit status. */ static void appSetup( int argc, char **argv) { SILK_FEATURES_DEFINE_STRUCT(features); const char *in_fname; const char *out_fname; int arg_index; int rv; /* verify same number of options and help strings */ assert((sizeof(appHelp)/sizeof(char *)) == (sizeof(appOptions)/sizeof(struct option))); /* register the application */ skAppRegister(argv[0]); skAppVerifyFeatures(&features, NULL); skOptionsSetUsageCallback(&appUsageLong); /* initialize globals */ memset(&set_options, 0, sizeof(skipset_options_t)); set_options.argc = argc; set_options.argv = argv; /* register the options */ if (skOptionsRegister(appOptions, &appOptionsHandler, NULL) || skIPSetOptionsRegister(&set_options)) { skAppPrintErr("Unable to register options"); exit(EXIT_FAILURE); } /* register the teardown handler */ if (atexit(appTeardown) < 0) { skAppPrintErr("Unable to register appTeardown() with atexit()"); appTeardown(); exit(EXIT_FAILURE); } /* parse the options */ arg_index = skOptionsParse(argc, argv); if (arg_index < 0) { skAppUsage(); /* never returns */ } /* default is to read from stdin and write to stdout */ in_fname = "-"; out_fname = "-"; /* process files named on the command line */ switch (argc - arg_index) { case 2: in_fname = argv[arg_index++]; out_fname = argv[arg_index++]; break; case 1: in_fname = argv[arg_index++]; break; case 0: /* Do not allow reading from a tty when no input */ if (FILEIsATty(stdin)) { skAppPrintErr("Must specify '-' as the input to read" " from a terminal"); exit(EXIT_FAILURE); } break; default: skAppPrintErr("Too many arguments;" " a maximum of two files may be specified"); skAppUsage(); } /* we should have processed all arguments */ assert(arg_index == argc); /* create the IPset */ if (skIPSetCreate(&ipset, 0)) { EXIT_NO_MEMORY; } skIPSetOptionsBind(ipset, &set_options); /* create input */ if ((rv = skStreamCreate(&in_stream, SK_IO_READ, SK_CONTENT_TEXT)) || (rv = skStreamBind(in_stream, in_fname)) || (rv = skStreamSetCommentStart(in_stream, "#"))) { skStreamPrintLastErr(in_stream, rv, &skAppPrintErr); exit(EXIT_FAILURE); } /* create output */ if ((rv = skStreamCreate(&out_stream, SK_IO_WRITE, SK_CONTENT_SILK)) || (rv = skStreamBind(out_stream, out_fname))) { skStreamPrintLastErr(out_stream, rv, &skAppPrintErr); exit(EXIT_FAILURE); } /* open the streams */ rv = skStreamOpen(in_stream); if (rv) { skStreamPrintLastErr(in_stream, rv, &skAppPrintErr); exit(EXIT_FAILURE); } rv = skStreamOpen(out_stream); if (rv) { skStreamPrintLastErr(out_stream, rv, &skAppPrintErr); exit(EXIT_FAILURE); } }
/* * appSetup(argc, argv); * * Perform all the setup for this application include setting up * required modules, parsing options, etc. This function should be * passed the same arguments that were passed into main(). * * Returns to the caller if all setup succeeds. If anything fails, * this function will cause the application to exit with a FAILURE * exit status. */ static void appSetup( int argc, char **argv) { SILK_FEATURES_DEFINE_STRUCT(features); int arg_index; int rv; /* verify same number of options and help strings */ assert((sizeof(appHelp)/sizeof(char *)) == (sizeof(appOptions)/sizeof(struct option))); /* register the application */ skAppRegister(argv[0]); skAppVerifyFeatures(&features, NULL); skOptionsSetUsageCallback(&appUsageLong); /* register the options */ if (skOptionsRegister(appOptions, &appOptionsHandler, NULL)) { skAppPrintErr("Unable to register options"); exit(EXIT_FAILURE); } /* register the teardown hanlder */ if (atexit(appTeardown) < 0) { skAppPrintErr("Unable to register appTeardown() with atexit()"); appTeardown(); exit(EXIT_FAILURE); } /* parse the options */ arg_index = skOptionsParse(argc, argv); if (arg_index < 0) { /* options parsing should print error */ skAppUsage(); /* never returns */ } /* check for extraneous arguments */ if (arg_index != argc) { skAppPrintErr("Too many arguments or unrecognized switch '%s'", argv[arg_index]); skAppUsage(); /* never returns */ } /* check for one and only one of --input-file and --address */ if (NULL != app_opt.input_file) { if (NULL != app_opt.address) { skAppPrintErr("Only one of --%s or --%s may be specified.", appOptions[OPT_ADDRESS].name, appOptions[OPT_INPUT_FILE].name); skAppUsage(); } } else if (NULL == app_opt.address) { skAppPrintErr("Either the --%s or --%s option is required.", appOptions[OPT_ADDRESS].name, appOptions[OPT_INPUT_FILE].name); skAppUsage(); } /* find and load the map file */ if (skCountrySetup(app_opt.map_file, &skAppPrintErr)) { exit(EXIT_FAILURE); } /* use default for print-ips if unset by user */ if (-1 == app_opt.print_ips) { if (app_opt.input_file) { app_opt.print_ips = 1; } else { app_opt.print_ips = 0; } } /* create the output stream. Only page output when processing * input file */ if ((rv = skStreamCreate(&out, SK_IO_WRITE, SK_CONTENT_TEXT)) || (rv = skStreamBind(out, app_opt.output_path))) { skStreamPrintLastErr(out, rv, &skAppPrintErr); exit(EXIT_FAILURE); } if (app_opt.input_file) { rv = skStreamPageOutput(out, app_opt.pager); if (rv) { skStreamPrintLastErr(out, rv, &skAppPrintErr); exit(EXIT_FAILURE); } } rv = skStreamOpen(out); if (rv) { skStreamPrintLastErr(out, rv, &skAppPrintErr); exit(EXIT_FAILURE); } return; /* OK */ }
/* * appSetup(argc, argv); * * Perform all the setup for this application include setting up * required modules, parsing options, etc. This function should be * passed the same arguments that were passed into main(). * * Returns to the caller if all setup succeeds. If anything fails, * this function will cause the application to exit with a FAILURE * exit status. * * NOTE: Make this extern due to declaration in rwfilter.h. */ void appSetup( int argc, char **argv) { SILK_FEATURES_DEFINE_STRUCT(features); int rv; /* verify same number of options and help strings */ assert((sizeof(appHelp)/sizeof(char *)) == (sizeof(appOptions)/sizeof(struct option))); /* register the application */ skAppRegister(argv[0]); skAppVerifyFeatures(&features, NULL); skOptionsSetUsageCallback(&appUsageLong); /* register the options */ if (skOptionsRegister(appOptions, &appOptionsHandler, NULL)) { skAppPrintErr("Unable to register options"); exit(EXIT_FAILURE); } /* Set up the fglob module */ if (fglobSetup()){ skAppPrintErr("Unable to setup fglob module"); exit(EXIT_FAILURE); } /* register the teardown handler */ if (atexit(appTeardown) < 0) { skAppPrintErr("Unable to register appTeardown() with atexit()"); appTeardown(); exit(EXIT_FAILURE); } /* Parse the options */ arg_index = skOptionsParse(argc, argv); if (arg_index < 0) { skAppUsage(); } /* try to load site config file; if it fails, we will not be able * to resolve flowtype and sensor from input file names */ sksiteConfigure(0); /* check for extraneous arguments */ if (arg_index != argc) { skAppPrintErr("Too many arguments or unrecognized switch '%s'", argv[arg_index]); skAppUsage(); } /* verify that an fglob option was provided and that everything is * ok with the setup. */ rv = fglobValid(); if (rv == -1) { exit(EXIT_FAILURE); } if (rv == 0) { skAppPrintErr("Must specify at least one file selection switch"); exit(EXIT_FAILURE); } return; /* OK */ }
/* * appSetup(argc, argv); * * Perform all the setup for this application include setting up * required modules, parsing options, etc. This function should be * passed the same arguments that were passed into main(). * * Returns to the caller if all setup succeeds. If anything fails, * this function will cause the application to exit with a FAILURE * exit status. */ static void appSetup( int argc, char **argv) { SILK_FEATURES_DEFINE_STRUCT(features); char errbuf[PCAP_ERRBUF_SIZE]; int arg_index; /* verify same number of options and help strings */ assert((sizeof(appHelp)/sizeof(char*)) == (sizeof(appOptions)/sizeof(struct option))); /* register the application */ skAppRegister(argv[0]); skAppVerifyFeatures(&features, NULL); skOptionsSetUsageCallback(&appUsageLong); /* register the options */ if (skOptionsRegister(appOptions, &appOptionsHandler, NULL)) { skAppPrintErr("Unable to register options"); exit(EXIT_FAILURE); } /* register the teardown handler */ if (atexit(appTeardown) < 0) { skAppPrintErr("Unable to register appTeardown() with atexit()"); appTeardown(); exit(EXIT_FAILURE); } /* parse options */ arg_index = skOptionsParse(argc, argv); if (arg_index < 0) { skAppUsage(); /* never returns */ } /* verify input file */ if (arg_index >= argc) { skAppPrintErr("No input packet file found"); skAppUsage(); /* never returns */ } /* verify output is not a terminal */ if (FILEIsATty(stdout)) { skAppPrintErr("stdout is connected to a terminal"); skAppUsage(); /* never returns */ } /* open input file */ g_pkt_input = pcap_open_offline(argv[arg_index], errbuf); if (g_pkt_input == NULL) { skAppPrintErr("Unable to open input file %s: %s", argv[arg_index], errbuf); exit(EXIT_FAILURE); } /* open output file (tcpdump format packet file) */ g_output = pcap_open_dead(pcap_datalink(g_pkt_input), pcap_snapshot(g_pkt_input)); if (g_output == NULL) { skAppPrintErr("Error opening stdout: %s", errbuf); exit(EXIT_FAILURE); } g_output_dumper = pcap_dump_open(g_output, "-"); if (g_output_dumper == NULL) { skAppPrintErr("Error opening stdout: %s", pcap_geterr(g_output)); exit(EXIT_FAILURE); } return; /* OK */ }