working fieldsets without headers
This commit is contained in:
parent
67aa6f0ab0
commit
7674433142
@ -49,7 +49,7 @@ void fs_add_string(fieldset_t *fs, const char *name, char *value, int free_)
|
||||
|
||||
void fs_add_uint64(fieldset_t *fs, const char *name, uint64_t value)
|
||||
{
|
||||
fs_add_word(fs, name, FS_STRING, 0, sizeof(uint64_t), (void*) value);
|
||||
fs_add_word(fs, name, FS_UINT64, 0, sizeof(uint64_t), (void*) value);
|
||||
}
|
||||
|
||||
void fs_add_binary(fieldset_t *fs, const char *name, size_t len,
|
||||
@ -89,9 +89,22 @@ void fs_free(fieldset_t *fs)
|
||||
free(fs);
|
||||
}
|
||||
|
||||
translation_t *fs_generate_fieldset_translation()
|
||||
void fs_generate_fieldset_translation(translation_t *t,
|
||||
fielddefset_t *avail, char** req, int reqlen)
|
||||
{
|
||||
return NULL;
|
||||
memset(t, 0, sizeof(translation_t));
|
||||
if (!t) {
|
||||
log_fatal("fieldset", "unable to allocate memory for translation");
|
||||
}
|
||||
for (int i=0; i < reqlen; i++) {
|
||||
int l = fds_get_index_by_name(avail, req[i]);
|
||||
if (l < 0) {
|
||||
log_fatal("fieldset", "specified field (%s) not "
|
||||
"available in selected "
|
||||
"probe module.", req[i]);
|
||||
}
|
||||
t->translation[t->len++] = l;
|
||||
}
|
||||
}
|
||||
|
||||
fieldset_t *translate_fieldset(fieldset_t *fs, translation_t *t)
|
||||
|
@ -84,7 +84,8 @@ uint64_t fs_get_uint64_by_index(fieldset_t *fs, int index);
|
||||
|
||||
void fs_free(fieldset_t *fs);
|
||||
|
||||
translation_t *fs_generate_fieldset_translation();
|
||||
void fs_generate_fieldset_translation(translation_t *t,
|
||||
fielddefset_t *avail, char** req, int reqlen);
|
||||
|
||||
fieldset_t *translate_fieldset(fieldset_t *fs, translation_t *t);
|
||||
|
||||
|
@ -35,13 +35,14 @@ int csv_init(struct state_conf *conf, fielddefset_t *fds)
|
||||
}
|
||||
}
|
||||
}
|
||||
// add output headers
|
||||
for (int i=0; i < fds->len; i++) {
|
||||
if (i) {
|
||||
fprintf(file, ", ");
|
||||
}
|
||||
fprintf(file, "%s", fds->fielddefs[i].name);
|
||||
}
|
||||
//// add output headers
|
||||
(void)fds;
|
||||
//for (int i=0; i < fds->len; i++) {
|
||||
// if (i) {
|
||||
// fprintf(file, ", ");
|
||||
// }
|
||||
// fprintf(file, "%s", fds->fielddefs[i].name);
|
||||
//}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
@ -76,6 +77,8 @@ int csv_process(fieldset_t *fs)
|
||||
fprintf(file, "%lu", (uint64_t) f->value);
|
||||
} else if (f->type == FS_BINARY) {
|
||||
hex_encode(file, (unsigned char*) f->value, f->len);
|
||||
} else {
|
||||
log_fatal("csv", "received unknown output type");
|
||||
}
|
||||
}
|
||||
fprintf(file, "\n");
|
||||
|
@ -122,10 +122,12 @@ void packet_cb(u_char __attribute__((__unused__)) *user,
|
||||
|
||||
// we need to translate the data provided by the probe module
|
||||
// into a fieldset that can be used by the output module
|
||||
|
||||
fieldset_t *o = translate_fieldset(fs, &zconf.fsconf.translation);
|
||||
if (zconf.output_module && zconf.output_module->process_ip) {
|
||||
zconf.output_module->process_ip(fs);
|
||||
zconf.output_module->process_ip(o);
|
||||
}
|
||||
fs_free(fs);
|
||||
free(o);
|
||||
if (zconf.output_module && zconf.output_module->update
|
||||
&& !(zrecv.success_unique % zconf.output_module->update_interval)) {
|
||||
zconf.output_module->update(&zconf, &zsend, &zrecv);
|
||||
|
@ -27,8 +27,7 @@ struct output_module;
|
||||
struct fieldset_conf {
|
||||
fielddefset_t defs;
|
||||
fielddefset_t outdefs;
|
||||
int *translation;
|
||||
int translation_len;
|
||||
translation_t translation;
|
||||
int success_index;
|
||||
int classification_index;
|
||||
};
|
||||
|
23
src/zmap.c
23
src/zmap.c
@ -44,7 +44,7 @@ pthread_mutex_t recv_ready_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
// splits comma delimited string into char*[]. Does not handle
|
||||
// escaping or complicated setups: designed to process a set
|
||||
// of fields that the user wants output
|
||||
static void fs_split_string(char* in, int *len, char***results)
|
||||
static void split_string(char* in, int *len, char***results)
|
||||
{
|
||||
char** fields = calloc(MAX_FIELDS, sizeof(char*));
|
||||
memset(fields, 0, sizeof(fields));
|
||||
@ -114,7 +114,7 @@ static void *start_mon(__attribute__((unused)) void *arg)
|
||||
#define SI(w,x,y) printf("%s\t%s\t%i\n", w, x, y);
|
||||
#define SD(w,x,y) printf("%s\t%s\t%f\n", w, x, y);
|
||||
#define SU(w,x,y) printf("%s\t%s\t%u\n", w, x, y);
|
||||
#define SLU(w,x,y) printf("%s\t%s\t%lu\n", w, x, (long unsigned int)y);
|
||||
#define SLU(w,x,y) printf("%s\t%s\t%lu\n", w, x, (long unsigned int) y);
|
||||
#define SS(w,x,y) printf("%s\t%s\t%s\n", w, x, y);
|
||||
#define STRTIME_LEN 1024
|
||||
|
||||
@ -333,7 +333,6 @@ int parse_mac(macaddr_t *out, char *in)
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
||||
struct gengetopt_args_info args;
|
||||
struct cmdline_parser_params *params;
|
||||
params = cmdline_parser_params_create();
|
||||
@ -341,17 +340,10 @@ int main(int argc, char *argv[])
|
||||
params->override = 0;
|
||||
params->check_required = 0;
|
||||
|
||||
SET_BOOL(zconf.dryrun, dryrun);
|
||||
SET_BOOL(zconf.quiet, quiet);
|
||||
SET_BOOL(zconf.summary, summary);
|
||||
zconf.cooldown_secs = args.cooldown_time_arg;
|
||||
zconf.senders = args.sender_threads_arg;
|
||||
zconf.log_level = args.verbosity_arg;
|
||||
|
||||
log_init(stderr, zconf.log_level);
|
||||
log_trace("zmap", "zmap main thread started");
|
||||
|
||||
|
||||
if (cmdline_parser_ext(argc, argv, &args, params) != 0) {
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
@ -416,7 +408,6 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
// find the fields we need for the framework
|
||||
zconf.fsconf.success_index =
|
||||
fds_get_index_by_name(fds, (char*) "success");
|
||||
@ -436,7 +427,7 @@ int main(int argc, char *argv[])
|
||||
} else {
|
||||
zconf.raw_output_fields = (char*) "saddr";
|
||||
}
|
||||
fs_split_string(zconf.raw_output_fields, &(zconf.output_fields_len),
|
||||
split_string(zconf.raw_output_fields, &(zconf.output_fields_len),
|
||||
&(zconf.output_fields));
|
||||
for (int i=0; i < zconf.output_fields_len; i++) {
|
||||
log_debug("zmap", "requested output field (%i): %s",
|
||||
@ -445,7 +436,15 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
// generate a translation that can be used to convert output
|
||||
// from a probe module to the input for an output module
|
||||
fs_generate_fieldset_translation(&zconf.fsconf.translation,
|
||||
&zconf.fsconf.defs, zconf.output_fields,
|
||||
zconf.output_fields_len);
|
||||
|
||||
SET_BOOL(zconf.dryrun, dryrun);
|
||||
SET_BOOL(zconf.quiet, quiet);
|
||||
SET_BOOL(zconf.summary, summary);
|
||||
zconf.cooldown_secs = args.cooldown_time_arg;
|
||||
zconf.senders = args.sender_threads_arg;
|
||||
SET_IF_GIVEN(zconf.output_filename, output_file);
|
||||
SET_IF_GIVEN(zconf.blacklist_filename, blacklist_file);
|
||||
SET_IF_GIVEN(zconf.whitelist_filename, whitelist_file);
|
||||
|
@ -56,7 +56,7 @@ const char *gengetopt_args_info_help[] = {
|
||||
" -i, --interface=name Specify network interface to use",
|
||||
"\nAdvanced options:",
|
||||
" -M, --probe-module=name Select probe module (default=`tcp_synscan')",
|
||||
" -O, --output-module=name Select output module (default=`simple_file')",
|
||||
" -O, --output-module=name Select output module (default=`csv')",
|
||||
" --probe-args=args Arguments to pass to probe module",
|
||||
" --output-args=args Arguments to pass to output module",
|
||||
" --list-output-modules List available output modules",
|
||||
@ -189,7 +189,7 @@ void clear_args (struct gengetopt_args_info *args_info)
|
||||
args_info->interface_orig = NULL;
|
||||
args_info->probe_module_arg = gengetopt_strdup ("tcp_synscan");
|
||||
args_info->probe_module_orig = NULL;
|
||||
args_info->output_module_arg = gengetopt_strdup ("simple_file");
|
||||
args_info->output_module_arg = gengetopt_strdup ("csv");
|
||||
args_info->output_module_orig = NULL;
|
||||
args_info->probe_args_arg = NULL;
|
||||
args_info->probe_args_orig = NULL;
|
||||
|
Loading…
Reference in New Issue
Block a user