View | Details | Raw Unified | Return to bug 6790
Collapse All | Expand All

(-)flow-export.c (-33 / +63 lines)
Lines 106-112 Link Here
106
int ftxfield_tocflow(u_int64 xfields, u_int32 *cfmask);
106
int ftxfield_tocflow(u_int64 xfields, u_int32 *cfmask);
107
107
108
int fmt_xfields_val(char *fmt_buf, char *rec, struct fts3rec_offsets *fo,
108
int fmt_xfields_val(char *fmt_buf, char *rec, struct fts3rec_offsets *fo,
109
  u_int64 xfields, int quote);
109
  u_int64 xfields, int quote, int ipv4form);
110
int fmt_xfields_type(char *buf, u_int64 xfield);
110
int fmt_xfields_type(char *buf, u_int64 xfield);
111
111
112
void usage(void);
112
void usage(void);
Lines 663-670 Link Here
663
663
664
  while ((rec = ftio_read(ftio))) {
664
  while ((rec = ftio_read(ftio))) {
665
665
666
    len = fmt_xfields_val(fmt_buf, rec, &fo, opt->ft_mask, 0);
666
    len = fmt_xfields_val(fmt_buf, rec, &fo, opt->ft_mask, 0, 0);
667
668
    if (len)
667
    if (len)
669
      printf("%s\n", fmt_buf);
668
      printf("%s\n", fmt_buf);
670
669
Lines 691-696 Link Here
691
  char *db_host, *db_name, *db_table, *db_user, *db_pwd, *db_tmp, *tmp;
690
  char *db_host, *db_name, *db_table, *db_user, *db_pwd, *db_tmp, *tmp;
692
  int db_port;
691
  int db_port;
693
  int len;
692
  int len;
693
  int debug; 
694
694
695
  MYSQL mysql;
695
  MYSQL mysql;
696
696
Lines 746-753 Link Here
746
  /* foreach flow */
746
  /* foreach flow */
747
  while ((rec = ftio_read(ftio))) {
747
  while ((rec = ftio_read(ftio))) {
748
748
749
    len = fmt_xfields_val(values, rec, &fo, opt->ft_mask, 1);
749
    bzero(values,sizeof(values));
750
750
    len = fmt_xfields_val(values, rec, &fo, opt->ft_mask, 1,1);
751
    
751
    /* form SQL query and execute it */
752
    /* form SQL query and execute it */
752
    if (len) {
753
    if (len) {
753
      strcpy (query, "INSERT INTO ");
754
      strcpy (query, "INSERT INTO ");
Lines 759-767 Link Here
759
      strcat (query, ")");
760
      strcat (query, ")");
760
761
761
      if (debug)
762
      if (debug)
762
        fprintf(stderr, "field=%s\n val=%s\n query=%s\n", fields, values,
763
        fprintf(stderr, "field=%s\n val=%s\n query=%s\n", fields, values, query);
763
          query);
764
      
764
765
      if (mysql_real_query(&mysql, query, strlen(query)) != 0) 
765
      if (mysql_real_query(&mysql, query, strlen(query)) != 0) 
766
        fterr_warnx("mysql_real_query(): %s", mysql_error(&mysql));
766
        fterr_warnx("mysql_real_query(): %s", mysql_error(&mysql));
767
767
Lines 1168-1174 Link Here
1168
1168
1169
1169
1170
int fmt_xfields_val(char *fmt_buf, char *rec, struct fts3rec_offsets *fo,
1170
int fmt_xfields_val(char *fmt_buf, char *rec, struct fts3rec_offsets *fo,
1171
  u_int64 xfields, int quote)
1171
  u_int64 xfields, int quote, int ipv4form)
1172
{
1172
{
1173
  int comma, len;
1173
  int comma, len;
1174
1174
Lines 1199-1208 Link Here
1199
1199
1200
  if (xfields & FT_XFIELD_EXADDR) {
1200
  if (xfields & FT_XFIELD_EXADDR) {
1201
    if (comma) fmt_buf[len++] = ',';
1201
    if (comma) fmt_buf[len++] = ',';
1202
    if (quote) fmt_buf[len++] = '"';
1202
    if (ipv4form)
1203
    len += fmt_ipv4(fmt_buf+len, *((u_int32*)(rec+fo->exaddr)),
1203
      len += fmt_uint32(fmt_buf+len, *((u_int32*)(rec+fo->exaddr)),
1204
      FMT_JUST_LEFT);
1204
       FMT_JUST_LEFT);
1205
    if (quote) fmt_buf[len++] = '"';
1205
    else {
1206
       if (quote) fmt_buf[len++] = '"';
1207
       len += fmt_ipv4(fmt_buf+len, *((u_int32*)(rec+fo->exaddr)),
1208
         FMT_JUST_LEFT);
1209
       if (quote) fmt_buf[len++] = '"';
1210
    }
1206
    comma = 1;
1211
    comma = 1;
1207
  }
1212
  }
1208
1213
Lines 1257-1284 Link Here
1257
1262
1258
  if (xfields & FT_XFIELD_SRCADDR) {
1263
  if (xfields & FT_XFIELD_SRCADDR) {
1259
    if (comma) fmt_buf[len++] = ',';
1264
    if (comma) fmt_buf[len++] = ',';
1260
    if (quote) fmt_buf[len++] = '"';
1265
    if (ipv4form)
1261
    len += fmt_ipv4(fmt_buf+len, *((u_int32*)(rec+fo->srcaddr)),
1266
      len += fmt_uint32(fmt_buf+len, *((u_int32*)(rec+fo->srcaddr)),
1262
      FMT_JUST_LEFT);
1267
       FMT_JUST_LEFT);
1263
    if (quote) fmt_buf[len++] = '"';
1268
    else {
1269
       if (quote) fmt_buf[len++] = '"';
1270
       len += fmt_ipv4(fmt_buf+len, *((u_int32*)(rec+fo->srcaddr)),
1271
         FMT_JUST_LEFT);
1272
       if (quote) fmt_buf[len++] = '"';
1273
    }
1264
    comma = 1;
1274
    comma = 1;
1265
  }
1275
  }
1266
1276
1267
  if (xfields & FT_XFIELD_DSTADDR) {
1277
  if (xfields & FT_XFIELD_DSTADDR) {
1268
    if (comma) fmt_buf[len++] = ',';
1278
    if (comma) fmt_buf[len++] = ',';
1269
    if (quote) fmt_buf[len++] = '"';
1279
    if (ipv4form)
1270
    len += fmt_ipv4(fmt_buf+len, *((u_int32*)(rec+fo->dstaddr)),
1280
      len += fmt_uint32(fmt_buf+len, *((u_int32*)(rec+fo->dstaddr)),
1271
      FMT_JUST_LEFT);
1281
       FMT_JUST_LEFT);
1272
    if (quote) fmt_buf[len++] = '"';
1282
    else {
1283
       if (quote) fmt_buf[len++] = '"';
1284
       len += fmt_ipv4(fmt_buf+len, *((u_int32*)(rec+fo->dstaddr)),
1285
         FMT_JUST_LEFT);
1286
       if (quote) fmt_buf[len++] = '"';
1287
    }
1273
    comma = 1;
1288
    comma = 1;
1274
  }
1289
  }
1275
1290
1276
  if (xfields & FT_XFIELD_NEXTHOP) {
1291
  if (xfields & FT_XFIELD_NEXTHOP) {
1277
    if (comma) fmt_buf[len++] = ',';
1292
    if (comma) fmt_buf[len++] = ',';
1278
    if (quote) fmt_buf[len++] = '"';
1293
    if (ipv4form)
1279
    len += fmt_ipv4(fmt_buf+len, *((u_int32*)(rec+fo->nexthop)),
1294
      len += fmt_uint32(fmt_buf+len, *((u_int32*)(rec+fo->nexthop)),
1280
      FMT_JUST_LEFT);
1295
       FMT_JUST_LEFT);
1281
    if (quote) fmt_buf[len++] = '"';
1296
    else {
1297
       if (quote) fmt_buf[len++] = '"';
1298
       len += fmt_ipv4(fmt_buf+len, *((u_int32*)(rec+fo->nexthop)),
1299
         FMT_JUST_LEFT);
1300
       if (quote) fmt_buf[len++] = '"';
1301
    }
1282
    comma = 1;
1302
    comma = 1;
1283
  }
1303
  }
1284
1304
Lines 1375-1393 Link Here
1375
1395
1376
  if (xfields & FT_XFIELD_PEER_NEXTHOP) {
1396
  if (xfields & FT_XFIELD_PEER_NEXTHOP) {
1377
    if (comma) fmt_buf[len++] = ',';
1397
    if (comma) fmt_buf[len++] = ',';
1378
    if (quote) fmt_buf[len++] = '"';
1398
    if (ipv4form)
1379
    len += fmt_ipv4(fmt_buf+len, *((u_int32*)(rec+fo->peer_nexthop)),
1399
      len += fmt_uint32(fmt_buf+len, *((u_int32*)(rec+fo->peer_nexthop)),
1380
      FMT_JUST_LEFT);
1400
       FMT_JUST_LEFT);
1381
    if (quote) fmt_buf[len++] = '"';
1401
    else {
1402
       if (quote) fmt_buf[len++] = '"';
1403
       len += fmt_ipv4(fmt_buf+len, *((u_int32*)(rec+fo->peer_nexthop)),
1404
         FMT_JUST_LEFT);
1405
       if (quote) fmt_buf[len++] = '"';
1406
    }
1382
    comma = 1;
1407
    comma = 1;
1383
  }
1408
  }
1384
1409
1385
  if (xfields & FT_XFIELD_ROUTER_SC) {
1410
  if (xfields & FT_XFIELD_ROUTER_SC) {
1386
    if (comma) fmt_buf[len++] = ',';
1411
    if (comma) fmt_buf[len++] = ',';
1387
    if (quote) fmt_buf[len++] = '"';
1412
    if (ipv4form)
1388
    len += fmt_ipv4(fmt_buf+len, *((u_int32*)(rec+fo->router_sc)),
1413
      len += fmt_uint32(fmt_buf+len, *((u_int32*)(rec+fo->router_sc)),
1389
      FMT_JUST_LEFT);
1414
       FMT_JUST_LEFT);
1390
    if (quote) fmt_buf[len++] = '"';
1415
    else {
1416
       if (quote) fmt_buf[len++] = '"';
1417
       len += fmt_ipv4(fmt_buf+len, *((u_int32*)(rec+fo->router_sc)),
1418
         FMT_JUST_LEFT);
1419
       if (quote) fmt_buf[len++] = '"';
1420
    }
1391
    comma = 1;
1421
    comma = 1;
1392
  }
1422
  }
1393
1423

Return to bug 6790