]> git.ipfire.org Git - thirdparty/mtr.git/commitdiff
updated --csv format: VERSION;TIMESTAMP;HOSTNAME;TTL;ENDPOINT;ASN;PING(ms)
authorVaibhav Bajpai <contact@vaibhavbajpai.com>
Fri, 3 May 2013 09:29:03 +0000 (11:29 +0200)
committerR.E. Wolff <R.E.Wolff@BitWizard.nl>
Mon, 13 May 2013 15:22:54 +0000 (17:22 +0200)
report.c

index dea1c4217f290e2d18bf9f6d7d512a23416bb846..da1c1e334a35e2ac262d8baf5e34a6eda6354855 100644 (file)
--- a/report.c
+++ b/report.c
@@ -25,6 +25,7 @@
 #include <string.h>
 #include <strings.h>
 #include <time.h>
+#include <ctype.h>
 
 #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<MAXFLD; i++ ) {
       j = fld_index[fld_active[j]];