Ejemplo n.º 1
0
// Return the first layer of the given type in the packet. If no suitable layer
// is found, return nil.
func FindLayer(p packet.Packet, layer packet.Type) packet.Packet {
	switch {
	case p == nil:
		return nil

	case p.GetType() == layer:
		return p

	default:
		return FindLayer(p.Payload(), layer)
	}
}
Ejemplo n.º 2
0
func (p *Packet) Answers(other packet.Packet) bool {
	if other == nil || other.GetType() != packet.Eth {
		return false
	}

	if p.Type != other.(*Packet).Type {
		return false
	}

	if p.Payload() != nil {
		return p.Payload().Answers(other.Payload())
	}

	return true
}
Ejemplo n.º 3
0
func (p *Packet) Answers(other packet.Packet) bool {
	if other == nil {
		return false
	}

	if other.GetType() == packet.VLAN &&
		p.VLAN != other.(*Packet).VLAN {
		return false
	}

	if p.Payload() != nil {
		return p.Payload().Answers(other.Payload())
	}

	return true
}
Ejemplo n.º 4
0
func (p *Packet) Answers(other packet.Packet) bool {
	if other == nil || other.GetType() != packet.IPv6 {
		return false
	}

	/* TODO: check link-local broadcast addresses */
	if !p.DstAddr.Equal(other.(*Packet).SrcAddr) {
		return false
	}

	/* TODO: check ICMPv6 errors */

	if p.Payload() != nil {
		return p.Payload().Answers(other.Payload())
	}

	return true
}
Ejemplo n.º 5
0
func (p *Packet) Answers(other packet.Packet) bool {
	if other == nil || other.GetType() != packet.IPv4 {
		return false
	}

	if p.Payload() != nil &&
		p.Payload().GetType() == packet.ICMPv4 &&
		p.Payload().Payload() != nil {
		return p.Payload().Payload().Equals(other)
	}

	if !p.SrcAddr.Equal(other.(*Packet).DstAddr) ||
		p.Protocol != other.(*Packet).Protocol {
		return false
	}

	if p.Payload() != nil {
		return p.Payload().Answers(other.Payload())
	}

	return true
}