feature: dumpfile list mode support read pcap file path from stdin

This commit is contained in:
luwenpeng
2024-08-20 19:29:31 +08:00
parent b46a5d4b23
commit 6e46dbf762

View File

@@ -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: