Example #1
0
File: pcap.go Project: sebkl/CAT_TP
// NewPacket creates a new cattp packet based on an existing pcap packet. Error is returned if
// the pcap packet is not a cattp packet.
func NewPacket(p *pcap.Packet) (ret *Packet, err error) {
	p.Decode()

	ret = &Packet{}

	//find lower header
	for _, h := range p.Headers {
		if ih, ok := h.(*pcap.Iphdr); ok {
			ret.ip = ih
		}

		if uh, ok := h.(*pcap.Udphdr); ok {
			ret.udp = uh
		}
	}

	// assert whether is udp datagram
	if ret.ip == nil || ret.udp == nil {
		return nil, fmt.Errorf("Not a udp packet.")
	}

	//Parse the cattp header
	hdr, err := NewHeader(p.Payload)
	if err != nil {
		return
	}
	ret.Header = *hdr
	return
}
Example #2
0
func (s SourceMap) process(pkt *pcap.Packet) {
	pkt.Decode()

	if len(pkt.Headers) >= 2 {
		if addr, ok := pkt.Headers[0].(addrHdr); ok {
			s.route(pkt, &addr)
		}
	}
}