2 // Copyright (c) 2010-2017 Intel Corporation
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
21 #include "pcapreader.hpp"
23 int PcapReader::open(const string& file_path)
25 char err_str[PCAP_ERRBUF_SIZE];
28 m_error = "Pcap file already open";
32 m_handle = pcap_open_offline_with_tstamp_precision(file_path.c_str(),
33 PCAP_TSTAMP_PRECISION_NANO,
37 m_error = "Failed to open pcap file";
41 m_file_beg = ftell(pcap_file(m_handle));
42 fseek(pcap_file(m_handle), 0, SEEK_END);
43 m_file_end = ftell(pcap_file(m_handle));
44 fseek(pcap_file(m_handle), m_file_beg, SEEK_SET);
49 int PcapReader::readOnce(PcapPkt *pkt, uint64_t pos)
54 int PcapReader::read(PcapPkt *pkt)
57 m_error = "No pcap file opened";
60 const uint8_t *buf = pcap_next(m_handle, &pkt->header);
63 memcpy(pkt->buf, buf, pkt->header.len);
70 void PcapReader::close()