我有一个c++应用程序,在该应用程序中,我将启动另一个进程(Wireshark),如下所示。
if (fp == NULL){
fp = popen(processpath, "r"); //processpath is the process I want to start
if (!fp){
throw std::invalid_argument("Cannot start process");
}
fprintf(fp, d_msg);//d_msg is the input I want to provide to process
} else if(fp != NULL){
fprintf(fp, d_msg);
}
问题是,当我执行我的c++应用程序时,它确实启动了wireshark,但是使用了错误的End of File on pipe magic during open
我该怎么做才能避免这种情况?
另外,我尝试使用mkfifo创建一个命名的管道并执行它。我用了这样的方法:
if (fp == NULL){
system("mkfifo /tmp/mine.pcap");
fp = popen("wireshark -k -i /tmp/mine.pcap", "r");
if (!fp){
dout << "Cannot start wireshark"<<std::endl;
throw std::invalid_argument("Cannot start wireshark");
}
input = fopen("/tmp/mine.pcap", "wb");
fprintf(input , d_msg);
fclose(input);
} else if(fp != NULL){
input = fopen("/tmp/mine.pcap", "wb");
fprintf(input , d_msg);
fclose(input);
}
但这也没用。有了这个,我得到了以下错误:
The file "/tmp/wireshark_mine.pcap_20130730012654_ndbFzk" is a capture for a network type that Wireshark doesn't support
任何帮助都将不胜感激。
非常感谢。
发布于 2013-07-31 09:47:09
问题是,当我执行我的c++应用程序时,它确实启动了wireshark,但是使用了错误的
End of File on pipe magic during open
我该怎么做才能避免这种情况?
您应该将一个pcap文件或pcap-ng文件写到管道中,而不是对某个东西进行fprintfing。
这两种文件格式都是二进制的。如果您正在构建您自己的数据包,您必须构造一个有效的pcap文件头或多个有效的pcap块(区段头块和至少一个接口描述块),然后才能编写任何数据包,然后,对于每个数据包,您必须在原始数据包数据之前(以及对于增强块,在后面)编写每个数据包的pcap增强数据包块的开头和结尾。如果您只是将一个现有文件发送到Wireshark,则需要从该文件中读取原始字节并将这些原始字节发送到管道中。
https://stackoverflow.com/questions/17966065
复制相似问题