Documentation ¶
Index ¶
- Constants
- func Generate(h Header, payload []byte) []byte
- func Hexdump(b []byte) string
- type Header
- type ICMPCode
- type ICMPHeader
- type ICMPType
- type IP
- type IPHeader
- type IPProto
- type NextHeader
- type ParsedPacket
- func (q *ParsedPacket) Buffer() []byte
- func (q *ParsedPacket) Decode(b []byte)
- func (q *ParsedPacket) ICMPHeader() ICMPHeader
- func (q *ParsedPacket) IPHeader() IPHeader
- func (q *ParsedPacket) IsEchoRequest() bool
- func (q *ParsedPacket) IsEchoResponse() bool
- func (q *ParsedPacket) IsError() bool
- func (q *ParsedPacket) IsTCPSyn() bool
- func (q *ParsedPacket) Payload() []byte
- func (p *ParsedPacket) String() string
- func (q *ParsedPacket) Sub(begin, n int) []byte
- func (q *ParsedPacket) Trim() []byte
- func (q *ParsedPacket) UDPHeader() UDPHeader
- type UDPHeader
Constants ¶
const ( TCPSyn = 0x02 TCPAck = 0x10 TCPSynAck = TCPSyn | TCPAck )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Header ¶ added in v0.100.0
type Header interface { // Len returns the length of the header after marshaling. Len() int // Marshal serializes the header into buf in wire format. // It clobbers the header region, which is the first h.Length() bytes of buf. // It explicitly initializes every byte of the header region, // so pre-zeroing it on reuse is not required. It does not allocate memory. // It fails if and only if len(buf) < Length(). Marshal(buf []byte) error // ToResponse transforms the header into one for a response packet. // For instance, this swaps the source and destination IPs. ToResponse() }
Header is a packet header capable of marshaling itself into a byte buffer.
type ICMPHeader ¶ added in v0.100.0
ICMPHeader represents an ICMP packet header.
func (ICMPHeader) Len ¶ added in v0.100.0
func (ICMPHeader) Len() int
func (ICMPHeader) Marshal ¶ added in v0.100.0
func (h ICMPHeader) Marshal(buf []byte) error
func (*ICMPHeader) ToResponse ¶ added in v0.100.0
func (h *ICMPHeader) ToResponse()
type IP ¶
type IP uint32
IP is an IPv4 address.
func IPFromNetaddr ¶ added in v1.0.0
IPFromNetaddr converts a netaddr.IP to an IP.
func NewIP ¶
NewIP converts a standard library IP address into an IP. It panics if b is not an IPv4 address.
type IPHeader ¶ added in v0.100.0
IPHeader represents an IP packet header.
func (IPHeader) MarshalPseudo ¶ added in v0.100.0
MarshalPseudo serializes the header into buf in pseudo format. It clobbers the header region, which is the first h.Length() bytes of buf. It explicitly initializes every byte of the header region, so pre-zeroing it on reuse is not required. It does not allocate memory.
func (*IPHeader) ToResponse ¶ added in v0.100.0
func (h *IPHeader) ToResponse()
type IPProto ¶
type IPProto uint8
IPProto is either a real IP protocol (ITCP, UDP, ...) or an special value like Unknown. If it is a real IP protocol, its value corresponds to its IP protocol number.
const ( // Unknown represents an unknown or unsupported protocol; it's deliberately the zero value. Unknown IPProto = 0x00 ICMP IPProto = 0x01 IGMP IPProto = 0x02 ICMPv6 IPProto = 0x3a TCP IPProto = 0x06 UDP IPProto = 0x11 // Fragment is a special value. It's not really an IPProto value // so we're using the unassigned 0xFF value. // TODO(dmytro): special values should be taken out of here. Fragment IPProto = 0xFF )
type ParsedPacket ¶ added in v0.100.0
type ParsedPacket struct { IPVersion uint8 // 4, 6, or 0 IPProto IPProto // IP subprotocol (UDP, TCP, etc); the NextHeader field for IPv6 SrcIP IP // IP source address (not used for IPv6) DstIP IP // IP destination address (not used for IPv6) SrcPort uint16 // TCP/UDP source port DstPort uint16 // TCP/UDP destination port TCPFlags uint8 // TCP flags (SYN, ACK, etc) // contains filtered or unexported fields }
ParsedPacket is a minimal decoding of a packet suitable for use in filters.
In general, it only supports IPv4. The IPv6 parsing is very minimal.
func (*ParsedPacket) Buffer ¶ added in v0.100.0
func (q *ParsedPacket) Buffer() []byte
Buffer returns the entire packet buffer. This is a read-only view; that is, q retains the ownership of the buffer.
func (*ParsedPacket) Decode ¶ added in v0.100.0
func (q *ParsedPacket) Decode(b []byte)
Decode extracts data from the packet in b into q. It performs extremely simple packet decoding for basic IPv4 packet types. It extracts only the subprotocol id, IP addresses, and (if any) ports, and shouldn't need any memory allocation.
func (*ParsedPacket) ICMPHeader ¶ added in v0.100.0
func (q *ParsedPacket) ICMPHeader() ICMPHeader
func (*ParsedPacket) IPHeader ¶ added in v0.100.0
func (q *ParsedPacket) IPHeader() IPHeader
func (*ParsedPacket) IsEchoRequest ¶ added in v0.100.0
func (q *ParsedPacket) IsEchoRequest() bool
IsEchoRequest reports whether q is an IPv4 ICMP Echo Request.
func (*ParsedPacket) IsEchoResponse ¶ added in v0.100.0
func (q *ParsedPacket) IsEchoResponse() bool
IsEchoRequest reports whether q is an IPv4 ICMP Echo Response.
func (*ParsedPacket) IsError ¶ added in v0.100.0
func (q *ParsedPacket) IsError() bool
IsError reports whether q is an IPv4 ICMP "Error" packet.
func (*ParsedPacket) IsTCPSyn ¶ added in v0.100.0
func (q *ParsedPacket) IsTCPSyn() bool
IsTCPSyn reports whether q is a TCP SYN packet (i.e. the first packet in a new connection).
func (*ParsedPacket) Payload ¶ added in v0.100.0
func (q *ParsedPacket) Payload() []byte
Payload returns the payload of the IP subprotocol section. This is a read-only view; that is, q retains the ownership of the buffer.
func (*ParsedPacket) String ¶ added in v0.100.0
func (p *ParsedPacket) String() string
func (*ParsedPacket) Sub ¶ added in v0.100.0
func (q *ParsedPacket) Sub(begin, n int) []byte
Sub returns the IP subprotocol section. This is a read-only view; that is, q retains the ownership of the buffer.
func (*ParsedPacket) Trim ¶ added in v0.100.0
func (q *ParsedPacket) Trim() []byte
Trim trims the buffer to its IPv4 length. Sometimes packets arrive from an interface with extra bytes on the end. This removes them.
func (*ParsedPacket) UDPHeader ¶ added in v0.100.0
func (q *ParsedPacket) UDPHeader() UDPHeader
type UDPHeader ¶ added in v0.100.0
UDPHeader represents an UDP packet header.
func (*UDPHeader) ToResponse ¶ added in v0.100.0
func (h *UDPHeader) ToResponse()