socket

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2020 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ListenDHCP

func ListenDHCP(l log.Logger, ip net.IP, iface *net.Interface) (net.PacketConn, error)

ListenDHCP starts listening for DHCP requests on the given IP and interface It opens a UDP and a AF_PACKET socket for communication

func PreparePacket

func PreparePacket(srcMAC net.HardwareAddr, srcIP net.IP, dstMAC net.HardwareAddr, dstIP net.IP, payload []byte) ([]byte, error)

PreparePacket prepares a raw UDP network packet including Ethernet, IP and UDP layers

Types

type Addr

type Addr struct {
	RawAddr
	Local RawAddr
}

Addr is a IPv4 address used to send directed unicasts (i.e. without a prior ARP request). The IP datagram will be sent to the provided MAC address without taking routing considerations into account!

func (*Addr) Network

func (a *Addr) Network() string

Network returns "upd(raw)" and implements net.Addr

func (*Addr) String

func (a *Addr) String() string

String returns a string representation of the peer's address

type DHCPConn

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

DHCPConn implements net.PacketConn but utilizes a standard UDP and and AF_PACKET socket

func (*DHCPConn) Close

func (p *DHCPConn) Close() error

Close will close both the UDP and the AF_PACKET socket and will return the first error encountered

func (*DHCPConn) LocalAddr

func (p *DHCPConn) LocalAddr() net.Addr

LocalAddr implements the PacketConn interface and returns the local address of the UDP socket

func (*DHCPConn) ReadFrom

func (p *DHCPConn) ReadFrom(b []byte) (int, net.Addr, error)

ReadFrom implements the PacketConn interface and calls ReadFrom on the underlying AF_PACKET socket

func (*DHCPConn) SetDeadline

func (p *DHCPConn) SetDeadline(t time.Time) error

SetDeadline implements the PacketConn interface but is not yet implemented

func (*DHCPConn) SetReadDeadline

func (p *DHCPConn) SetReadDeadline(t time.Time) error

SetReadDeadline implements the PacketConn interface

func (*DHCPConn) SetWriteDeadline

func (p *DHCPConn) SetWriteDeadline(t time.Time) error

SetWriteDeadline implements the PacketConn interface

func (*DHCPConn) WriteTo

func (p *DHCPConn) WriteTo(b []byte, addr net.Addr) (int, error)

WriteTo sends a packet to the given addr. If addr is a *Addr the AF_PACKET socket will be choosen. Otherwise, for e.g. net.UDPAddr, the underlying UDP packet conn will be used. It implements the PacketConn interface

type RawAddr

type RawAddr struct {
	MAC  net.HardwareAddr
	IP   net.IP
	Port uint16 // FIXME: not yet used due to PreparePacket implementation
}

RawAddr implements net.Addr and holds the Ethernet and IP address as well as the TCP/UDP port

Jump to

Keyboard shortcuts

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