Skip to content

Commit

Permalink
updated --csv format: VERSION;TIMESTAMP;HOSTNAME;TTL;ENDPOINT;ASN;PIN…
Browse files Browse the repository at this point in the history
…G(ms)
  • Loading branch information
vbajpai authored and rewolff committed May 13, 2013
1 parent 552a298 commit 54475cf
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions report.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <string.h>
#include <strings.h>
#include <time.h>
#include <ctype.h>

#include "mtr.h"
#include "version.h"
Expand Down Expand Up @@ -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;
Expand All @@ -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]];
Expand Down

0 comments on commit 54475cf

Please sign in to comment.