Documentation ¶
Overview ¶
Package client4 is deprecated. Use "nclient4" instead.
Index ¶
Constants ¶
const (
MaxUDPReceivedPacketSize = 8192
)
MaxUDPReceivedPacketSize is the (arbitrary) maximum UDP packet size supported by this library. Theoretically could be up to 65kb.
Variables ¶
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 ¶
MakeBroadcastSocket creates a socket that can be passed to unix.Sendto that will send packets out to the broadcast address.
func MakeListeningSocket ¶
MakeListeningSocket creates a listening socket on 0.0.0.0 for the DHCP client port and returns it.
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 ¶
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