[英]WinPcap creating empty .pcap file
Do you know how to create empty file pcap with winpcap dll?你知道如何使用 winpcap dll 创建空文件 pcap 吗? I buffer filtered packets in program memory and want to save when user click to export to.pcap file.
我在程序 memory 中缓冲过滤后的数据包,并希望在用户单击导出到.pcap 文件时保存。
But when using pcap_open_offline(const char *fname, char *errbuf) can open file only if file exists.但是当使用 pcap_open_offline(const char *fname, char *errbuf) 时,只有当文件存在时才能打开文件。 I tried fopen and other functions to create file previously (in binary mode too) but unsucessfully.
我以前尝试过 fopen 和其他功能来创建文件(也以二进制模式)但没有成功。
So how to get pcap_t handle pointer for pcap_dump_open(pcap_t *p, const char *fname) this way?那么如何以这种方式获取 pcap_dump_open(pcap_t *p, const char *fname) 的 pcap_t 句柄指针呢?
UPDATED: I try to use this code更新:我尝试使用此代码
fileHandle = pcap_open_offline(pcap_file_path.c_str(), errbuf);
if (errbuf == nullptr) {
fprintf(stderr, "\nUnable to open the file %s.\n", pcap_file_path.c_str());
return 1;
}
if (fileHandle == nullptr) {
fprintf(stderr, "\nError to open file\n");//HERE IT FAILS
return 1;
}
dumpfile = pcap_dump_open(fileHandle, pcap_file_path.c_str());
if (dumpfile == NULL)
{
fprintf(stderr, "\nError opening output file\n");
return 1;
}
SOLUTION: ( Creating a pcap file )解决方案:( 创建一个 pcap 文件)
/*create fake handle*/
fileHandle = pcap_open_dead(DLT_EN10MB, 65535);
if (fileHandle == nullptr) {
fprintf(stderr, "\nError to open file\n");
return 1;
}
/* Open the dump file */
dumpfile = pcap_dump_open(fileHandle, file_path.c_str());
if (dumpfile == NULL)
{
fprintf(stderr, "\nError opening output file\n");
return 1;
}
Do you know how to create empty file pcap with winpcap dll?
你知道如何使用 winpcap dll 创建空文件 pcap 吗? I buffer filtered packets in program memory and want to save when user click to export to.pcap file.
我在程序 memory 中缓冲过滤后的数据包,并希望在用户单击导出到.pcap 文件时保存。
... ...
So how to get pcap_t handle pointer for pcap_dump_open(pcap_t *p, const char *fname) this way?
那么如何以这种方式获取 pcap_dump_open(pcap_t *p, const char *fname) 的 pcap_t 句柄指针呢?
pcap_dump_open()
returns a pcap_dumper_t *
handle for use when writing the file; pcap_dump_open()
返回一个pcap_dumper_t *
句柄供写入文件时使用; a pcap_t *
is used for capturing or reading , not writing . pcap_t *
用于捕获或读取,而不是写入。
What you need to do, if you want to write a pcap file, is use pcap_dump_open()
.如果要编写pcap 文件,您需要做的是使用
pcap_dump_open()
。 If you have a pcap_t *
from which you're reading or capturing the filtered packets, you should use that pcap_t *
in the call to pcap_dump_open()
.如果您有一个
pcap_t *
从中读取或捕获过滤的数据包,您应该在调用pcap_dump_open()
时使用该pcap_t *
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.