packet

package module
v0.0.0-...-9e5bfbb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 1, 2015 License: MIT Imports: 6 Imported by: 0

README

Packet :: Collection of GoPacket Layers

Sometimes it's easier to implement low level network protocols yourself.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var LayerTypeTFTP = gopacket.RegisterLayerType(1000, gopacket.LayerTypeMetadata{
	Name: "TFTP", Decoder: gopacket.DecodeFunc(decodeTFTP),
})

LayerTypeTFTP defines a GoPacket application layer.

View Source
var LayerTypeUDP = gopacket.RegisterLayerType(1045, gopacket.LayerTypeMetadata{
	Name: "UDP", Decoder: gopacket.DecodeFunc(decodeUDP),
})

LayerTypeUDP is a extensible UDP packet LayerType

View Source
var UDPPortLayerTypes = map[UDPPort]gopacket.LayerType{
	53:   layers.LayerTypeDNS,
	6343: layers.LayerTypeSFlow,
}

UDPPortLayerTypes is a UDPPort LayerType mapping for decoding.

Functions

func RegisterUDPPortLayerType

func RegisterUDPPortLayerType(port UDPPort, layer gopacket.LayerType)

RegisterUDPPortLayerType registers a NextLayerType for a UDPPort. This can be used with UnregisterUDPPortLayerType to enable TID sessions for a protocol such as TFTP.

func UnregisterUDPPortLayerType

func UnregisterUDPPortLayerType(port UDPPort)

UnregisterUDPPortLayerType unregisters a NextLayerType for a UDPPort.

Types

type TFTP

type TFTP struct {
	layers.BaseLayer
	TFTPOpCode

	Filename, Mode string
	Block          uint16
	Data           []byte
	Last           bool

	TFTPErrorCode
	ErrorMessage string
}

TFTP defines a TFTP packet layer.

func (*TFTP) CanDecode

func (t *TFTP) CanDecode() gopacket.LayerClass

CanDecode returns what LayerType TFTP can decode.

func (*TFTP) DecodeFromBytes

func (t *TFTP) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error

DecodeFromBytes decodes packet data and populates the TFTP structure.

func (*TFTP) LayerType

func (t *TFTP) LayerType() gopacket.LayerType

LayerType returns LayerTypeTFTP.

func (*TFTP) NextLayerType

func (t *TFTP) NextLayerType() gopacket.LayerType

NextLayerType returns gopacket.LayerTypePayload.

func (*TFTP) Payload

func (t *TFTP) Payload() []byte

Payload returns the remaining Payload (should be nil)

func (*TFTP) SerializeTo

func (t *TFTP) 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 TFTPErrorCode

type TFTPErrorCode uint16

TFTPErrorCode defines the TFTP error codes. These messages are meant to be user customized.

type TFTPOpCode

type TFTPOpCode uint16

TFTPOpCode defines the TFTP packet operation.

const (

	// TFTPOpRead performs a read operation.
	TFTPOpRead TFTPOpCode
	// TFTPOpWrite performs a write operation.
	TFTPOpWrite
	// TFTPOpData performs a data operation.
	TFTPOpData
	// TFTPOpAck acknowledges a statement.
	TFTPOpAck
	// TFTPOpError performs an error operation.
	TFTPOpError
)

type UDP

type UDP struct {
	layers.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

CanDecode returns the LayerType that UDP can decode.

func (*UDP) DecodeFromBytes

func (u *UDP) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error

DecodeFromBytes decodes a UDP packet into the UDP structure.

func (*UDP) LayerType

func (u *UDP) LayerType() gopacket.LayerType

LayerType returns LayerTypeUDP

func (*UDP) NextLayerType

func (u *UDP) NextLayerType() gopacket.LayerType

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) TransportFlow

func (u *UDP) TransportFlow() gopacket.Flow

TransportFlow creates a flow for UDP packets on the source and destination ports.

type UDPPort

type UDPPort uint16

UDPPort is a port in a UDP layer.

func (UDPPort) LayerType

func (a UDPPort) LayerType() gopacket.LayerType

LayerType returns a LayerType that would be able to decode the application payload. It use some well-known port such as 53 for DNS.

Returns gopacket.LayerTypePayload for unknown/unsupported port numbers.

func (UDPPort) String

func (a UDPPort) String() string

String returns the port as "number(name)" if there's a well-known port name, or just "number" if there isn't. Well-known names are stored in UDPPortNames.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL