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.
22 #include "stream3.hpp"
24 Stream3::Stream3(uint32_t id, PcapPkt::L4Proto proto)
25 : m_id(id), m_proto(proto), m_pktCount(0), m_flushCount(0)
29 void Stream3::writeHeader(ofstream *outputFile) const
31 outputFile->write(reinterpret_cast<const char *>(&m_id), sizeof(m_id));
32 outputFile->write(reinterpret_cast<const char *>(&m_flushCount), sizeof(m_flushCount));
35 void Stream3::writePackets(ofstream *outputFile) const
37 for (size_t i = 0; i < m_pkts.size(); ++i)
38 m_pkts[i]->toFile(outputFile);
41 void Stream3::clearPackets()
43 for (size_t i = 0; i < m_pkts.size(); ++i)
49 void Stream3::flush(ofstream *outputFile)
51 writeHeader(outputFile);
52 writePackets(outputFile);
56 void Stream3::addPkt(const PcapPkt& pkt)
58 m_pkts.push_back(new PcapPkt(pkt));
63 Timestamp Stream3::getTimeout() const
65 uint32_t timeoutMinutes = m_proto == PcapPkt::PROTO_UDP? 10 : 5;
67 return Timestamp(timeoutMinutes * 60, 0);
70 uint32_t Stream3::getIDFromMem(uint8_t *mem)
72 return *reinterpret_cast<uint32_t *>(mem);
75 void Stream3::addFromMemory(uint8_t *mem, size_t *len)
80 n_pkts = *reinterpret_cast<uint32_t *>(mem);
81 mem += sizeof(n_pkts);
83 *len = sizeof(m_id) + sizeof(n_pkts);
84 for (uint32_t i = 0; i < n_pkts; ++i) {
86 mem += m_pkts.back()->memSize();
87 *len += m_pkts.back()->memSize();
91 void Stream3::removeAllPackets()