// AddPacket updates the meta data for a TCPFlow and saves a reference to the
// pkt.Packet.  This assumes the packet addresses have been checked and the TCP
// flow matches (it does not check for matching addresses).
AddPacket updates the meta data for a TCPFlow and saves a reference to the
pkt.Packet.  This assumes the packet addresses have been checked and the TCP
flow matches (it does not check for matching addresses).
// AddPacket updates the meta data for a TCPFlow and saves a reference to the // pkt . Packet . This assumes the packet addresses have been checked and the TCP // flow matches ( it does not check for matching addresses ) .
func (f *TCPFlow) AddPacket(p *pkt.Packet) error {
	ip, ok := p.Headers[pkt.NetworkLayer].(pkt.InetProtoHdr)
	if !ok || ip == nil {
		return ErrNetworkLayerHeader
	}
	tcpHdr, ok := p.Headers[pkt.TransportLayer].(*pkt.TcpHdr)
	if !ok || tcpHdr == nil {
		return ErrTransportLayerHeader
	}
	pt, err := NewTCPTuple(p)
	if err != nil {
		return err
	}
	var downstream = f.TCPTuple.Equal(pt)
	if p.Time.Before(f.StartTime) || f.StartTime.IsZero() {
		f.StartTime = p.Time
		if downstream {
			if f.SrcFirstSeq > tcpHdr.Seq {
				f.SrcFirstSeq = tcpHdr.Seq
			}
			if f.SrcFirstAckSeq > tcpHdr.AckSeq {
				f.SrcFirstAckSeq = tcpHdr.AckSeq
			}
		} else {
			if f.DstFirstSeq > tcpHdr.Seq {
				f.DstFirstSeq = tcpHdr.Seq
			}
			if f.DstFirstAckSeq > tcpHdr.AckSeq {
				f.DstFirstAckSeq = tcpHdr.AckSeq
			}
		}
	}
	if p.Time.After(f.EndTime) || f.EndTime.IsZero() {
		f.EndTime = p.Time
	}
	if downstream {
		f.SrcBytes += int64(tcpHdr.PayloadLen(ip.PL()))
		f.SrcPLBytes += int64(ip.PL())
		f.SrcWireBytes += int64(p.Len)
		f.SrcPktCnt++
		f.SrcData = append(f.SrcData, p)
		f.SrcDataMap[tcpHdr.Seq] = p
	} else {
		f.DstBytes += int64(tcpHdr.PayloadLen(ip.PL()))
		f.DstPLBytes += int64(ip.PL())
		f.DstWireBytes += int64(p.Len)
		f.DstPktCnt++
		f.DstData = append(f.DstData, p)
		f.DstDataMap[tcpHdr.Seq] = p
	}
	f.Data = append(f.Data, p)
	return nil
}
func ( f * TCPFlow ) AddPacket ( p * pkt . Packet ) error { ip , ok := p . Headers [ pkt . NetworkLayer ] . ( pkt . InetProtoHdr ) if ! ok || ip == nil { return ErrNetworkLayerHeader } tcpHdr , ok := p . Headers [ pkt . TransportLayer ] . ( * pkt . TcpHdr ) if ! ok || tcpHdr == nil { return ErrTransportLayerHeader } pt , err := NewTCPTuple ( p ) if err != nil { return err } var downstream = f . TCPTuple . Equal ( pt ) if p . Time . Before ( f . StartTime ) || f . StartTime . IsZero ( ) { f . StartTime = p . Time if downstream { if f . SrcFirstSeq > tcpHdr . Seq { f . SrcFirstSeq = tcpHdr . Seq } if f . SrcFirstAckSeq > tcpHdr . AckSeq { f . SrcFirstAckSeq = tcpHdr . AckSeq } } else { if f . DstFirstSeq > tcpHdr . Seq { f . DstFirstSeq = tcpHdr . Seq } if f . DstFirstAckSeq > tcpHdr . AckSeq { f . DstFirstAckSeq = tcpHdr . AckSeq } } } if p . Time . After ( f . EndTime ) || f . EndTime . IsZero ( ) { f . EndTime = p . Time } if downstream { f . SrcBytes += int64 ( tcpHdr . PayloadLen ( ip . PL ( ) ) ) f . SrcPLBytes += int64 ( ip . PL ( ) ) f . SrcWireBytes += int64 ( p . Len ) f . SrcPktCnt ++ f . SrcData = append ( f . SrcData , p ) f . SrcDataMap [ tcpHdr . Seq ] = p } else { f . DstBytes += int64 ( tcpHdr . PayloadLen ( ip . PL ( ) ) ) f . DstPLBytes += int64 ( ip . PL ( ) ) f . DstWireBytes += int64 ( p . Len ) f . DstPktCnt ++ f . DstData = append ( f . DstData , p ) f . DstDataMap [ tcpHdr . Seq ] = p } f . Data = append ( f . Data , p ) return nil }
AddPacket updates the meta data for a TCPFlow and saves a reference to the
pkt.Packet.
AddPacket updates the meta data for a TCPFlow and saves a reference to the pkt . Packet .