Documentation ¶
Index ¶
Constants ¶
const ( // ARPRequest for ARP requests. ARPRequest = 1 // ARPReply for ARP replies. ARPReply = 2 )
const ( // DefaultARPExpiration is the default expiration for entries in the ARP table. DefaultARPExpiration = 4 * time.Hour // DefaultARPCleanupInterval is the cleanup interval for the cache. DefaultARPCleanupInterval = DefaultARPExpiration // DefaultARPQueryInterval is the default query interval to use when sending // ARP requests. DefaultARPQueryInterval = 1 * time.Second // DefaultARPTimeout is the default number of ARP requests after which to // give up on an ARP request. DefaultARPTimeout = 3 )
const ( // ProtocolICMP is used for the ICMP protocol. ProtocolICMP = 1 // ProtocolUDP is used for the UDP protocol. ProtocolUDP = 17 )
const (
// ARPHardwareEthernet as lower layer.
ARPHardwareEthernet = 1
)
const (
// ARPProtocolIPv4 as upper layer.
ARPProtocolIPv4 = 0x800
)
Variables ¶
var ( // ErrInvalidIHL is a check error returned when the length of the Options // byte slice does not match the IHL value. ErrInvalidIHL = errors.New("IHL field does not match Options byte slice length") // ErrInvalidChecksum is a check error returned when header checksum is // incorrect. ErrInvalidChecksum = errors.New("Checksum field is incorrect") // ErrInvalidTotalLength is an error returned when the packet length is // too small. ErrInvalidTotalLength = errors.New("TotalLength field is too small") )
var Broadcast = Address([4]byte{255, 255, 255, 255})
Broadcast is the IPv4 broadcast address.
var ( // ErrARPTimeout occurs when no ARP reply is received for an ARP request. ErrARPTimeout = errors.New("ARP request timeout") )
var ( // ErrNoRouteToDestinationAddress is returned when there is no route // to the destination address. ErrNoRouteToDestinationAddress = errors.New("no route to destination address") )
Functions ¶
This section is empty.
Types ¶
type ARP ¶
ARP represents an ARP layer that can convert IPv4 addresses to Ethernet addresses.
type ARPHardwareType ¶
type ARPHardwareType uint16
ARPHardwareType is the network protocol of the ARP packet.
type ARPPacket ¶
type ARPPacket struct { HardwareType ARPHardwareType ProtocolType ARPProtocolType HardwareAddressLength uint8 ProtocolAddressLength uint8 Operation ARPOperation SenderHardwareAddress ethernet.MAC SenderProtocolAddress Address TargetHardwareAddress ethernet.MAC TargetProtocolAddress Address }
ARPPacket represents an ARP packet
func NewARPPacket ¶
NewARPPacket reads an ARP packet from a reader.
func NewARPReply ¶
NewARPReply constructs an ARP reply packet.
func NewARPRequest ¶
NewARPRequest creates an ARP request packet.
type ARPProtocolType ¶
type ARPProtocolType uint16
ARPProtocolType is the internetwork protocol of the ARP packet.
type Address ¶
type Address [4]byte
Address is an IPv4 address.
func NewAddress ¶
NewAddress creates a new address from a string.
If the string is invalid, NewAddress returns false.
type Header ¶
type Header struct { Version uint8 IHL uint8 ToS uint8 TotalLength uint16 Identification uint16 Flags uint8 FragmentOffset uint16 TTL uint8 Protocol Protocol Checksum uint16 Source Address Destination Address Options []byte }
Header is the logical version of an IPv4 header.
func (Header) CalculateChecksum ¶
CalculateChecksum calculates the header checksum.
func (Header) Check ¶
Check checks whether the IPv4 header is valid.
The function fails if the checksum is not correct, or if the IHL field does not match the length of the Options byte slice.
This functions can return ErrInvalidIHL, ErrInvalidChecksum or ErrInvalidTotalLength.
type Packet ¶
Packet is an IPv4 packet.
func NewDefaultPacket ¶
func NewDefaultPacket() Packet
NewDefaultPacket constructs a default IPv4 packet.
func NewPacket ¶
NewPacket will read a packet from a reader.
The header will be checked using the Check() function. Only valid packets will be returned, unless err is not nil.
func NewPacketTo ¶
NewPacketTo constructs a new packet with a destination.
type RawHeader ¶
type RawHeader struct { VersionIHL uint8 ToS uint8 TotalLength uint16 Identification uint16 FlagsFragmentOffset uint16 TTL uint8 Protocol Protocol Checksum uint16 Source Address Destination Address }
RawHeader represents a raw IPv4 header.
This struct can be written and read with the binary package.
func NewRawHeader ¶
NewRawHeader reads a new raw header from a reader.