diff options
| author | luwenpeng <[email protected]> | 2024-08-20 19:29:31 +0800 |
|---|---|---|
| committer | luwenpeng <[email protected]> | 2024-08-20 19:43:57 +0800 |
| commit | 6e46dbf762da2b49305ee5c7a2dc686c91c43880 (patch) | |
| tree | d9d95fa88cabb18c107f0e668bb475adcf35786a | |
| parent | b46a5d4b23f1eddb7dc5ebebff7e2523fc229fe5 (diff) | |
feature: dumpfile list mode support read pcap file path from stdin
| -rw-r--r-- | src/packet_io/dumpfile_io.cpp | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/src/packet_io/dumpfile_io.cpp b/src/packet_io/dumpfile_io.cpp index a16a217..d19585c 100644 --- a/src/packet_io/dumpfile_io.cpp +++ b/src/packet_io/dumpfile_io.cpp @@ -136,15 +136,24 @@ static void *dumpfile_thread(void *arg) } else // PACKET_IO_DUMPFILELIST { - FILE *fp = fopen(handle->dumpfile_path, "r"); - if (fp == NULL) + FILE *fp = NULL; + if (strcmp(handle->dumpfile_path, "-") == 0) { - PACKET_IO_LOG_ERROR("unable to open dumpfile list: %s", handle->dumpfile_path); - goto erro_out; + PACKET_IO_LOG_ERROR("dumpfile list is empty"); + fp = stdin; + } + else + { + fp = fopen(handle->dumpfile_path, "r"); + if (fp == NULL) + { + PACKET_IO_LOG_ERROR("unable to open dumpfile list: %s", handle->dumpfile_path); + goto erro_out; + } } char line[PATH_MAX]; - while (fgets(line, sizeof(line), fp)) + while (ATOMIC_READ(&handle->io_thread_need_exit) == 0 && fgets(line, sizeof(line), fp)) { if (line[0] == '#') { @@ -159,7 +168,10 @@ static void *dumpfile_thread(void *arg) dumpfile_handler(handle, line); } - fclose(fp); + if (fp != stdin) + { + fclose(fp); + } } erro_out: |
