I have a pcap file captured by wireshark, now I need to read each packet of it and write them to a vector of structure. I got some promblem with writing packets into the structure. the structure:
struct pktStruct {
struct pcap_pkthdr * pkt_header; // header object
const u_char * pkt_data; // data object
long time; // used to compare with each other
};
the code how I save each packet to structure:
string resultFile = "/home/xing/Desktop/tmp.pcap";
char errbuff[PCAP_ERRBUF_SIZE];
pcap_t * resultPcap = pcap_open_offline(resultFile.c_str(), errbuff);
struct pcap_pkthdr * header; // header object
const u_char * data; // data object
vector<pktStruct> pktVector; // this vector contains each pktStruct
pktStruct myStruct;
while (int i=pcap_next_ex(resultPcap,&header,&data) >=0) {
myStruct.pkt_header = header;
myStruct.pkt_data = data;
myStruct.time = header->ts.tv_sec * 1000000 + header->ts.tv_usec;
pktVector.push_back(myStruct);
}
when I printed each packet's information I found each structure which stored a packet is totally the same. did I save the same packet to each structure of the vector?