client4

package
Version: v0.0.0-...-dd8bdda Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2019 License: BSD-3-Clause Imports: 9 Imported by: 3

Documentation

Index

Constants

View Source
const (
	MaxUDPReceivedPacketSize = 8192
)

MaxUDPReceivedPacketSize is the (arbitrary) maximum UDP packet size supported by this library. Theoretically could be up to 65kb.

Variables

View Source
var (
	// DefaultReadTimeout is the time to wait after listening in which the
	// exchange is considered failed.
	DefaultReadTimeout = 3 * time.Second

	// DefaultWriteTimeout is the time to wait after sending in which the
	// exchange is considered failed.
	DefaultWriteTimeout = 3 * time.Second
)

Functions

func MakeBroadcastSocket

func MakeBroadcastSocket(ifname string) (int, error)

MakeBroadcastSocket creates a socket that can be passed to unix.Sendto that will send packets out to the broadcast address.

func MakeListeningSocket

func MakeListeningSocket(ifname string) (int, error)

MakeListeningSocket creates a listening socket on 0.0.0.0 for the DHCP client port and returns it.

func MakeRawUDPPacket

func MakeRawUDPPacket(payload []byte, serverAddr, clientAddr net.UDPAddr) ([]byte, error)

MakeRawUDPPacket converts a payload (a serialized DHCPv4 packet) into a raw UDP packet for the specified serverAddr from the specified clientAddr.

Types

type Client

type Client struct {
	ReadTimeout, WriteTimeout time.Duration
	RemoteAddr                net.Addr
	LocalAddr                 net.Addr
}

Client is the object that actually performs the DHCP exchange. It currently only has read and write timeout values, plus (optional) local and remote addresses.

func NewClient

func NewClient() *Client

NewClient generates a new client to perform a DHCP exchange with, setting the read and write timeout fields to defaults.

func (*Client) Exchange

func (c *Client) Exchange(ifname string, modifiers ...dhcpv4.Modifier) ([]*dhcpv4.DHCPv4, error)

Exchange runs a full DORA transaction: Discover, Offer, Request, Acknowledge, over UDP. Does not retry in case of failures. Returns a list of DHCPv4 structures representing the exchange. It can contain up to four elements, ordered as Discovery, Offer, Request and Acknowledge. In case of errors, an error is returned, and the list of DHCPv4 objects will be shorted than 4, containing all the sent and received DHCPv4 messages.

func (*Client) SendReceive

func (c *Client) SendReceive(sendFd, recvFd int, packet *dhcpv4.DHCPv4, messageType dhcpv4.MessageType) (*dhcpv4.DHCPv4, error)

SendReceive sends a packet (with some write timeout) and waits for a response up to some read timeout value. If the message type is not MessageTypeNone, it will wait for a specific message type

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL