Documentation
¶
Index ¶
- Variables
- func Checksum(b []byte) uint16
- func GetLocalAddr(network string, ip net.IP) (net.Addr, error)
- func IPv4HeaderToPseudoHeader(hdr *ipv4.Header, udplen int) ([]byte, error)
- func IPv6HeaderToPseudoHeader(hdr *ipv6.Header) ([]byte, error)
- type ICMP
- type ICMPCode
- type ICMPType
- type ICMPv6
- type ICMPv6Code
- type ICMPv6Type
- type IPProto
- type IPv6
- type Layer
- type Raw
- type UDP
Constants ¶
This section is empty.
Variables ¶
var ICMPHeaderLen = 8
ICMPHeaderLen is the ICMPv4 header length
var ICMPv6HeaderLen = 8
ICMPv6HeaderLen is the ICMPv6 header length
var IPv6HeaderLen = 40
IPv6HeaderLen is the length of the IPv6 header
var UDPHeaderLen = 8
UDPHeaderLen is the UDP header length
var Version6 = 6
Version6 is IP version 6
Functions ¶
func GetLocalAddr ¶
GetLocalAddr returns the local address to reach the IP address with the given network type.
func IPv4HeaderToPseudoHeader ¶
IPv4HeaderToPseudoHeader returns a byte slice usable as IPv4 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 (ICMP) ComputeChecksum ¶
ComputeChecksum computes the ICMP checksum.
func (ICMP) MarshalBinary ¶
MarshalBinary serializes the layer
func (*ICMP) UnmarshalBinary ¶
UnmarshalBinary deserializes the layer
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 (ICMPv6) MarshalBinary ¶
MarshalBinary serializes the layer
func (*ICMPv6) UnmarshalBinary ¶
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 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 (IPv6) MarshalBinary ¶
MarshalBinary serializes the layer
func (*IPv6) UnmarshalBinary ¶
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 (Raw) MarshalBinary ¶
MarshalBinary serializes the layer
func (*Raw) UnmarshalBinary ¶
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 (*UDP) MarshalBinary ¶
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 ¶
UnmarshalBinary deserializes the raw bytes to an UDP header