header

package
v0.0.0-...-a69ce32 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2021 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	VLANNone = 0x000
	VLANMax  = 0xfff
)
View Source
const (
	FIN = 0x01
	SYN = 0x02
	RST = 0x04
	PSH = 0x08
	ACK = 0x10
	URG = 0x20
	ECE = 0x40
	CWR = 0x80
)
View Source
const (
	TCPID = 6
	UDPID = 17
)

Variables

View Source
var (
	Broadcast = net.HardwareAddr{0xff, 0xff, 0xff, 0xff, 0xff, 0xff}
)

Functions

func BuildTcpHeader

func BuildTcpHeader(src, dst string) (*IPv4, *TCP)

func BuildTcpPacket

func BuildTcpPacket(ipHeader *IPv4, tcpHeader *TCP, data []byte) []byte

func BuildUdpHeader

func BuildUdpHeader(src, dst string) (*IPv4, *UDP)

func BuildUdpPacket

func BuildUdpPacket(ipHeader *IPv4, udpHeader *UDP, data []byte) []byte

func Get

func Get(data []byte) (proto string, iph *IPv4, udph *UDP, tcph *TCP, packetData []byte, err error)

func GetBase

func GetBase(data []byte) (proto string, src string, dst string, err error)

func GetIp

func GetIp(data []byte) (src uint32, dst uint32, err error)

func GetSubSlice

func GetSubSlice(b []byte, bgn, end int) []byte

func GetTcpAddr

func GetTcpAddr(iph *IPv4, tcph *TCP) (src string, dst string)

func GetUdpAddr

func GetUdpAddr(iph *IPv4, udph *UDP) (src string, dst string)

func IP2Str

func IP2Str(ip uint32) string

func IpStr2Bytes

func IpStr2Bytes(ip string) [4]byte

a.b.c.d -> []byte{a,b,c,d}

func MaskNumber2Mask

func MaskNumber2Mask(mask int) uint32

func ParseAddr

func ParseAddr(src string) (string, int)

src: IP:PORT

func ParseNet

func ParseNet(src string) (string, int)

src: ip/mask

func ReCalTcpCheckSum

func ReCalTcpCheckSum(bs []byte) error

func ReCalUdpCheckSum

func ReCalUdpCheckSum(bs []byte) error

func Str2IP

func Str2IP(s string) uint32

Types

type EtherType

type EtherType uint16
const (
	EtherTypeIPv4        EtherType = 0x0800
	EtherTypeARP         EtherType = 0x0806
	EtherTypeIPv6        EtherType = 0x86DD
	EtherTypeVLAN        EtherType = 0x8100
	EtherTypeServiceVLAN EtherType = 0x88a8
)

type Frame

type Frame struct {
	Destination net.HardwareAddr
	Source      net.HardwareAddr
	ServiceVLAN *VLAN
	VLAN        *VLAN
	EtherType   EtherType
	Payload     []byte
}

func (*Frame) MarshalBinary

func (f *Frame) MarshalBinary() ([]byte, error)

func (*Frame) MarshalFCS

func (f *Frame) MarshalFCS() ([]byte, error)

func (*Frame) UnmarshalBinary

func (f *Frame) UnmarshalBinary(b []byte) error

func (*Frame) UnmarshalFCS

func (f *Frame) UnmarshalFCS(b []byte) error

type IPv4

type IPv4 struct {
	VerIHL   uint8
	Tos      uint8
	Len      uint16
	Id       uint16
	Offset   uint16
	TTL      uint8
	Protocol uint8
	Checksum uint16
	Src      uint32
	Dst      uint32
	Opt      []byte
}

func (*IPv4) CalChecksum

func (h *IPv4) CalChecksum() uint16

func (*IPv4) HeaderLen

func (h *IPv4) HeaderLen() uint16

func (*IPv4) LenBytes

func (h *IPv4) LenBytes() uint16

func (*IPv4) Marshal

func (h *IPv4) Marshal() []byte

func (*IPv4) MarshalRaw

func (h *IPv4) MarshalRaw() []byte

func (*IPv4) ResetChecksum

func (h *IPv4) ResetChecksum()

func (IPv4) String

func (h IPv4) String() string

func (*IPv4) Unmarshal

func (h *IPv4) Unmarshal(bs []byte) error

type IPv4Pseudo

type IPv4Pseudo struct {
	Src      uint32
	Dst      uint32
	Reserved uint8
	Protocol uint8
	Len      uint16
}

func (*IPv4Pseudo) HeaderLen

func (h *IPv4Pseudo) HeaderLen() uint16

func (*IPv4Pseudo) LenBytes

func (h *IPv4Pseudo) LenBytes() uint16

func (*IPv4Pseudo) Marshal

func (h *IPv4Pseudo) Marshal() []byte

func (IPv4Pseudo) String

func (h IPv4Pseudo) String() string

func (*IPv4Pseudo) Unmarshal

func (h *IPv4Pseudo) Unmarshal(bs []byte) error

type Priority

type Priority uint8
const (
	PriorityBackground           Priority = 1
	PriorityBestEffort           Priority = 0
	PriorityExcellentEffort      Priority = 2
	PriorityCriticalApplications Priority = 3
	PriorityVideo                Priority = 4
	PriorityVoice                Priority = 5
	PriorityInternetworkControl  Priority = 6
	PriorityNetworkControl       Priority = 7
)

type TCP

type TCP struct {
	SrcPort    uint16
	DstPort    uint16
	Seq        uint32
	Ack        uint32
	Offset     uint8
	Flags      uint8
	Win        uint16
	Checksum   uint16
	UrgPointer uint16
	Opt        uint32
}

func (*TCP) HeaderLen

func (h *TCP) HeaderLen() uint16

func (*TCP) Marshal

func (h *TCP) Marshal() []byte

func (TCP) String

func (h TCP) String() string

func (*TCP) Unmarshal

func (h *TCP) Unmarshal(bs []byte) error

type UDP

type UDP struct {
	SrcPort  uint16
	DstPort  uint16
	Len      uint16
	Checksum uint16
}

func (*UDP) HeaderLen

func (h *UDP) HeaderLen() uint16

func (*UDP) LenBytes

func (h *UDP) LenBytes() uint16

func (*UDP) Marshal

func (h *UDP) Marshal() []byte

func (UDP) String

func (h UDP) String() string

func (*UDP) Unmarshal

func (h *UDP) Unmarshal(bs []byte) error

type VLAN

type VLAN struct {
	Priority     Priority
	DropEligible bool
	ID           uint16
}

func (*VLAN) MarshalBinary

func (v *VLAN) MarshalBinary() ([]byte, error)

func (*VLAN) UnmarshalBinary

func (v *VLAN) UnmarshalBinary(b []byte) error

Jump to

Keyboard shortcuts

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