尝试使用主代码
读取pcap的全局文件头int main()
{
std::ifstream in("test.pcap", std::ifstream::in | std::ifstream::binary);
pcap_header gheader(in);
in.close();
return 0;
}
和以下的gheader构造函数:
pcap_header::pcap_header(std::ifstream& in)
{
in >> magic_number;
in >> version_major;
in >> version_minor;
in >> thiszone;
in >> sigfigs;
in >> snaplen;
in >> network;
// debug
std::cout << std::hex << magic_number << " " << version_major << " " << version_minor << " " << thiszone << " " << sigfigs << " " << snaplen<< " " << network << std::endl;
}
返回的输出是:
0 ffcc 28 75b97220 38369fae fffffffe 75b8413a
而不是:
a1b2c3d4 2 4 0 0 40000 1
答案 0 :(得分:2)
看起来你正在以二进制文件打开文件:std::ifstream::binary
但是读取它就像是一个文本文件。如果是文本文件,请删除std::ifstream::binary
。