我有一个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
任何帮助,将不胜感激。

非常感谢你。

最佳答案



您应该在管道中写入pcap filepcap-ng file,而不是fprintfing一些东西。

这些文件格式均为二进制。如果您要构造自己的数据包,则必须先构造有效的pcap文件头或几个有效的pcap-ng块并​​将其写入管道(部分头块和至少一个Interface Description块),然后才能写入任何数据包,然后,对于每个数据包,您必须在原始数据包数据之前(对于扩展模块,则在之后)写入每个数据包的pcap header 或pcap-ng增强数据包块的开头和结尾。如果您只是将现有文件发送到Wireshark,则需要从文件中读取原始字节,然后将这些原始字节发送到管道中。

关于c++ - 打开期间管道魔术文件的结尾,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/17966065/

10-10 22:32
查看更多