Documentation ¶
Overview ¶
Package arp implements the ARP protocol, as described in RFC 826.
Index ¶
- Variables
- type Client
- func (c *Client) Close() error
- func (c Client) HardwareAddr() net.HardwareAddr
- func (c *Client) Read() (*Packet, *ethernet.Frame, error)
- func (c *Client) Reply(req *Packet, hwAddr net.HardwareAddr, ip netip.Addr) error
- func (c *Client) Request(ip netip.Addr) error
- func (c *Client) Resolve(ip netip.Addr) (net.HardwareAddr, error)
- func (c *Client) SetDeadline(t time.Time) error
- func (c *Client) SetReadDeadline(t time.Time) error
- func (c *Client) SetWriteDeadline(t time.Time) error
- func (c *Client) WriteTo(p *Packet, addr net.HardwareAddr) error
- type Operation
- type Packet
Constants ¶
This section is empty.
Variables ¶
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 ¶
This section is empty.
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 ¶
Dial creates a new Client using the specified network interface. Dial retrieves the IPv4 address of the interface and binds a raw socket to send and receive ARP packets.
func New ¶
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 ¶
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 ¶
Read reads a single ARP packet and returns it, together with its ethernet frame.
func (*Client) Reply ¶
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 ¶
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 ¶
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 ¶
SetDeadline sets the read and write deadlines associated with the connection.
func (*Client) SetReadDeadline ¶
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 ¶
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.
type Operation ¶
type Operation uint16
An Operation is an ARP operation, such as request or reply.
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 netip.Addr // 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 netip.Addr }
A Packet is a raw ARP packet, as described in RFC 826.
func NewPacket ¶
func NewPacket(op Operation, srcHW net.HardwareAddr, srcIP netip.Addr, dstHW net.HardwareAddr, dstIP netip.Addr) (*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 ¶
MarshalBinary allocates a byte slice containing the data from a Packet.
MarshalBinary never returns an error.
func (*Packet) UnmarshalBinary ¶
UnmarshalBinary unmarshals a raw byte slice into a Packet.
Directories ¶
Path | Synopsis |
---|---|
cmd
|
|
arpc
Command arpc provides a simple ARP client which can be used to retrieve hardware addresses of other machines in a LAN using their IPv4 address.
|
Command arpc provides a simple ARP client which can be used to retrieve hardware addresses of other machines in a LAN using their IPv4 address. |