header

package
v0.0.0-...-78e5dd6 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2022 License: LGPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IPv4HeaderLen    = 20
	MaxIPv4HeaderLen = 60
	IPv6HeaderLen    = 40
	TCPHeaderLen     = 20
	MaxTCPHeaderLen  = 60
	UDPHeaderLen     = 8
	ICMPv4HeaderLen  = 8
	ICMPv6HeaderLen  = 8

	ICMPv4 = 1
	TCP    = 6
	UDP    = 17
	ICMPv6 = 58

	IPv4 = 4
	IPv6 = 6
)

Variables

This section is empty.

Functions

func ProtocolName

func ProtocolName(protocol uint8) string

Returns the name of the given protocol number See : https://en.wikipedia.org/wiki/List_of_IP_protocol_numbers

Types

type ICMPv4Header

type ICMPv4Header struct {
	Raw      []byte
	Modified bool
}

Represents a ICMP header https://en.wikipedia.org/wiki/Internet_Control_Message_Protocol#Header

func NewICMPv4Header

func NewICMPv4Header(raw []byte) *ICMPv4Header

func (*ICMPv4Header) Body

func (h *ICMPv4Header) Body() uint32

Reads the header's bytes and returns the body (Rest of the Header)

func (*ICMPv4Header) Checksum

func (h *ICMPv4Header) Checksum() uint16

Reads the header's bytes and returns the Checksum

func (*ICMPv4Header) Code

func (h *ICMPv4Header) Code() uint8

Reads the header's bytes and returns the code

func (*ICMPv4Header) DstPort

func (h *ICMPv4Header) DstPort() (uint16, error)

Not used for ICMP

func (*ICMPv4Header) HeaderLen

func (h *ICMPv4Header) HeaderLen() int

Returns the length of the header in bytes (8 bytes)

func (*ICMPv4Header) NeedNewChecksum

func (h *ICMPv4Header) NeedNewChecksum() bool

Returns true if the header has been modified

func (*ICMPv4Header) SetBody

func (h *ICMPv4Header) SetBody(body uint32)

func (*ICMPv4Header) SetCode

func (h *ICMPv4Header) SetCode(code uint8)

func (*ICMPv4Header) SetDstPort

func (h *ICMPv4Header) SetDstPort(port uint16) error

Not used for ICMP

func (*ICMPv4Header) SetSrcPort

func (h *ICMPv4Header) SetSrcPort(port uint16) error

Not used for ICMP

func (*ICMPv4Header) SetType

func (h *ICMPv4Header) SetType(hType uint8)

func (*ICMPv4Header) SrcPort

func (h *ICMPv4Header) SrcPort() (uint16, error)

Not used for ICMP

func (*ICMPv4Header) String

func (h *ICMPv4Header) String() string

func (*ICMPv4Header) Type

func (h *ICMPv4Header) Type() uint8

Reads the header's bytes and returns the type

type ICMPv6Header

type ICMPv6Header struct {
	Raw      []byte
	Modified bool
}

Represents a ICMPv6 header https://en.wikipedia.org/wiki/Internet_Control_Message_Protocol_for_IPv6#Message_types_and_formats

func NewICMPv6Header

func NewICMPv6Header(raw []byte) *ICMPv6Header

func (*ICMPv6Header) Body

func (h *ICMPv6Header) Body() uint32

Reads the header's bytes and returns the body (Rest of the Header)

func (*ICMPv6Header) Checksum

func (h *ICMPv6Header) Checksum() uint16

Reads the header's bytes and returns the Checksum

func (*ICMPv6Header) Code

func (h *ICMPv6Header) Code() uint8

Reads the header's bytes and returns the type

func (*ICMPv6Header) DstPort

func (h *ICMPv6Header) DstPort() (uint16, error)

Not used for ICMPv6

func (*ICMPv6Header) HeaderLen

func (h *ICMPv6Header) HeaderLen() int

Returns the length of the header in bytes (8 bytes)

func (*ICMPv6Header) NeedNewChecksum

func (h *ICMPv6Header) NeedNewChecksum() bool

Returns true if the header has been modified

func (*ICMPv6Header) SetBody

func (h *ICMPv6Header) SetBody(body uint32)

func (*ICMPv6Header) SetCode

func (h *ICMPv6Header) SetCode(code uint8)

func (*ICMPv6Header) SetDstPort

func (h *ICMPv6Header) SetDstPort(port uint16) error

Not used for ICMPv6

func (*ICMPv6Header) SetSrcPort

func (h *ICMPv6Header) SetSrcPort(port uint16) error

Not used for ICMPv6

func (*ICMPv6Header) SetType

func (h *ICMPv6Header) SetType(hType uint8)

func (*ICMPv6Header) SrcPort

func (h *ICMPv6Header) SrcPort() (uint16, error)

Not used for ICMPv6

func (*ICMPv6Header) String

func (h *ICMPv6Header) String() string

func (*ICMPv6Header) Type

func (h *ICMPv6Header) Type() uint8

Reads the header's bytes and returns the type

type IPHeader

type IPHeader interface {
	String() string

	Version() int
	HeaderLen() uint8
	NextHeader() uint8
	SrcIP() net.IP
	DstIP() net.IP
	SetSrcIP(net.IP)
	SetDstIP(net.IP)
	Checksum() (uint16, error)
	NeedNewChecksum() bool
}

Represents a IPv4 or IPv6 Header

type IPv4Header

type IPv4Header struct {
	Raw      []byte
	Modified bool
}

Represents a IPv4 Header https://en.wikipedia.org/wiki/IPv4#Header

func NewIPv4Header

func NewIPv4Header(raw []byte) *IPv4Header

func (*IPv4Header) Checksum

func (h *IPv4Header) Checksum() (uint16, error)

Reads the header's bytes and returns the Checksum

func (*IPv4Header) DstIP

func (h *IPv4Header) DstIP() net.IP

Reads the header's bytes and returns the destination IP

func (*IPv4Header) Flags

func (h *IPv4Header) Flags() uint8

Reads the header's bytes and returns the flags

func (*IPv4Header) FragOff

func (h *IPv4Header) FragOff() uint16

Reads the header's bytes and returns the Fragment Offset

func (*IPv4Header) HeaderLen

func (h *IPv4Header) HeaderLen() uint8

Reads the header's bytes and returns its length

func (*IPv4Header) ID

func (h *IPv4Header) ID() uint16

Reads the header's bytes and returns the ID

func (*IPv4Header) NeedNewChecksum

func (h *IPv4Header) NeedNewChecksum() bool

Returns true if the header has been modified

func (*IPv4Header) NextHeader

func (h *IPv4Header) NextHeader() uint8

Reads the header's bytes and returns the protocol number

func (*IPv4Header) Options

func (h *IPv4Header) Options() []byte

Reads the header's bytes and returns the options as a byte slice if they exist or nil

func (*IPv4Header) SetDstIP

func (h *IPv4Header) SetDstIP(ip net.IP)

Sets the destination IP of the packet

func (*IPv4Header) SetSrcIP

func (h *IPv4Header) SetSrcIP(ip net.IP)

Sets the source IP of the packet

func (*IPv4Header) SrcIP

func (h *IPv4Header) SrcIP() net.IP

Reads the header's bytes and returns the source IP

func (*IPv4Header) String

func (h *IPv4Header) String() string

func (*IPv4Header) TOS

func (h *IPv4Header) TOS() uint8

Reads the header's bytes and returns the Type Of Service

func (*IPv4Header) TTL

func (h *IPv4Header) TTL() uint8

Reads the header's bytes and returns the Time To Live of the packet

func (*IPv4Header) TotalLen

func (h *IPv4Header) TotalLen() uint16

Reads the header's bytes and returns the total length of the packet

func (*IPv4Header) Version

func (h *IPv4Header) Version() int

Returns the IP Version

type IPv6Header

type IPv6Header struct {
	Raw      []byte
	Modified bool
}

Represents a IPv6 header https://en.wikipedia.org/wiki/IPv6_packet#Fixed_header

func NewIPv6Header

func NewIPv6Header(raw []byte) *IPv6Header

func (*IPv6Header) Checksum

func (h *IPv6Header) Checksum() (uint16, error)

Always returns 0 and an error as IPv6 has no checksum

func (*IPv6Header) DstIP

func (h *IPv6Header) DstIP() net.IP

Reads the header's bytes and returns the destination IP

func (*IPv6Header) FlowLabel

func (h *IPv6Header) FlowLabel() uint32

Reads the header's bytes and returns the flow label

func (*IPv6Header) HeaderLen

func (h *IPv6Header) HeaderLen() uint8

Returns the length of the header in bytes (40 bytes)

func (*IPv6Header) HopLimit

func (h *IPv6Header) HopLimit() uint8

Reads the header's bytes and returns the hop limit

func (*IPv6Header) NeedNewChecksum

func (h *IPv6Header) NeedNewChecksum() bool

Always returns false as IPv6 has no checksum

func (*IPv6Header) NextHeader

func (h *IPv6Header) NextHeader() uint8

Reads the header's bytes and returns the protocol number

func (*IPv6Header) PayloadLen

func (h *IPv6Header) PayloadLen() uint16

Reads the header's bytes and returns the length of the payload

func (*IPv6Header) SetDstIP

func (h *IPv6Header) SetDstIP(ip net.IP)

Sets the destination IP of the packet

func (*IPv6Header) SetSrcIP

func (h *IPv6Header) SetSrcIP(ip net.IP)

Sets the source IP of the packet

func (*IPv6Header) SrcIP

func (h *IPv6Header) SrcIP() net.IP

Reads the header's bytes and returns the source IP

func (*IPv6Header) String

func (h *IPv6Header) String() string

func (*IPv6Header) TrafficClass

func (h *IPv6Header) TrafficClass() uint8

Reads the header's bytes and returns the traffic class

func (*IPv6Header) Version

func (h *IPv6Header) Version() int

Returns the IP Version

type ProtocolHeader

type ProtocolHeader interface {
	String() string

	HeaderLen() int
	Checksum() uint16
	SrcPort() (uint16, error)
	DstPort() (uint16, error)
	SetSrcPort(uint16) error
	SetDstPort(uint16) error
	NeedNewChecksum() bool
}

Represents a protocol header Supported headers are TCP, UDP, ICMPv4, ICMPv6

type TCPHeader

type TCPHeader struct {
	Raw      []byte
	Modified bool
}

Represents a TCP header https://en.wikipedia.org/wiki/Transmission_Control_Protocol#TCP_segment_structure

func NewTCPHeader

func NewTCPHeader(raw []byte) *TCPHeader

func (*TCPHeader) ACK

func (h *TCPHeader) ACK() bool

Reads the header's bytes and returns the ACK flag as a boolean

func (*TCPHeader) AckNum

func (h *TCPHeader) AckNum() uint32

Reads the header's bytes and returns the acknowledgment number

func (*TCPHeader) CWR

func (h *TCPHeader) CWR() bool

Reads the header's bytes and returns the CWR as a boolean

func (*TCPHeader) Checksum

func (h *TCPHeader) Checksum() uint16

Reads the header's bytes and returns the checksum

func (*TCPHeader) DataOffset

func (h *TCPHeader) DataOffset() uint8

Reads the header's bytes and returns the data offset

func (*TCPHeader) DstPort

func (h *TCPHeader) DstPort() (uint16, error)

Reads the header's bytes and returns the destination port

func (*TCPHeader) ECE

func (h *TCPHeader) ECE() bool

Reads the header's bytes and returns the ECE flag as a boolean

func (*TCPHeader) FIN

func (h *TCPHeader) FIN() bool

Reads the header's bytes and returns the FIN flag as a boolean

func (*TCPHeader) HeaderLen

func (h *TCPHeader) HeaderLen() int

Reads the header's bytes and returns the length of the header in bytes

func (*TCPHeader) NS

func (h *TCPHeader) NS() bool

Reads the header's bytes and returns the NS flag as a boolean

func (*TCPHeader) NeedNewChecksum

func (h *TCPHeader) NeedNewChecksum() bool

Returns true if the header has been modified

func (*TCPHeader) Options

func (h *TCPHeader) Options() []byte

Reads the header's bytes and returns the options as a byte slice if they exist or nil

func (*TCPHeader) PSH

func (h *TCPHeader) PSH() bool

Reads the header's bytes and returns the PSH flag as a boolean

func (*TCPHeader) RST

func (h *TCPHeader) RST() bool

Reads the header's bytes and returns the RST flag as a boolean

func (*TCPHeader) Reserved

func (h *TCPHeader) Reserved() uint8

Reads the header's bytes and returns the reserved part

func (*TCPHeader) SYN

func (h *TCPHeader) SYN() bool

Reads the header's bytes and returns the SYN flag as a boolean

func (*TCPHeader) SeqNum

func (h *TCPHeader) SeqNum() uint32

Reads the header's bytes and returns the sequence number

func (*TCPHeader) SetDstPort

func (h *TCPHeader) SetDstPort(port uint16) error

Sets the destination port

func (*TCPHeader) SetSrcPort

func (h *TCPHeader) SetSrcPort(port uint16) error

Sets the source port

func (*TCPHeader) SrcPort

func (h *TCPHeader) SrcPort() (uint16, error)

Reads the header's bytes and returns the source port

func (*TCPHeader) String

func (h *TCPHeader) String() string

func (*TCPHeader) URG

func (h *TCPHeader) URG() bool

Reads the header's bytes and returns the URG flag as a boolean

func (*TCPHeader) UrgPtr

func (h *TCPHeader) UrgPtr() uint16

Reads the header's bytes and returns the urgent pointer field

func (*TCPHeader) Window

func (h *TCPHeader) Window() uint16

Reads the header's bytes and returns the window size

type UDPHeader

type UDPHeader struct {
	Raw      []byte
	Modified bool
}

Represents a UDP header https://en.wikipedia.org/wiki/User_Datagram_Protocol#Packet_structure

func NewUDPHeader

func NewUDPHeader(raw []byte) *UDPHeader

func (*UDPHeader) Checksum

func (h *UDPHeader) Checksum() uint16

Reads the header's bytes and returns the checksum

func (*UDPHeader) DstPort

func (h *UDPHeader) DstPort() (uint16, error)

Reads the header's bytes and returns the destination port

func (*UDPHeader) HeaderLen

func (h *UDPHeader) HeaderLen() int

Returns the length of the header in bytes (8 bytes)

func (*UDPHeader) Len

func (h *UDPHeader) Len() uint16

Reads the header and returns the length of UDP header and UDP data in bytes

func (*UDPHeader) NeedNewChecksum

func (h *UDPHeader) NeedNewChecksum() bool

Returns true if the header has been modified

func (*UDPHeader) SetDstPort

func (h *UDPHeader) SetDstPort(port uint16) error

Sets the destination port

func (*UDPHeader) SetSrcPort

func (h *UDPHeader) SetSrcPort(port uint16) error

Sets the source port

func (*UDPHeader) SrcPort

func (h *UDPHeader) SrcPort() (uint16, error)

Reads the header's bytes and returns the source port

func (*UDPHeader) String

func (h *UDPHeader) String() string

Jump to

Keyboard shortcuts

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