--- flow-export.c 2003-12-04 09:55:31 +0400 +++ flow-export.c.new 2005-05-05 18:26:12 +0500 @@ -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); @@ -663,8 +663,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); @@ -691,6 +690,7 @@ char *db_host, *db_name, *db_table, *db_user, *db_pwd, *db_tmp, *tmp; int db_port; int len; + int debug; MYSQL mysql; @@ -746,8 +746,9 @@ /* 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) { strcpy (query, "INSERT INTO "); @@ -759,9 +760,8 @@ strcat (query, ")"); if (debug) - fprintf(stderr, "field=%s\n val=%s\n query=%s\n", fields, values, - query); - + 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)); @@ -1168,7 +1168,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; @@ -1199,10 +1199,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; } @@ -1257,28 +1262,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; } @@ -1375,19 +1395,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; }