// NewTCPTuple constructs a TCPTuple from the information in the pkt.Packet
// headers.  This assumes that the packet is a TCP/IP packet.
NewTCPTuple constructs a TCPTuple from the information in the pkt.Packet
headers.  This assumes that the packet is a TCP/IP packet.
// NewTCPTuple constructs a TCPTuple from the information in the pkt . Packet // headers . This assumes that the packet is a TCP / IP packet .
func NewTCPTuple(p *pkt.Packet) (*TCPTuple, error) {
	t := &TCPTuple{
		Src: &net.TCPAddr{},
		Dst: &net.TCPAddr{},
	}
	if p == nil {
		return t, nil
	}
	ipHdr, ok := p.Headers[pkt.NetworkLayer].(pkt.InetProtoHdr)
	if !ok || ipHdr == nil {
		return t, ErrNetworkLayerHeader
	}
	t.Src.IP = ipHdr.Src()
	t.Dst.IP = ipHdr.Dst()
	tcpHdr, ok := p.Headers[pkt.TransportLayer].(*pkt.TcpHdr)
	if !ok || tcpHdr == nil {
		return t, ErrTransportLayerHeader
	}
	t.Src.Port = int(tcpHdr.Source)
	t.Dst.Port = int(tcpHdr.Dest)
	return t, nil
}
func NewTCPTuple ( p * pkt . Packet ) ( * TCPTuple , error ) { t := & TCPTuple { Src : & net . TCPAddr { } , Dst : & net . TCPAddr { } , } if p == nil { return t , nil } ipHdr , ok := p . Headers [ pkt . NetworkLayer ] . ( pkt . InetProtoHdr ) if ! ok || ipHdr == nil { return t , ErrNetworkLayerHeader } t . Src . IP = ipHdr . Src ( ) t . Dst . IP = ipHdr . Dst ( ) tcpHdr , ok := p . Headers [ pkt . TransportLayer ] . ( * pkt . TcpHdr ) if ! ok || tcpHdr == nil { return t , ErrTransportLayerHeader } t . Src . Port = int ( tcpHdr . Source ) t . Dst . Port = int ( tcpHdr . Dest ) return t , nil }
NewTCPTuple constructs a TCPTuple from the information in the pkt.Packet
headers.
NewTCPTuple constructs a TCPTuple from the information in the pkt . Packet headers .