GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Why Go
  • Case Studies
  • Use Cases
  • Security
  • Learn
  • Effective Go
  • Go User Manual
  • Standard library
  • Release Notes
  • API
  • Packages
  • Recorded Talks
  • Meetups
  • Conferences

This view

  • Original page
  • New address

GeezerVison is showing pkg.go.dev — arp package - github.com/mdlayher/arp - Go Packages

Details

  • checked Valid go.mod file

    The Go module system was introduced in Go 1.11 and is the official dependency management solution for Go.

  • checked Redistributable license

    Redistributable licenses place minimal restrictions on how software can be used, modified, and redistributed.

  • unchecked Tagged version

    Modules with tagged versions give importers more predictable builds.

  • unchecked Stable version

    When a project reaches major version v1 it is considered stable.

  • Learn more about best practices

Repository

github.com/mdlayher/arp

Links

  • Open Source Insights Logo Open Source Insights

README ¶

arp Build Status GoDoc

Package arp implements the ARP protocol, as described in RFC 826. MIT Licensed.

Portions of this code are taken from the Go standard library. The Go standard library is Copyright (c) 2012 The Go Authors. All rights reserved. The Go license can be found at https://golang.org/LICENSE.

Documentation ¶

Overview ¶

Package arp implements the ARP protocol, as described in RFC 826.

Index ¶

  • Variables
  • type Client
    • func Dial(ifi *net.Interface) (*Client, error)
    • func New(ifi *net.Interface, p net.PacketConn) (*Client, error)
    • func (c *Client) Close() error
    • func (c Client) HardwareAddr() net.HardwareAddr
    • func (c Client) InterfaceName() string
    • 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
    • func (i Operation) String() string
  • type Packet
    • func NewPacket(op Operation, srcHW net.HardwareAddr, srcIP netip.Addr, dstHW net.HardwareAddr, ...) (*Packet, error)
    • func (p *Packet) MarshalBinary() ([]byte, error)
    • func (p *Packet) UnmarshalBinary(b []byte) error

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 ¶

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 ¶

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

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 ¶

func New(ifi *net.Interface, p net.PacketConn) (*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) InterfaceName ¶

func (c Client) InterfaceName() string

InterfaceName fetches the name 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 netip.Addr) 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 netip.Addr) 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 netip.Addr) (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.

func (Operation) String ¶

func (i Operation) String() string

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 ¶

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.

Source Files ¶

View all Source files
  • client.go
  • doc.go
  • packet.go
  • string.go

Directories ¶

Path Synopsis
cmd
arpc command
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.
proxyarpd command
Click to show internal directories.
Click to hide internal directories.
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.