--- src/flow-export.c.orig Fri Aug 8 11:21:44 2003 +++ src/flow-export.c Fri Aug 8 12:09:42 2003 @@ -90,6 +90,7 @@ u_int32 cflowd_mask; u_int64 ft_mask; u_long records; + int debug; }; struct jump { @@ -143,6 +144,7 @@ case 'd': /* debug */ debug = atoi(optarg); + opt.debug = debug; break; case 'f': /* format */ @@ -757,7 +759,9 @@ strcat (query, ") VALUES ("); strcat (query, values); strcat (query, ")"); -printf("field=%s\n val=%s\n query=%s\n", fields, values, query); + + if (opt->debug) + fprintf(stderr,"field=%s\n val=%s\n query=%s\n", fields, values, query); if (mysql_real_query(&mysql, query, strlen(query)) != 0) fterr_warnx("mysql_real_query(): %s", mysql_error(&mysql)); @@ -925,7 +929,9 @@ strcat (query, ") VALUES ("); strcat (query, values); strcat (query, ")"); - printf("field=%s\n val=%s\n query=%s\n", fields, values, query); + + if (opt->debug) + fprintf(stderr,"field=%s\n val=%s\n query=%s\n", fields, values, query); res = PQexec(conn, query); if (!res || PQresultStatus(res) != PGRES_COMMAND_OK) { @@ -954,11 +960,12 @@ int fmt_xfields_type(char *buf, u_int64 xfield) { - int comma; + int comma=0; buf[0] = 0; if (xfield & FT_XFIELD_UNIX_SECS) { + if (comma) strcat(buf, ","); strcat(buf, FT_XFIELD_ASC_UNIX_SECS); comma = 1; } @@ -1193,10 +1200,10 @@ if (xfields & FT_XFIELD_EXADDR) { if (comma) fmt_buf[len++] = ','; - if (quote) fmt_buf[len++] = '"'; + fmt_buf[len++] = '"'; len += fmt_ipv4(fmt_buf+len, *((u_int32*)(rec+fo->exaddr)), FMT_JUST_LEFT); - if (quote) fmt_buf[len++] = '"'; + fmt_buf[len++] = '"'; comma = 1; } @@ -1251,28 +1258,28 @@ if (xfields & FT_XFIELD_SRCADDR) { if (comma) fmt_buf[len++] = ','; - if (quote) fmt_buf[len++] = '"'; + fmt_buf[len++] = '"'; len += fmt_ipv4(fmt_buf+len, *((u_int32*)(rec+fo->srcaddr)), FMT_JUST_LEFT); - if (quote) fmt_buf[len++] = '"'; + fmt_buf[len++] = '"'; comma = 1; } if (xfields & FT_XFIELD_DSTADDR) { if (comma) fmt_buf[len++] = ','; - if (quote) fmt_buf[len++] = '"'; + fmt_buf[len++] = '"'; len += fmt_ipv4(fmt_buf+len, *((u_int32*)(rec+fo->dstaddr)), FMT_JUST_LEFT); - if (quote) fmt_buf[len++] = '"'; + fmt_buf[len++] = '"'; comma = 1; } if (xfields & FT_XFIELD_NEXTHOP) { if (comma) fmt_buf[len++] = ','; - if (quote) fmt_buf[len++] = '"'; + fmt_buf[len++] = '"'; len += fmt_ipv4(fmt_buf+len, *((u_int32*)(rec+fo->nexthop)), FMT_JUST_LEFT); - if (quote) fmt_buf[len++] = '"'; + fmt_buf[len++] = '"'; comma = 1; } @@ -1369,19 +1376,19 @@ if (xfields & FT_XFIELD_PEER_NEXTHOP) { if (comma) fmt_buf[len++] = ','; - if (quote) fmt_buf[len++] = '"'; + fmt_buf[len++] = '"'; len += fmt_ipv4(fmt_buf+len, *((u_int32*)(rec+fo->peer_nexthop)), FMT_JUST_LEFT); - if (quote) fmt_buf[len++] = '"'; + fmt_buf[len++] = '"'; comma = 1; } if (xfields & FT_XFIELD_ROUTER_SC) { if (comma) fmt_buf[len++] = ','; - if (quote) fmt_buf[len++] = '"'; + fmt_buf[len++] = '"'; len += fmt_ipv4(fmt_buf+len, *((u_int32*)(rec+fo->router_sc)), FMT_JUST_LEFT); - if (quote) fmt_buf[len++] = '"'; + fmt_buf[len++] = '"'; comma = 1; } @@ -1413,6 +1420,9 @@ comma = 1; } + /* forgot to terminate string */ + fmt_buf[len++] = '\0'; + return strlen(fmt_buf); } /* fmt_xfields_val */