Documentation ¶
Index ¶
- Constants
- Variables
- func NewIPEndpoint(a net.IP) gopacket.Endpoint
- func NewTCPPortEndpoint(p TCPPort) gopacket.Endpoint
- func NewUDPPortEndpoint(p UDPPort) gopacket.Endpoint
- type BaseLayer
- type EnumMetadata
- type IPProtocol
- type IPv4
- func (ip *IPv4) AddressTo4() error
- func (i *IPv4) CanDecode() gopacket.LayerClass
- func (ip *IPv4) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error
- func (i *IPv4) LayerType() gopacket.LayerType
- func (i *IPv4) NetworkFlow() gopacket.Flow
- func (i *IPv4) NextLayerType() gopacket.LayerType
- func (ip *IPv4) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error
- type IPv4Flag
- type IPv4Option
- type IPv6
- func (ipv6 *IPv6) AddressTo16() error
- func (ipv6 *IPv6) CanDecode() gopacket.LayerClass
- func (ipv6 *IPv6) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error
- func (ipv6 *IPv6) LayerType() gopacket.LayerType
- func (ipv6 *IPv6) NetworkFlow() gopacket.Flow
- func (ipv6 *IPv6) NextLayerType() gopacket.LayerType
- func (ipv6 *IPv6) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error
- type IPv6Destination
- type IPv6DestinationOption
- type IPv6ExtensionSkipper
- type IPv6Fragment
- type IPv6HopByHop
- type IPv6HopByHopOption
- type IPv6Routing
- type ProtocolFamily
- type TCP
- func (t *TCP) CanDecode() gopacket.LayerClass
- func (t *TCP) ComputeChecksum() (uint16, error)
- func (tcp *TCP) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error
- func (t *TCP) LayerType() gopacket.LayerType
- func (t *TCP) NextLayerType() gopacket.LayerType
- func (t *TCP) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error
- func (t *TCP) SetInternalPortsForTesting()
- func (i *TCP) SetNetworkLayerForChecksum(l gopacket.NetworkLayer) error
- func (t *TCP) TransportFlow() gopacket.Flow
- type TCPOption
- type TCPOptionKind
- type TCPPort
- type UDP
- func (u *UDP) CanDecode() gopacket.LayerClass
- func (udp *UDP) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error
- func (u *UDP) LayerType() gopacket.LayerType
- func (u *UDP) NextLayerType() gopacket.LayerType
- func (u *UDP) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error
- func (u *UDP) SetInternalPortsForTesting()
- func (i *UDP) SetNetworkLayerForChecksum(l gopacket.NetworkLayer) error
- func (u *UDP) TransportFlow() gopacket.Flow
- type UDPPort
Constants ¶
const ( TCPOptionKindEndList = 0 TCPOptionKindNop = 1 TCPOptionKindMSS = 2 // len = 4 TCPOptionKindWindowScale = 3 // len = 3 TCPOptionKindSACKPermitted = 4 // len = 2 TCPOptionKindSACK = 5 // len = n TCPOptionKindEcho = 6 // len = 6, obsolete TCPOptionKindEchoReply = 7 // len = 6, obsolete TCPOptionKindTimestamps = 8 // len = 10 TCPOptionKindPartialOrderConnectionPermitted = 9 // len = 2, obsolete TCPOptionKindPartialOrderServiceProfile = 10 // len = 3, obsolete TCPOptionKindCC = 11 // obsolete TCPOptionKindCCNew = 12 // obsolete TCPOptionKindCCEcho = 13 // obsolete TCPOptionKindAltChecksum = 14 // len = 3, obsolete TCPOptionKindAltChecksumData = 15 // len = n, obsolete )
const (
// IPv6HopByHopOptionJumbogram code as defined in RFC 2675
IPv6HopByHopOptionJumbogram = 0xC2
)
Variables ¶
var ( // We use two different endpoint types for IPv4 vs IPv6 addresses, so that // ordering with endpointA.LessThan(endpointB) sanely groups all IPv4 // addresses and all IPv6 addresses, such that IPv6 > IPv4 for all addresses. EndpointIPv4 = gopacket.RegisterEndpointType(1, gopacket.EndpointTypeMetadata{Name: "IPv4", Formatter: func(b []byte) string { return net.IP(b).String() }}) EndpointIPv6 = gopacket.RegisterEndpointType(2, gopacket.EndpointTypeMetadata{Name: "IPv6", Formatter: func(b []byte) string { return net.IP(b).String() }}) EndpointTCPPort = gopacket.RegisterEndpointType(4, gopacket.EndpointTypeMetadata{Name: "TCP", Formatter: func(b []byte) string { return strconv.Itoa(int(binary.BigEndian.Uint16(b))) }}) EndpointUDPPort = gopacket.RegisterEndpointType(5, gopacket.EndpointTypeMetadata{Name: "UDP", Formatter: func(b []byte) string { return strconv.Itoa(int(binary.BigEndian.Uint16(b))) }}) )
var ( LayerTypeIPv4 = gopacket.RegisterLayerType(20, gopacket.LayerTypeMetadata{Name: "IPv4", Decoder: gopacket.DecodeFunc(decodeIPv4)}) LayerTypeIPv6 = gopacket.RegisterLayerType(21, gopacket.LayerTypeMetadata{Name: "IPv6", Decoder: gopacket.DecodeFunc(decodeIPv6)}) LayerTypeTCP = gopacket.RegisterLayerType(44, gopacket.LayerTypeMetadata{Name: "TCP", Decoder: gopacket.DecodeFunc(decodeTCP)}) LayerTypeUDP = gopacket.RegisterLayerType(45, gopacket.LayerTypeMetadata{Name: "UDP", Decoder: gopacket.DecodeFunc(decodeUDP)}) LayerTypeIPv6HopByHop = gopacket.RegisterLayerType(46, gopacket.LayerTypeMetadata{Name: "IPv6HopByHop", Decoder: gopacket.DecodeFunc(decodeIPv6HopByHop)}) LayerTypeIPv6Routing = gopacket.RegisterLayerType(47, gopacket.LayerTypeMetadata{Name: "IPv6Routing", Decoder: gopacket.DecodeFunc(decodeIPv6Routing)}) LayerTypeIPv6Fragment = gopacket.RegisterLayerType(48, gopacket.LayerTypeMetadata{Name: "IPv6Fragment", Decoder: gopacket.DecodeFunc(decodeIPv6Fragment)}) LayerTypeIPv6Destination = gopacket.RegisterLayerType(49, gopacket.LayerTypeMetadata{Name: "IPv6Destination", Decoder: gopacket.DecodeFunc(decodeIPv6Destination)}) )
var ( // LayerClassIPNetwork contains TCP/IP network layer types. LayerClassIPNetwork = gopacket.NewLayerClass([]gopacket.LayerType{ LayerTypeIPv4, LayerTypeIPv6, }) // LayerClassIPTransport contains TCP/IP transport layer types. LayerClassIPTransport = gopacket.NewLayerClass([]gopacket.LayerType{ LayerTypeTCP, LayerTypeUDP, }) // LayerClassIPv6Extension contains IPv6 extension headers. LayerClassIPv6Extension = gopacket.NewLayerClass([]gopacket.LayerType{ LayerTypeIPv6HopByHop, LayerTypeIPv6Routing, LayerTypeIPv6Fragment, LayerTypeIPv6Destination, }) )
var IPProtocolMetadata [256]EnumMetadata
var ProtocolFamilyMetadata [256]EnumMetadata
Functions ¶
func NewIPEndpoint ¶
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 NewTCPPortEndpoint ¶
NewTCPPortEndpoint returns an endpoint based on a TCP port.
func NewUDPPortEndpoint ¶
NewUDPPortEndpoint returns an endpoint based on a UDP port.
Types ¶
type BaseLayer ¶
type BaseLayer struct { // Contents is the set of bytes that make up this layer. IE: for an // Ethernet packet, this would be the set of bytes making up the // Ethernet frame. Contents []byte // Payload is the set of bytes contained by (but not part of) this // Layer. Again, to take Ethernet as an example, this would be the // set of bytes encapsulated by the Ethernet protocol. Payload []byte }
BaseLayer is a convenience struct which implements the LayerData and LayerPayload functions of the Layer interface.
func (*BaseLayer) LayerContents ¶
LayerContents returns the bytes of the packet layer.
func (*BaseLayer) LayerPayload ¶
LayerPayload returns the bytes contained within the packet layer.
type EnumMetadata ¶
type EnumMetadata struct { // DecodeWith is the decoder to use to decode this protocol's data. DecodeWith gopacket.Decoder // Name is the name of the enumeration value. Name string // LayerType is the layer type implied by the given enum. LayerType gopacket.LayerType }
EnumMetadata keeps track of a set of metadata for each enumeration value for protocol enumerations.
type IPProtocol ¶
type IPProtocol uint8
IPProtocol is an enumeration of IP protocol values, and acts as a decoder for any type it supports.
const ( IPProtocolIPv6HopByHop IPProtocol = 0 IPProtocolIPv4 IPProtocol = 4 IPProtocolTCP IPProtocol = 6 IPProtocolUDP IPProtocol = 17 IPProtocolIPv6 IPProtocol = 41 IPProtocolIPv6Routing IPProtocol = 43 IPProtocolIPv6Fragment IPProtocol = 44 IPProtocolNoNextHeader IPProtocol = 59 IPProtocolIPv6Destination IPProtocol = 60 )
func (IPProtocol) Decode ¶
func (a IPProtocol) Decode(data []byte, p gopacket.PacketBuilder) error
Decoder calls IPProtocolMetadata.DecodeWith's decoder.
func (IPProtocol) LayerType ¶
func (a IPProtocol) LayerType() gopacket.LayerType
LayerType returns IPProtocolMetadata.LayerType.
func (IPProtocol) String ¶
func (a IPProtocol) String() string
String returns IPProtocolMetadata.Name.
type IPv4 ¶
type IPv4 struct { BaseLayer Version uint8 IHL uint8 TOS uint8 Length uint16 Id uint16 Flags IPv4Flag FragOffset uint16 TTL uint8 Protocol IPProtocol Checksum uint16 SrcIP net.IP DstIP net.IP Options []IPv4Option Padding []byte }
IPv4 is the header of an IP packet.
func (*IPv4) AddressTo4 ¶
func (*IPv4) CanDecode ¶
func (i *IPv4) CanDecode() gopacket.LayerClass
func (*IPv4) DecodeFromBytes ¶
func (ip *IPv4) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error
DecodeFromBytes decodes the given bytes into this layer.
func (*IPv4) NetworkFlow ¶
func (*IPv4) NextLayerType ¶
func (*IPv4) SerializeTo ¶
func (ip *IPv4) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error
SerializeTo writes the serialized form of this layer into the SerializationBuffer, implementing gopacket.SerializableLayer.
type IPv4Flag ¶
type IPv4Flag uint8
const ( IPv4EvilBit IPv4Flag = 1 << 2 // http://tools.ietf.org/html/rfc3514 ;) IPv4DontFragment IPv4Flag = 1 << 1 IPv4MoreFragments IPv4Flag = 1 << 0 )
type IPv4Option ¶
func (IPv4Option) String ¶
func (i IPv4Option) String() string
type IPv6 ¶
type IPv6 struct { // http://www.networksorcery.com/enp/protocol/ipv6.htm BaseLayer Version uint8 TrafficClass uint8 FlowLabel uint32 Length uint16 NextHeader IPProtocol HopLimit uint8 SrcIP net.IP DstIP net.IP HopByHop *IPv6HopByHop // contains filtered or unexported fields }
IPv6 is the layer for the IPv6 header.
func (*IPv6) AddressTo16 ¶
AddressTo16 ensures IPv6.SrcIP and IPv6.DstIP are actually IPv6 addresses (i.e. 16 byte addresses)
func (*IPv6) CanDecode ¶
func (ipv6 *IPv6) CanDecode() gopacket.LayerClass
CanDecode implementation according to gopacket.DecodingLayer
func (*IPv6) DecodeFromBytes ¶
func (ipv6 *IPv6) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error
DecodeFromBytes implementation according to gopacket.DecodingLayer
func (*IPv6) NetworkFlow ¶
NetworkFlow returns this new Flow (EndpointIPv6, SrcIP, DstIP)
func (*IPv6) NextLayerType ¶
NextLayerType implementation according to gopacket.DecodingLayer
func (*IPv6) SerializeTo ¶
func (ipv6 *IPv6) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error
SerializeTo writes the serialized form of this layer into the SerializationBuffer, implementing gopacket.SerializableLayer. See the docs for gopacket.SerializableLayer for more info.
type IPv6Destination ¶
type IPv6Destination struct { Options []*IPv6DestinationOption // contains filtered or unexported fields }
IPv6Destination is the IPv6 destination options header.
func (*IPv6Destination) DecodeFromBytes ¶
func (i *IPv6Destination) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error
DecodeFromBytes implementation according to gopacket.DecodingLayer
func (*IPv6Destination) LayerType ¶
func (i *IPv6Destination) LayerType() gopacket.LayerType
LayerType returns LayerTypeIPv6Destination.
func (*IPv6Destination) SerializeTo ¶
func (i *IPv6Destination) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error
SerializeTo writes the serialized form of this layer into the SerializationBuffer, implementing gopacket.SerializableLayer. See the docs for gopacket.SerializableLayer for more info.
type IPv6DestinationOption ¶
type IPv6DestinationOption ipv6HeaderTLVOption
IPv6DestinationOption is a TLV option present in an IPv6 destination options extension.
type IPv6ExtensionSkipper ¶
type IPv6ExtensionSkipper struct { NextHeader IPProtocol BaseLayer }
IPv6ExtensionSkipper is a DecodingLayer which decodes and ignores v6 extensions. You can use it with a DecodingLayerParser to handle IPv6 stacks which may or may not have extensions.
func (*IPv6ExtensionSkipper) CanDecode ¶
func (i *IPv6ExtensionSkipper) CanDecode() gopacket.LayerClass
CanDecode implementation according to gopacket.DecodingLayer
func (*IPv6ExtensionSkipper) DecodeFromBytes ¶
func (i *IPv6ExtensionSkipper) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error
DecodeFromBytes implementation according to gopacket.DecodingLayer
func (*IPv6ExtensionSkipper) NextLayerType ¶
func (i *IPv6ExtensionSkipper) NextLayerType() gopacket.LayerType
NextLayerType implementation according to gopacket.DecodingLayer
type IPv6Fragment ¶
type IPv6Fragment struct { BaseLayer NextHeader IPProtocol // Reserved1 is bits [8-16), from least to most significant, 0-indexed Reserved1 uint8 FragmentOffset uint16 // Reserved2 is bits [29-31), from least to most significant, 0-indexed Reserved2 uint8 MoreFragments bool Identification uint32 }
IPv6Fragment is the IPv6 fragment header, used for packet fragmentation/defragmentation.
func (*IPv6Fragment) LayerType ¶
func (i *IPv6Fragment) LayerType() gopacket.LayerType
LayerType returns LayerTypeIPv6Fragment.
type IPv6HopByHop ¶
type IPv6HopByHop struct { Options []*IPv6HopByHopOption // contains filtered or unexported fields }
IPv6HopByHop is the IPv6 hop-by-hop extension.
func (*IPv6HopByHop) DecodeFromBytes ¶
func (i *IPv6HopByHop) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error
DecodeFromBytes implementation according to gopacket.DecodingLayer
func (*IPv6HopByHop) LayerType ¶
func (i *IPv6HopByHop) LayerType() gopacket.LayerType
LayerType returns LayerTypeIPv6HopByHop.
func (*IPv6HopByHop) SerializeTo ¶
func (i *IPv6HopByHop) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error
SerializeTo implementation according to gopacket.SerializableLayer
type IPv6HopByHopOption ¶
type IPv6HopByHopOption ipv6HeaderTLVOption
IPv6HopByHopOption is a TLV option present in an IPv6 hop-by-hop extension.
func (*IPv6HopByHopOption) SetJumboLength ¶
func (o *IPv6HopByHopOption) SetJumboLength(len uint32)
SetJumboLength adds the IPv6HopByHopOptionJumbogram with the given length
type IPv6Routing ¶
type IPv6Routing struct { RoutingType uint8 SegmentsLeft uint8 // This segment is supposed to be zero according to RFC2460, the second set of // 4 bytes in the extension. Reserved []byte // SourceRoutingIPs is the set of IPv6 addresses requested for source routing, // set only if RoutingType == 0. SourceRoutingIPs []net.IP // contains filtered or unexported fields }
IPv6Routing is the IPv6 routing extension.
func (*IPv6Routing) LayerType ¶
func (i *IPv6Routing) LayerType() gopacket.LayerType
LayerType returns LayerTypeIPv6Routing.
type ProtocolFamily ¶
type ProtocolFamily uint8
ProtocolFamily is the set of values defined as PF_* in sys/socket.h
const ( ProtocolFamilyIPv4 ProtocolFamily = 2 // BSDs use different values for INET6... glory be. These values taken from // tcpdump 4.3.0. ProtocolFamilyIPv6BSD ProtocolFamily = 24 ProtocolFamilyIPv6FreeBSD ProtocolFamily = 28 ProtocolFamilyIPv6Darwin ProtocolFamily = 30 ProtocolFamilyIPv6Linux ProtocolFamily = 10 )
func (ProtocolFamily) Decode ¶
func (a ProtocolFamily) Decode(data []byte, p gopacket.PacketBuilder) error
Decoder calls ProtocolFamilyMetadata.DecodeWith's decoder.
func (ProtocolFamily) LayerType ¶
func (a ProtocolFamily) LayerType() gopacket.LayerType
LayerType returns ProtocolFamilyMetadata.LayerType.
func (ProtocolFamily) String ¶
func (a ProtocolFamily) String() string
String returns ProtocolFamilyMetadata.Name.
type TCP ¶
type TCP struct { BaseLayer SrcPort, DstPort TCPPort Seq uint32 Ack uint32 DataOffset uint8 FIN, SYN, RST, PSH, ACK, URG, ECE, CWR, NS bool Window uint16 Checksum uint16 Urgent uint16 Options []TCPOption Padding []byte // contains filtered or unexported fields }
TCP is the layer for TCP headers.
func (*TCP) CanDecode ¶
func (t *TCP) CanDecode() gopacket.LayerClass
func (*TCP) ComputeChecksum ¶
func (*TCP) DecodeFromBytes ¶
func (tcp *TCP) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error
func (*TCP) NextLayerType ¶
func (*TCP) SerializeTo ¶
func (t *TCP) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error
SerializeTo writes the serialized form of this layer into the SerializationBuffer, implementing gopacket.SerializableLayer. See the docs for gopacket.SerializableLayer for more info.
func (*TCP) SetInternalPortsForTesting ¶
func (t *TCP) SetInternalPortsForTesting()
For testing only
func (*TCP) SetNetworkLayerForChecksum ¶
func (i *TCP) SetNetworkLayerForChecksum(l gopacket.NetworkLayer) error
SetNetworkLayerForChecksum tells this layer which network layer is wrapping it. This is needed for computing the checksum when serializing, since TCP/IP transport layer checksums depends on fields in the IPv4 or IPv6 layer that contains it. The passed in layer must be an *IPv4 or *IPv6.
func (*TCP) TransportFlow ¶
type TCPOption ¶
type TCPOption struct { OptionType TCPOptionKind OptionLength uint8 OptionData []byte }
type TCPOptionKind ¶
type TCPOptionKind uint8
TCPOptionKind represents a TCP option code.
func (TCPOptionKind) String ¶
func (k TCPOptionKind) String() string
type TCPPort ¶
type TCPPort uint16
TCPPort is a port in a TCP layer.
type UDP ¶
type UDP struct { BaseLayer SrcPort, DstPort UDPPort Length uint16 Checksum uint16 // contains filtered or unexported fields }
UDP is the layer for UDP headers.
func (*UDP) CanDecode ¶
func (u *UDP) CanDecode() gopacket.LayerClass
func (*UDP) DecodeFromBytes ¶
func (udp *UDP) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error
func (*UDP) NextLayerType ¶
NextLayerType use the destination port to select the right next decoder. It tries first to decode via the destination port, then the source port.
func (*UDP) SerializeTo ¶
func (u *UDP) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error
SerializeTo writes the serialized form of this layer into the SerializationBuffer, implementing gopacket.SerializableLayer. See the docs for gopacket.SerializableLayer for more info.
func (*UDP) SetInternalPortsForTesting ¶
func (u *UDP) SetInternalPortsForTesting()
For testing only
func (*UDP) SetNetworkLayerForChecksum ¶
func (i *UDP) SetNetworkLayerForChecksum(l gopacket.NetworkLayer) error
SetNetworkLayerForChecksum tells this layer which network layer is wrapping it. This is needed for computing the checksum when serializing, since TCP/IP transport layer checksums depends on fields in the IPv4 or IPv6 layer that contains it. The passed in layer must be an *IPv4 or *IPv6.
func (*UDP) TransportFlow ¶
type UDPPort ¶
type UDPPort uint16
UDPPort is a port in a UDP layer.