#include <string.h>
#include <strings.h>
#include <time.h>
+#include <ctype.h>
#include "mtr.h"
#include "version.h"
}
+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;
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]];