arp

package module
v0.0.0-...-7eda11d Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2024 License: MIT Imports: 7 Imported by: 0

README

ARP

This package provide easy way to marshal and unmarshal ARP packets. Written with pure Go. MIT License.

Documentation

Index

Constants

View Source
const (
	OpcodeRequest = 1
	OpcodeReply   = 2
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

func New

func New(device string) (*Client, error)

Creates new ARP client, pass empty string to use default gateway

func (*Client) Close

func (c *Client) Close() error

Close arp client

func (*Client) Read

func (c *Client) Read() (*Packet, error)

Read first ARP packet

func (*Client) Request

func (c *Client) Request(ip netip.Addr) error

Make ARP request looking for ip

func (*Client) Resolve

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

Make ARP request and wait for response

func (*Client) Write

func (c *Client) Write(p *Packet, to net.HardwareAddr) error

Write ARP packet to certain MAC address

type Packet

type Packet struct {
	// byte length of each hardware address
	HarwAddrLength uint8
	// byte length of each protocol address
	ProtocolAddrLength uint8
	// opcode (REQUEST | REPLY)
	Opcode uint16
	// Hardware address space (e.g., Ethernet, Packet Radio Net.)
	HarwAddrSpace uint16
	// Protocol address space.  For Ethernet hardware, this is from the set of type fields <ether_type>
	ProtocolAddrSpace uint16
	// Hardware address of sender of this packet, with length <HarwAddrLength>
	SrcHarwAddr net.HardwareAddr
	// Hardware address of destination of this packet (if known)
	DstHarwAddr net.HardwareAddr
	//	Protocol address of sender of this packet, with length <ProtocolAddrLength>
	SrcProtocolAddr netip.Addr
	// Protocol address of destination
	DstProtocolAddr netip.Addr
}

ARP packet from RFC 826 https://www.rfc-editor.org/rfc/rfc826

func NewReply

func NewReply() *Packet

func NewRequest

func NewRequest() *Packet

func (*Packet) Marshal

func (p *Packet) Marshal() []byte

func (*Packet) Unmarshal

func (p *Packet) Unmarshal(input []byte)

func (*Packet) WithDstHarwAddr

func (p *Packet) WithDstHarwAddr(addr net.HardwareAddr) *Packet

func (*Packet) WithDstProtocolAddr

func (p *Packet) WithDstProtocolAddr(addr netip.Addr) *Packet

func (*Packet) WithSrcHarwAddr

func (p *Packet) WithSrcHarwAddr(addr net.HardwareAddr) *Packet

func (*Packet) WithSrcProtocolAddr

func (p *Packet) WithSrcProtocolAddr(addr netip.Addr) *Packet

Jump to

Keyboard shortcuts

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