From 54475cf38329d96e580cc3850273ee0d582ab8c8 Mon Sep 17 00:00:00 2001 From: Vaibhav Bajpai Date: Fri, 3 May 2013 11:29:03 +0200 Subject: [PATCH] updated --csv format: VERSION;TIMESTAMP;HOSTNAME;TTL;ENDPOINT;ASN;PING(ms) --- report.c | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/report.c b/report.c index dea1c421..da1c1e33 100644 --- a/report.c +++ b/report.c @@ -25,6 +25,7 @@ #include #include #include +#include #include "mtr.h" #include "version.h" @@ -323,6 +324,26 @@ void csv_open(void) } +char *trimwhitespace(char *str) { + char *end; + + /* Trim leading space*/ + while(isspace(*str)) str++; + + if(*str == 0) // All spaces? + return str; + + // Trim trailing space + end = str + strlen(str) - 1; + while(end > str && isspace(*end)) end--; + + // Write new null terminator + *(end+1) = 0; + + return str; +} + + void csv_close(void) { int i, j, at, max; @@ -342,8 +363,15 @@ void csv_close(void) snprint_addr(name, sizeof(name), addr); int last = net_last(at); - printf("MTR.%s;%lu;%s;%d;%s;%d", MTR_VERSION, now, Hostname, - at+1, name, last); + if(!ipinfo_no) { + char* fmtinfo = fmt_ipinfo(addr); + if (fmtinfo != NULL) fmtinfo = trimwhitespace(fmtinfo); + printf("MTR.%s;%lu;%s;%d;%s;%s;%d", MTR_VERSION, now, Hostname, + at+1, name, fmtinfo, last); + } else { + printf("MTR.%s;%lu;%s;%d;%s;%d", MTR_VERSION, now, Hostname, + at+1, name, last); + } for( i=0; i