From 36564d8bb563ffade87421d0dbf85a2e03a4c127 Mon Sep 17 00:00:00 2001 From: HD Moore Date: Sat, 17 Aug 2013 14:44:29 -0500 Subject: [PATCH] Add module names and gw mac address to output --- src/output_modules/module_json.c | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/src/output_modules/module_json.c b/src/output_modules/module_json.c index c9be429..202cca1 100644 --- a/src/output_modules/module_json.c +++ b/src/output_modules/module_json.c @@ -25,6 +25,7 @@ #include "../../lib/logger.h" #include "output_modules.h" +#include "../probe_modules/probe_modules.h" static FILE *file = NULL; #define UNUSED __attribute__((unused)) @@ -34,6 +35,9 @@ static FILE *file = NULL; int json_output_file_init(struct state_conf *conf) { + int i; + char mac_buf[ (IFHWADDRLEN * 2) + (IFHWADDRLEN - 1) + 1 ]; + char *p; json_object *obj = json_object_new_object(); assert(conf); @@ -65,17 +69,27 @@ int json_output_file_init(struct state_conf *conf) json_object_object_add(obj, "use_seed", json_object_new_int(conf->use_seed)); json_object_object_add(obj, "seed", json_object_new_int(conf->seed)); json_object_object_add(obj, "generator", json_object_new_int(conf->generator)); - json_object_object_add(obj, "packet_streams", json_object_new_int(conf->packet_streams)); - - //json_object_object_add(obj, "probe_module", json_object_new_string(conf->probe_module->name)); - //json_object_object_add(obj, "output_module", json_object_new_string(conf->output_module->name)); - + json_object_object_add(obj, "probe_module", json_object_new_string(((probe_module_t *)conf->probe_module)->name)); + json_object_object_add(obj, "output_module", json_object_new_string(((output_module_t *)conf->output_module)->name)); + if (conf->probe_args) json_object_object_add(obj, "probe_args", json_object_new_string(conf->probe_args)); if (conf->output_args) json_object_object_add(obj, "output_args", json_object_new_string(conf->output_args)); - // macaddr_t gw_mac[IFHWADDRLEN]; - //json_object_object_add(obj, "gw_mac", json_object_new_string(conf->gw_mac)); + if (conf->gw_mac) { + memset(mac_buf, 0, sizeof(mac_buf)); + p = mac_buf; + for(i=0; i < IFHWADDRLEN; i++) { + if (i == IFHWADDRLEN-1) { + snprintf(p, 3, "%.2x", conf->gw_mac[i]); + p += 2; + } else { + snprintf(p, 4, "%.2x:", conf->gw_mac[i]); + p += 3; + } + } + json_object_object_add(obj, "gw_mac", json_object_new_string(mac_buf)); + } json_object_object_add(obj, "source_ip_first", json_object_new_string(conf->source_ip_first)); json_object_object_add(obj, "source_ip_last", json_object_new_string(conf->source_ip_last));