diff -ruN flow-tools-0.68/src/flow-export.c.orig flow-tools-0.68/src/flow-export.c --- flow-tools-0.68/src/flow-export.c.orig 2004-03-31 11:11:14 +0800 +++ flow-tools-0.68/src/flow-export.c 2006-05-23 23:45:50 +0800 @@ -106,7 +106,7 @@ int ftxfield_tocflow(u_int64 xfields, u_int32 *cfmask); int fmt_xfields_val(char *fmt_buf, char *rec, struct fts3rec_offsets *fo, - u_int64 xfields, int quote); + u_int64 xfields, int quote, int ipv4form); int fmt_xfields_type(char *buf, u_int64 xfield); void usage(void); @@ -664,7 +664,7 @@ while ((rec = ftio_read(ftio))) { - len = fmt_xfields_val(fmt_buf, rec, &fo, opt->ft_mask, 0); + len = fmt_xfields_val(fmt_buf, rec, &fo, opt->ft_mask, 0, 0); if (len) printf("%s\n", fmt_buf); @@ -747,7 +747,8 @@ /* foreach flow */ while ((rec = ftio_read(ftio))) { - len = fmt_xfields_val(values, rec, &fo, opt->ft_mask, 1); + bzero(values,sizeof(values)); + len = fmt_xfields_val(values, rec, &fo, opt->ft_mask, 1, 1); /* form SQL query and execute it */ if (len) { @@ -918,7 +919,7 @@ /* foreach flow */ while ((rec = ftio_read(ftio))) { - len = fmt_xfields_val(values, rec, &fo, opt->ft_mask, 1); + len = fmt_xfields_val(values, rec, &fo, opt->ft_mask, 1, 1); /* form SQL query and execute it */ if (len) { @@ -1169,7 +1170,7 @@ int fmt_xfields_val(char *fmt_buf, char *rec, struct fts3rec_offsets *fo, - u_int64 xfields, int quote) + u_int64 xfields, int quote, int ipv4form) { int comma, len; @@ -1200,10 +1201,15 @@ if (xfields & FT_XFIELD_EXADDR) { if (comma) fmt_buf[len++] = ','; - if (quote) fmt_buf[len++] = '"'; - len += fmt_ipv4(fmt_buf+len, *((u_int32*)(rec+fo->exaddr)), - FMT_JUST_LEFT); - if (quote) fmt_buf[len++] = '"'; + if (ipv4form) + len += fmt_uint32(fmt_buf+len, *((u_int32*)(rec+fo->exaddr)), + FMT_JUST_LEFT); + else { + if (quote) fmt_buf[len++] = '"'; + len += fmt_ipv4(fmt_buf+len, *((u_int32*)(rec+fo->exaddr)), + FMT_JUST_LEFT); + if (quote) fmt_buf[len++] = '"'; + } comma = 1; } @@ -1258,28 +1264,43 @@ if (xfields & FT_XFIELD_SRCADDR) { if (comma) fmt_buf[len++] = ','; - if (quote) fmt_buf[len++] = '"'; - len += fmt_ipv4(fmt_buf+len, *((u_int32*)(rec+fo->srcaddr)), - FMT_JUST_LEFT); - if (quote) fmt_buf[len++] = '"'; + if (ipv4form) + len += fmt_uint32(fmt_buf+len, *((u_int32*)(rec+fo->srcaddr)), + FMT_JUST_LEFT); + else { + if (quote) fmt_buf[len++] = '"'; + len += fmt_ipv4(fmt_buf+len, *((u_int32*)(rec+fo->srcaddr)), + FMT_JUST_LEFT); + if (quote) fmt_buf[len++] = '"'; + } comma = 1; } if (xfields & FT_XFIELD_DSTADDR) { if (comma) fmt_buf[len++] = ','; - if (quote) fmt_buf[len++] = '"'; - len += fmt_ipv4(fmt_buf+len, *((u_int32*)(rec+fo->dstaddr)), - FMT_JUST_LEFT); - if (quote) fmt_buf[len++] = '"'; + if (ipv4form) + len += fmt_uint32(fmt_buf+len, *((u_int32*)(rec+fo->dstaddr)), + FMT_JUST_LEFT); + else { + if (quote) fmt_buf[len++] = '"'; + len += fmt_ipv4(fmt_buf+len, *((u_int32*)(rec+fo->dstaddr)), + FMT_JUST_LEFT); + if (quote) fmt_buf[len++] = '"'; + } comma = 1; } if (xfields & FT_XFIELD_NEXTHOP) { if (comma) fmt_buf[len++] = ','; - if (quote) fmt_buf[len++] = '"'; - len += fmt_ipv4(fmt_buf+len, *((u_int32*)(rec+fo->nexthop)), - FMT_JUST_LEFT); - if (quote) fmt_buf[len++] = '"'; + if (ipv4form) + len += fmt_uint32(fmt_buf+len, *((u_int32*)(rec+fo->nexthop)), + FMT_JUST_LEFT); + else { + if (quote) fmt_buf[len++] = '"'; + len += fmt_ipv4(fmt_buf+len, *((u_int32*)(rec+fo->nexthop)), + FMT_JUST_LEFT); + if (quote) fmt_buf[len++] = '"'; + } comma = 1; } @@ -1376,19 +1397,29 @@ if (xfields & FT_XFIELD_PEER_NEXTHOP) { if (comma) fmt_buf[len++] = ','; - if (quote) fmt_buf[len++] = '"'; - len += fmt_ipv4(fmt_buf+len, *((u_int32*)(rec+fo->peer_nexthop)), - FMT_JUST_LEFT); - if (quote) fmt_buf[len++] = '"'; + if (ipv4form) + len += fmt_uint32(fmt_buf+len, *((u_int32*)(rec+fo->peer_nexthop)), + FMT_JUST_LEFT); + else { + if (quote) fmt_buf[len++] = '"'; + len += fmt_ipv4(fmt_buf+len, *((u_int32*)(rec+fo->peer_nexthop)), + FMT_JUST_LEFT); + if (quote) fmt_buf[len++] = '"'; + } comma = 1; } if (xfields & FT_XFIELD_ROUTER_SC) { if (comma) fmt_buf[len++] = ','; - if (quote) fmt_buf[len++] = '"'; - len += fmt_ipv4(fmt_buf+len, *((u_int32*)(rec+fo->router_sc)), - FMT_JUST_LEFT); - if (quote) fmt_buf[len++] = '"'; + if (ipv4form) + len += fmt_uint32(fmt_buf+len, *((u_int32*)(rec+fo->router_sc)), + FMT_JUST_LEFT); + else { + if (quote) fmt_buf[len++] = '"'; + len += fmt_ipv4(fmt_buf+len, *((u_int32*)(rec+fo->router_sc)), + FMT_JUST_LEFT); + if (quote) fmt_buf[len++] = '"'; + } comma = 1; }