// NewIPEndpoint creates a new IP (v4 or v6) endpoint from a net.IP address. // It returns gopacket.InvalidEndpoint if the IP address is invalid. func NewIPEndpoint(a net.IP) gopacket.Endpoint { switch len(a) { case 4: return gopacket.NewEndpoint(EndpointIPv4, []byte(a)) case 16: return gopacket.NewEndpoint(EndpointIPv6, []byte(a)) } return gopacket.InvalidEndpoint }
import ( "code.google.com/p/gopacket" "encoding/binary" "errors" ) // PPP is the layer for PPP encapsulation headers. type PPP struct { BaseLayer PPPType PPPType } // PPPEndpoint is a singleton endpoint for PPP. Since there is no actual // addressing for the two ends of a PPP connection, we use a singleton value // named 'point' for each endpoint. var PPPEndpoint = gopacket.NewEndpoint(EndpointPPP, nil) // PPPFlow is a singleton flow for PPP. Since there is no actual addressing for // the two ends of a PPP connection, we use a singleton value to represent the // flow for all PPP connections. var PPPFlow = gopacket.NewFlow(EndpointPPP, nil, nil) // LayerType returns LayerTypePPP func (p *PPP) LayerType() gopacket.LayerType { return LayerTypePPP } // LinkFlow returns PPPFlow. func (p *PPP) LinkFlow() gopacket.Flow { return PPPFlow } func decodePPP(data []byte, p gopacket.PacketBuilder) error { ppp := &PPP{} if data[0]&0x1 == 0 {
// NewRUDPPortEndpoint returns an endpoint based on a RUDP port. func NewRUDPPortEndpoint(p RUDPPort) gopacket.Endpoint { return gopacket.NewEndpoint(EndpointRUDPPort, []byte{byte(p)}) }
func newPortEndpoint(t gopacket.EndpointType, p uint16) gopacket.Endpoint { return gopacket.NewEndpoint(t, []byte{byte(p >> 8), byte(p)}) }
// NewMACEndpoint returns a new MAC address endpoint. func NewMACEndpoint(a net.HardwareAddr) gopacket.Endpoint { return gopacket.NewEndpoint(EndpointMAC, []byte(a)) }
// ForwardEndpoint returns the EthernetCTPForwardData ForwardAddress as an endpoint. func (c *EthernetCTPForwardData) ForwardEndpoint() gopacket.Endpoint { return gopacket.NewEndpoint(EndpointMAC, c.ForwardAddress) }