arp

package
v0.4.4 Latest Latest
Warning

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

Go to latest
Published: May 11, 2022 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidHardwareAddr is returned when one or more invalid hardware
	// addresses are passed to NewPacket.
	ErrInvalidHardwareAddr = errors.New("invalid hardware address")

	// ErrInvalidIP is returned when one or more invalid IPv4 addresses are
	// passed to NewPacket.
	ErrInvalidIP = errors.New("invalid IPv4 address")
)

Functions

func CheckWithTimeout

func CheckWithTimeout(ifi *net.Interface, srcPod, gateway net.IP, timeout time.Duration) error

CheckWithTimeout checks vlan network environment and duplicate ip problems, timeout parameter determines how long this function will exactly last.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

A Client is an ARP client, which can be used to send and receive ARP packets.

func Dial

func Dial(ifi *net.Interface, ip net.IP) (*Client, error)

Dial creates a new Client using the specified network interface. Dial the specific IPv4 address and binds a raw socket to send and receive ARP packets.

func New

func New(ifi *net.Interface, p net.PacketConn, ip net.IP) (*Client, error)

New creates a new Client using the specified network interface and net.PacketConn. This allows the caller to define exactly how they bind to the net.PacketConn. This is most useful to define what protocol to pass to socket(7).

In most cases, callers would be better off calling Dial.

func (*Client) Close

func (c *Client) Close() error

Close closes the Client's raw socket and stops sending and receiving ARP packets.

func (Client) HardwareAddr

func (c Client) HardwareAddr() net.HardwareAddr

HardwareAddr fetches the hardware address for the interface associated with the connection.

func (*Client) Read

func (c *Client) Read() (*Packet, *ethernet.Frame, error)

Read reads a single ARP packet and returns it, together with its ethernet frame.

func (*Client) Reply

func (c *Client) Reply(req *Packet, hwAddr net.HardwareAddr, ip net.IP) error

Reply constructs and sends a reply to an ARP request. On the ARP layer, it will be addressed to the sender address of the packet. On the ethernet layer, it will be sent to the actual remote address from which the request was received.

For more fine-grained control, use WriteTo to write a custom response.

func (*Client) Request

func (c *Client) Request(ip net.IP) error

Request sends an ARP request, asking for the hardware address associated with an IPv4 address. The response, if any, can be read with the Read method.

Unlike Resolve, which provides an easier interface for getting the hardware address, Request allows sending many requests in a row, retrieving the responses afterwards.

func (*Client) Resolve

func (c *Client) Resolve(ip net.IP) (net.HardwareAddr, error)

Resolve performs an ARP request, attempting to retrieve the hardware address of a machine using its IPv4 address. Resolve must not be used concurrently with Read. If you're using Read (usually in a loop), you need to use Request instead. Resolve may read more than one message if it receives messages unrelated to the request.

func (*Client) SetDeadline

func (c *Client) SetDeadline(t time.Time) error

SetDeadline sets the read and write deadlines associated with the connection.

func (*Client) SetReadDeadline

func (c *Client) SetReadDeadline(t time.Time) error

SetReadDeadline sets the deadline for future raw socket read calls. If the deadline is reached, a raw socket read will fail with a timeout (see type net.Error) instead of blocking. A zero value for t means a raw socket read will not time out.

func (*Client) SetWriteDeadline

func (c *Client) SetWriteDeadline(t time.Time) error

SetWriteDeadline sets the deadline for future raw socket write calls. If the deadline is reached, a raw socket write will fail with a timeout (see type net.Error) instead of blocking. A zero value for t means a raw socket write will not time out. Even if a write times out, it may return n > 0, indicating that some of the data was successfully written.

func (*Client) WriteTo

func (c *Client) WriteTo(p *Packet, addr net.HardwareAddr) error

WriteTo writes a single ARP packet to addr. Note that addr should, but doesn't have to, match the target hardware address of the ARP packet.

type Operation

type Operation uint16

An Operation is an ARP operation, such as request or reply.

const (
	OperationRequest Operation = 1
	OperationReply   Operation = 2
)

Operation constants which indicate an ARP request or reply.

type Packet

type Packet struct {
	// HardwareType specifies an IANA-assigned hardware type, as described
	// in RFC 826.
	HardwareType uint16

	// ProtocolType specifies the internetwork protocol for which the ARP
	// request is intended.  Typically, this is the IPv4 EtherType.
	ProtocolType uint16

	// HardwareAddrLength specifies the length of the sender and target
	// hardware addresses included in a Packet.
	HardwareAddrLength uint8

	// IPLength specifies the length of the sender and target IPv4 addresses
	// included in a Packet.
	IPLength uint8

	// Operation specifies the ARP operation being performed, such as request
	// or reply.
	Operation Operation

	// SenderHardwareAddr specifies the hardware address of the sender of this
	// Packet.
	SenderHardwareAddr net.HardwareAddr

	// SenderIP specifies the IPv4 address of the sender of this Packet.
	SenderIP net.IP

	// TargetHardwareAddr specifies the hardware address of the target of this
	// Packet.
	TargetHardwareAddr net.HardwareAddr

	// TargetIP specifies the IPv4 address of the target of this Packet.
	TargetIP net.IP
}

A Packet is a raw ARP packet, as described in RFC 826.

func NewPacket

func NewPacket(op Operation, srcHW net.HardwareAddr, srcIP net.IP, dstHW net.HardwareAddr, dstIP net.IP) (*Packet, error)

NewPacket creates a new Packet from an input Operation and hardware/IPv4 address values for both a sender and target.

If either hardware address is less than 6 bytes in length, or there is a length mismatch between the two, ErrInvalidHardwareAddr is returned.

If either IP address is not an IPv4 address, or there is a length mismatch between the two, ErrInvalidIP is returned.

func (*Packet) MarshalBinary

func (p *Packet) MarshalBinary() ([]byte, error)

MarshalBinary allocates a byte slice containing the data from a Packet.

MarshalBinary never returns an error.

func (*Packet) UnmarshalBinary

func (p *Packet) UnmarshalBinary(b []byte) error

UnmarshalBinary unmarshals a raw byte slice into a Packet.

Jump to

Keyboard shortcuts

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