/* * status = readerStart(flow_processor) * * Invoked by input_mode_type->start_fn(); */ static int readerStart( flow_proc_t *fproc) { const char *filename = skpcProbeGetFileSource(fproc->probe); skPDUSource_t *pdu_src; skFlowSourceParams_t params; /* if a pdu_src already exists, just return. */ if (fproc->flow_src != NULL) { return 0; } if (filename == NULL) { ERRMSG("Probe %s not configured for reading from file", skpcProbeGetName(fproc->probe)); return -1; } params.path_name = filename; pdu_src = skPDUSourceCreate(fproc->probe, ¶ms); if (pdu_src == NULL) { ERRMSG("'%s': Could not create PDU source from file '%s'", skpcProbeGetName(fproc->probe), filename); errorDirectoryInsertFile(filename); return -1; } /* zero counts */ fproc->rec_count_total = 0; fproc->rec_count_bad = 0; fproc->flow_src = pdu_src; return 0; }
/* * count = pdu2silk(filename); * * Read PDUs from 'filename' and write records to the global * 'silk_output' file. Return number of records processed, or -1 * on error. */ static int64_t pdu2silk( const char *filename) { static unsigned int file_count = 0; char probe_name[128]; skPDUSource_t *pdu_src; skFlowSourceParams_t params; int64_t count; rwRec rwrec; int rv; ++file_count; snprintf(probe_name, sizeof(probe_name), "input%04u", file_count); params.path_name = filename; skpcProbeSetName(probe, probe_name); pdu_src = skPDUSourceCreate(probe, ¶ms); if (pdu_src == NULL) { return -1; } count = 0; while (-1 != skPDUSourceGetGeneric(pdu_src, &rwrec)) { ++count; rv = skStreamWriteRecord(silk_output, &rwrec); if (rv) { skStreamPrintLastErr(silk_output, rv, &skAppPrintErr); if (SKSTREAM_ERROR_IS_FATAL(rv)) { exit(EXIT_FAILURE); } } } skPDUSourceLogStatsAndClear(pdu_src); skPDUSourceDestroy(pdu_src); return count; }