adding support for help text to output modules

This commit is contained in:
Zakir Durumeric 2013-10-09 17:05:44 -04:00
parent 13ca18479a
commit 0410a99d18
3 changed files with 47 additions and 38 deletions

View File

@ -6,7 +6,6 @@
* of the License at http://www.apache.org/licenses/LICENSE-2.0 * of the License at http://www.apache.org/licenses/LICENSE-2.0
*/ */
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
@ -25,7 +24,7 @@ extern output_module_t module_json_file;
output_module_t* output_modules[] = { output_module_t* output_modules[] = {
&module_csv_file, &module_csv_file,
#ifdef REDIS #ifdef REDIS
//&module_redis, &module_redis,
#endif #endif
#ifdef JSON #ifdef JSON
&module_json_file &module_json_file
@ -33,8 +32,6 @@ output_module_t* output_modules[] = {
// ADD YOUR MODULE HERE // ADD YOUR MODULE HERE
}; };
output_module_t* get_output_module_by_name(const char* name) output_module_t* get_output_module_by_name(const char* name)
{ {
int num_modules = (int) (sizeof(output_modules)/sizeof(output_modules[0])); int num_modules = (int) (sizeof(output_modules)/sizeof(output_modules[0]));

View File

@ -30,9 +30,9 @@ typedef struct output_module {
output_update_cb update; output_update_cb update;
output_update_cb close; output_update_cb close;
output_packet_cb process_ip; output_packet_cb process_ip;
const char *helptext;
} output_module_t; } output_module_t;
output_module_t* get_output_module_by_name(const char*); output_module_t* get_output_module_by_name(const char*);
void print_output_modules(void); void print_output_modules(void);

View File

@ -369,39 +369,6 @@ int main(int argc, char *argv[])
zconf.log_level = args.verbosity_arg; zconf.log_level = args.verbosity_arg;
log_init(stderr, zconf.log_level); log_init(stderr, zconf.log_level);
log_trace("zmap", "zmap main thread started"); log_trace("zmap", "zmap main thread started");
if (args.help_given) {
cmdline_parser_print_help();
exit(EXIT_SUCCESS);
}
if (args.version_given) {
cmdline_parser_print_version();
exit(EXIT_SUCCESS);
}
if (args.list_output_modules_given) {
print_output_modules();
exit(EXIT_SUCCESS);
}
if (args.list_probe_modules_given) {
print_probe_modules();
exit(EXIT_SUCCESS);
}
if (args.config_given || file_exists(args.config_arg)) {
params->initialize = 0;
params->override = 0;
if (cmdline_parser_config_file(args.config_arg, &args, params)
!= 0) {
exit(EXIT_FAILURE);
}
}
if (args.vpn_given) {
zconf.send_ip_pkts = 1;
zconf.gw_mac_set = 1;
memset(zconf.gw_mac, 0, IFHWADDRLEN);
}
if (cmdline_parser_required(&args, CMDLINE_PARSER_PACKAGE) != 0) {
exit(EXIT_FAILURE);
}
// parse the provided probe and output module s.t. that we can support // parse the provided probe and output module s.t. that we can support
// other command-line helpers (e.g. probe help) // other command-line helpers (e.g. probe help)
if (!args.output_module_given) { if (!args.output_module_given) {
@ -451,6 +418,51 @@ int main(int argc, char *argv[])
CMDLINE_PARSER_PACKAGE, args.probe_module_arg); CMDLINE_PARSER_PACKAGE, args.probe_module_arg);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (args.help_given) {
cmdline_parser_print_help();
printf("\nselected probe-module (%s) help\n", zconf.probe_module->name);
if (zconf.probe_module->helptext) {
printf("%s\n", zconf.probe_module->helptext);
} else {
printf("no help text available\n");
}
printf("\nselected output-module help\n");
if (zconf.output_module->helptext) {
printf("%s\n", zconf.output_module->helptext);
} else {
printf("no help text available\n");
}
exit(EXIT_SUCCESS);
}
if (args.version_given) {
cmdline_parser_print_version();
exit(EXIT_SUCCESS);
}
if (args.list_output_modules_given) {
print_output_modules();
exit(EXIT_SUCCESS);
}
if (args.list_probe_modules_given) {
print_probe_modules();
exit(EXIT_SUCCESS);
}
if (args.config_given || file_exists(args.config_arg)) {
params->initialize = 0;
params->override = 0;
if (cmdline_parser_config_file(args.config_arg, &args, params)
!= 0) {
exit(EXIT_FAILURE);
}
}
if (args.vpn_given) {
zconf.send_ip_pkts = 1;
zconf.gw_mac_set = 1;
memset(zconf.gw_mac, 0, IFHWADDRLEN);
}
if (cmdline_parser_required(&args, CMDLINE_PARSER_PACKAGE) != 0) {
exit(EXIT_FAILURE);
}
// now that we know the probe module, let's find what it supports // now that we know the probe module, let's find what it supports
memset(&zconf.fsconf, 0, sizeof(struct fieldset_conf)); memset(&zconf.fsconf, 0, sizeof(struct fieldset_conf));
// the set of fields made available to a user is constructed // the set of fields made available to a user is constructed