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.
18 #include <arpa/inet.h>
20 #include "halfstream.hpp"
22 HalfStream::Action::Part HalfStream::addPkt(const PcapPkt &pkt)
24 const uint32_t pktId = pkts.size();
29 const struct PcapPkt::tcp_hdr *tcp;
31 struct pkt_tuple pt = pkt.parsePkt((const uint8_t **)&tcp, &tmpHdrLen, &l5, &l5Len);
33 if (pt.proto_id == IPPROTO_TCP) {
34 if (tcp->tcp_flags & 0x02)
36 if (tcp->tcp_flags & 0x01)
43 memcpy(hdr, pkt.payload(), hdrLen);
51 return Action::Part(pktId, l5 - pkt.payload(), l5Len);
54 double HalfStream::getRate() const
61 return totLen / (last - first);
64 HalfStream::Action::Action(HalfStream* stream, const Part &p, bool isClient)
65 : halfStream(stream), m_isClient(isClient)
70 void HalfStream::Action::addPart(const Part &p)
75 uint32_t HalfStream::Action::totLen() const
79 for (list<Part>::const_iterator i = parts.begin(); i != parts.end(); ++i) {
86 void HalfStream::Action::toFile(ofstream *f) const
88 for (list<Part>::const_iterator i = parts.begin(); i != parts.end(); ++i) {
89 const PcapPkt &pkt = halfStream->pkts[i->pktId];
90 const uint8_t *payload = &pkt.payload()[i->offset];
91 const uint16_t len = i->len;
93 f->write((const char *)payload, len);
97 HalfStream::HalfStream()
98 : first(0, 0), last(0, 0), totLen(0), hdrLen(0), contentLen(0), tcpOpen(false), tcpClose(false)