net

package
v0.4.3-0...-b136db8 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2024 License: BSD-2-Clause Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ICMPHeaderLen = 8

ICMPHeaderLen is the ICMPv4 header length

View Source
var ICMPv6HeaderLen = 8

ICMPv6HeaderLen is the ICMPv6 header length

View Source
var IPv6HeaderLen = 40

IPv6HeaderLen is the length of the IPv6 header

View Source
var UDPHeaderLen = 8

UDPHeaderLen is the UDP header length

View Source
var Version6 = 6

Version6 is IP version 6

Functions

func Checksum

func Checksum(b []byte) uint16

Checksum computes the UDP checksum. See RFC768 and RFC1071.

func GetLocalAddr

func GetLocalAddr(network string, ip net.IP) (net.Addr, error)

GetLocalAddr returns the local address to reach the IP address with the given network type.

func IPv4HeaderToPseudoHeader

func IPv4HeaderToPseudoHeader(hdr *ipv4.Header, udplen int) ([]byte, error)

IPv4HeaderToPseudoHeader returns a byte slice usable as IPv4 pseudoheader for UDP checksum calculation.

func IPv6HeaderToPseudoHeader

func IPv6HeaderToPseudoHeader(hdr *ipv6.Header) ([]byte, error)

IPv6HeaderToPseudoHeader returns a byte slice usable as IPv6 pseudoheader for UDP checksum calculation.

Types

type ICMP

type ICMP struct {
	Type     ICMPType
	Code     ICMPCode
	Checksum uint16
	// See RFC792, RFC4884, RFC4950.
	Unused  uint32
	Payload []byte
}

ICMP is an ICMPv4 packet

func NewICMP

func NewICMP(b []byte) (*ICMP, error)

NewICMP constructs a new ICMP header from a sequence of bytes

func (ICMP) ComputeChecksum

func (i ICMP) ComputeChecksum() (uint16, error)

ComputeChecksum computes the ICMP checksum.

func (ICMP) MarshalBinary

func (i ICMP) MarshalBinary() ([]byte, error)

MarshalBinary serializes the layer

func (*ICMP) UnmarshalBinary

func (i *ICMP) UnmarshalBinary(b []byte) error

UnmarshalBinary deserializes the layer

type ICMPCode

type ICMPCode uint8

ICMPCode defines ICMP types

type ICMPType

type ICMPType uint8

ICMPType defines ICMP types

var (
	ICMPEchoReply                     ICMPType
	ICMPDestUnreachable               ICMPType = 3
	ICMPSourceQuench                  ICMPType = 4
	ICMPRedirect                      ICMPType = 5
	ICMPAlternateHostAddr             ICMPType = 6
	ICMPEchoRequest                   ICMPType = 8
	ICMPRouterAdv                     ICMPType = 9
	ICMPRouterSol                     ICMPType = 10
	ICMPTimeExceeded                  ICMPType = 11
	ICMPParamProblem                  ICMPType = 12
	ICMPTimestampReq                  ICMPType = 13
	ICMPTimestampReply                ICMPType = 14
	ICMPAddrMaskReq                   ICMPType = 17
	ICMPAddrMaskReply                 ICMPType = 18
	ICMPTraceroute                    ICMPType = 30
	ICMPConversionErr                 ICMPType = 31
	ICMPMobileHostRedirect            ICMPType = 32
	ICMPIPv6WhereAreYou               ICMPType = 33
	ICMPIPv6IAmHere                   ICMPType = 34
	ICMPMobileRegistrationReq         ICMPType = 35
	ICMPMobileRegistrationReply       ICMPType = 36
	ICMPDomainNameReq                 ICMPType = 37
	ICMPDomainNameReply               ICMPType = 38
	ICMPSkipAlgoDiscoveryProtocol     ICMPType = 39
	ICMPPhoturis                      ICMPType = 40
	ICMPExperimentalMobilityProtocols ICMPType = 41
)

ICMP types

type ICMPv6

type ICMPv6 struct {
	Type     ICMPv6Type
	Code     ICMPv6Code
	Checksum uint16
	// See RFC792, RFC4884, RFC4950.
	Unused uint32
	// contains filtered or unexported fields
}

ICMPv6 is an ICMPv6 packet

func NewICMPv6

func NewICMPv6(b []byte) (*ICMPv6, error)

NewICMPv6 constructs a new ICMPv6 header from a sequence of bytes

func (ICMPv6) MarshalBinary

func (i ICMPv6) MarshalBinary() ([]byte, error)

MarshalBinary serializes the layer

func (ICMPv6) Next

func (i ICMPv6) Next() Layer

Next returns the next layer

func (*ICMPv6) SetNext

func (i *ICMPv6) SetNext(l Layer)

SetNext sets the next layer

func (*ICMPv6) UnmarshalBinary

func (i *ICMPv6) UnmarshalBinary(b []byte) error

UnmarshalBinary deserializes the layer

type ICMPv6Code

type ICMPv6Code uint8

ICMPv6Code defines ICMP types

var (
	// Destination unreachable
	ICMPv6CodeNoRouteToDestination       ICMPv6Code
	ICMPv6CodeAdministrativelyProhibited ICMPv6Code = 1
	ICMPv6CodeAddressUnreachable         ICMPv6Code = 2
	ICMPv6CodePortUnreachable            ICMPv6Code = 4
	// Time exceeded
	ICMPv6CodeHopLimitExceeded          ICMPv6Code
	ICMPv6CodeFragmentReassemblyTimeout ICMPv6Code = 1
)

TODO map ICMP codes, see https://www.iana.org/assignments/icmp-parameters/icmp-parameters.xhtml#icmp-parameters-codes

type ICMPv6Type

type ICMPv6Type uint8

ICMPv6Type defines ICMP types

var (
	ICMPv6TypeDestUnreachable                              ICMPv6Type = 1
	ICMPv6TypePacketTooBig                                 ICMPv6Type = 2
	ICMPv6TypeTimeExceeded                                 ICMPv6Type = 3
	ICMPv6TypeParameterProblem                             ICMPv6Type = 4
	ICMPv6TypeEchoRequest                                  ICMPv6Type = 128
	ICMPv6TypeEchoReply                                    ICMPv6Type = 129
	ICMPv6TypeGroupMembershipQuery                         ICMPv6Type = 130
	ICMPv6TypeGroupMembershipReport                        ICMPv6Type = 131
	ICMPv6TypeGroupMembershipReduction                     ICMPv6Type = 132
	ICMPv6TypeRouterSolicitation                           ICMPv6Type = 133
	ICMPv6TypeRouterAdvertisement                          ICMPv6Type = 134
	ICMPv6TypeNeighborAdvertisement                        ICMPv6Type = 135
	ICMPv6TypeNeighborSolicitation                         ICMPv6Type = 136
	ICMPv6TypeRedirect                                     ICMPv6Type = 137
	ICMPv6TypeRouterRenumbering                            ICMPv6Type = 138
	ICMPv6TypeICMPNodeInformationQuery                     ICMPv6Type = 139
	ICMPv6TypeICMPNodeInformationResponse                  ICMPv6Type = 140
	ICMPv6TypeInverseNeighborDiscoverySolicitationMessage  ICMPv6Type = 141
	ICMPv6TypeInverseNeighborDiscoveryAdvertisementMessage ICMPv6Type = 142
	ICMPv6TypeMLDv2MulticastListenerReport                 ICMPv6Type = 143
	ICMPv6TypeHomeAgentAddressDiscoveryRequestMessage      ICMPv6Type = 144
	ICMPv6TypeHomeAgentAddressDiscoveryReplyMessage        ICMPv6Type = 145
	ICMPv6TypeMobilePrefixSolicitation                     ICMPv6Type = 146
	ICMPv6TypeMobilePrefixAdvertisement                    ICMPv6Type = 147
	ICMPv6TypeCertificationPathSolicitation                ICMPv6Type = 148
	ICMPv6TypeCertificationPathAdvertisement               ICMPv6Type = 149
	ICMPv6TypeExperimentalMobilityProtocols                ICMPv6Type = 150
	ICMPv6TypeMulticastRouterAdvertisement                 ICMPv6Type = 151
	ICMPv6TypeMulticastRouterSolicitation                  ICMPv6Type = 152
	ICMPv6TypeMulticastRouterTermination                   ICMPv6Type = 153
	ICMPv6TypeFMIPv6Messages                               ICMPv6Type = 154
)

ICMP types

type IPProto

type IPProto int

IPProto is the IP protocol type

var (
	ProtoICMP   IPProto = 1
	ProtoTCP    IPProto = 6
	ProtoUDP    IPProto = 17
	ProtoICMPv6 IPProto = 58
)

a few common IANA protocol numbers

type IPv6

type IPv6 struct {
	Version      int
	TrafficClass int
	FlowLabel    int
	PayloadLen   int
	NextHeader   IPProto
	HopLimit     int
	Src          net.IP
	Dst          net.IP

	// IP in ICMP, if set, won't make the parser fail on short packets
	IPinICMP bool
	// contains filtered or unexported fields
}

IPv6 is the IPv6 header

func NewIPv6

func NewIPv6(b []byte) (*IPv6, error)

NewIPv6 constructs a new IPv6 header from a sequence of bytes

func (IPv6) MarshalBinary

func (h IPv6) MarshalBinary() ([]byte, error)

MarshalBinary serializes the layer

func (IPv6) Next

func (h IPv6) Next() Layer

Next returns the next layer

func (*IPv6) SetNext

func (h *IPv6) SetNext(l Layer)

SetNext sets the next Layer

func (*IPv6) UnmarshalBinary

func (h *IPv6) UnmarshalBinary(b []byte) error

UnmarshalBinary deserializes the raw bytes to an IPv6 header

type Layer

type Layer interface {
	MarshalBinary() ([]byte, error)
	UnmarshalBinary(data []byte) error
	Next() Layer
	SetNext(Layer)
}

Layer is a serializable interface that support chaining.

type Raw

type Raw struct {
	Data []byte
}

Raw is a raw payload

func NewRaw

func NewRaw(b []byte) (*Raw, error)

NewRaw builds a new Raw layer

func (Raw) MarshalBinary

func (r Raw) MarshalBinary() ([]byte, error)

MarshalBinary serializes the layer

func (Raw) Next

func (r Raw) Next() Layer

Next returns the next layer. For Raw the next layer is always nil

func (Raw) SetNext

func (r Raw) SetNext(Layer)

SetNext sets the next layer. For Raw this is a no op

func (*Raw) UnmarshalBinary

func (r *Raw) UnmarshalBinary(b []byte) error

UnmarshalBinary deserializes the layer

type UDP

type UDP struct {
	Src     uint16
	Dst     uint16
	Len     uint16
	Csum    uint16
	Payload []byte
	// PseudoHeader is used for checksum computation. The caller is responsible
	// for passing a valid pseudoheader as a byte slice.
	PseudoHeader []byte
}

UDP is the UDP header

func NewUDP

func NewUDP(b []byte) (*UDP, error)

NewUDP constructs a new UDP header from a sequence of bytes.

func (*UDP) MarshalBinary

func (h *UDP) MarshalBinary() ([]byte, error)

MarshalBinary serializes the layer. If the checksum is zero and the IP header is not nil, checksum is computed using the pseudoheader, otherwise it is left to zero.

func (*UDP) UnmarshalBinary

func (h *UDP) UnmarshalBinary(b []byte) error

UnmarshalBinary deserializes the raw bytes to an UDP header

Jump to

Keyboard shortcuts

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