Documentation ¶
Overview ¶
Provides the interfaces for implementing packet encoders and decoders. Every supported protocol implements the Packet interface as a submodule of this package (e.g. packet/ipv4, packet/tcp, ...).
Index ¶
- func Compare(a, b Packet) bool
- func Stringify(p Packet) string
- type Buffer
- func (b *Buffer) Buffer() []byte
- func (b *Buffer) Bytes() []byte
- func (b *Buffer) Init(buf []byte)
- func (b *Buffer) LayerBytes() []byte
- func (b *Buffer) LayerLen() int
- func (b *Buffer) Len() int
- func (b *Buffer) NewLayer()
- func (b *Buffer) Next(n int) []byte
- func (b *Buffer) PutUint16N(off int, data uint16)
- func (b *Buffer) Read(p []byte) (n int, err error)
- func (p *Buffer) ReadL(data interface{}) error
- func (p *Buffer) ReadLAligned(data interface{}, width uintptr) error
- func (p *Buffer) ReadN(data interface{}) error
- func (b *Buffer) SetOffset(off int)
- func (b *Buffer) Write(p []byte) (n int, err error)
- func (b *Buffer) WriteL(data interface{}) error
- func (b *Buffer) WriteN(data interface{}) error
- type Packet
- type Type
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Buffer ¶
type Buffer struct {
// contains filtered or unexported fields
}
A Buffer is a variable-sized buffer of bytes with Read and Write methods. It's based on the bytes.Buffer code provided by the standard library, but implements additional convenience methods.
This is used internally to provide packet encoding and decoding, and should not be used directly.
func (*Buffer) LayerBytes ¶
Return the buffer of the current layer as slice.
func (*Buffer) NewLayer ¶
func (b *Buffer) NewLayer()
Point the layer starting offset to the current buffer offset.
func (*Buffer) Next ¶
Return a slice containing the next n bytes from the buffer, advancing the buffer as if the bytes had been returned by Read
func (*Buffer) PutUint16N ¶
Write data in network byte order to the specified offset relative to the start of the current layer.
func (*Buffer) ReadLAligned ¶
Read aligned structured data from the buffer in little endian byte order.
type Packet ¶
type Packet interface { /* Return the type of the packet */ GetType() Type /* Return the length of the packet including the payload if present */ GetLength() uint16 /* Check if the packet matches another packet */ Equals(other Packet) bool /* Check if the packet is an answer to another packet */ Answers(other Packet) bool /* Encode the packet and write it to the given buffer */ Pack(out *Buffer) error /* Decode the packet from the given buffer */ Unpack(in *Buffer) error /* Return the payload of the packet or nil */ Payload() Packet /* Initialize the payload of the packet */ SetPayload(payload Packet) error /* Try to guess the type of the payload */ GuessPayloadType() Type /* Initialize the checksum of the packet with the given seed */ InitChecksum(seed uint32) String() string }
Packet is the interface used internally to implement packet encoding and decoding independently of the packet wire format.
type Type ¶
type Type uint16
Type represents the protocol of a packet.
const ( None Type = iota ARP Bluetooth /* TODO */ Eth GRE /* TODO */ ICMPv4 ICMPv6 IGMP /* TODO */ IPSec /* TODO */ IPv4 IPv6 ISIS /* TODO */ L2TP /* TODO */ LLC LLDP /* TODO */ OSPF /* TODO */ RadioTap /* TODO */ Raw SCTP /* TODO */ SLL SNAP TCP TRILL /* TODO */ UDP UDPLite /* TODO */ VLAN WiFi /* TODO */ WoL /* TODO */ )
func (Type) ToLinkType ¶
Convert the Type to the corresponding PCAP link type.
Directories ¶
Path | Synopsis |
---|---|
Provides encoding and decoding for ARP packets.
|
Provides encoding and decoding for ARP packets. |
Provides encoding and decoding for Ethernet (both EthernetII and 802.3) packets.
|
Provides encoding and decoding for Ethernet (both EthernetII and 802.3) packets. |
Provides encoding and decoding for ICMPv4 packets.
|
Provides encoding and decoding for ICMPv4 packets. |
Provides encoding and decoding for ICMPv6 packets.
|
Provides encoding and decoding for ICMPv6 packets. |
Provides encoding and decoding for IPv4 packets.
|
Provides encoding and decoding for IPv4 packets. |
Provides encoding and decoding for IPv6 packets.
|
Provides encoding and decoding for IPv6 packets. |
Provides encoding and decoding for LLC (802.2 Logical Link Control) packets.
|
Provides encoding and decoding for LLC (802.2 Logical Link Control) packets. |
Provides encoding and decoding for RadioTap packets.
|
Provides encoding and decoding for RadioTap packets. |
Provides encoding and decoding for raw data packets.
|
Provides encoding and decoding for raw data packets. |
Provides encoding and decoding for SLL (Linux cooked mode) packets.
|
Provides encoding and decoding for SLL (Linux cooked mode) packets. |
Provides encoding and decoding for SNAP packets.
|
Provides encoding and decoding for SNAP packets. |
Provides encoding and decoding for TCP packets.
|
Provides encoding and decoding for TCP packets. |
Provides encoding and decoding for UDP packets.
|
Provides encoding and decoding for UDP packets. |
Provides encoding and decoding for VLAN packets.
|
Provides encoding and decoding for VLAN packets. |