dhclient

package module
v0.0.0-...-1e6f657 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2025 License: GPL-3.0 Imports: 11 Imported by: 0

README

go-dhclient

CircleCI Codecov Go Report Card

go-dhclient is a DHCPv4 client library written in Go. It uses raw sockets and binds them to a specific interface. Callback functions are triggered on binding or expiration of a lease.

See main.go for example code.

Dependencies

Documentation

Index

Constants

This section is empty.

Variables

DefaultParamsRequestList is a list of params to be requested from the server

Functions

This section is empty.

Types

type Client

type Client struct {
	Hostname    string
	Iface       func() *net.Interface
	Lease       *Lease          // The current lease
	OnBound     OnBoundCallback // On renew or rebound
	OnEexchange OnExchangeCallback
	DHCPOptions []Option         // List of options to send on discovery and requests
	HWAddr      net.HardwareAddr // client's hardware address
	// contains filtered or unexported fields
}

Client is a DHCP client instance

func NewClient

func NewClient(clientName string, HWAddr net.HardwareAddr, getIface func() *net.Interface, OnBound OnBoundCallback) *Client

NewClient create and return new client

func (*Client) AddOption

func (client *Client) AddOption(optType layers.DHCPOpt, data []byte)

AddOption adds an DHCP option

func (*Client) AddParamRequest

func (client *Client) AddParamRequest(dhcpOpt layers.DHCPOpt)

AddParamRequest adds an parameter to parameter request list, if not included yet.

func (*Client) Destroy

func (client *Client) Destroy()

Destroy -

func (*Client) Disable

func (client *Client) Disable()

Disable stops the client

func (*Client) Enable

func (client *Client) Enable(cb OnExchangeCallback)

Enable starts the client

func (*Client) Rebind

func (client *Client) Rebind()

Rebind forgets the current lease and triggers acquirement of a new one

func (*Client) Renew

func (client *Client) Renew()

Renew triggers the renewal of the current lease

type Lease

type Lease struct {
	ServerID     net.IP
	FixedAddress net.IP
	Netmask      net.IPMask
	NextServer   net.IP
	Broadcast    net.IP
	Router       []net.IP
	DNS          []net.IP
	TimeServer   []net.IP
	DomainName   string
	MTU          uint16

	// Other options
	OtherOptions []Option

	Bound  time.Time
	Renew  time.Time
	Rebind time.Time
	Expire time.Time
}

Lease is an assignment by the DHCP server

type OnBoundCallback

type OnBoundCallback func(*Lease)

OnBoundCallback is a function called on certain events

type OnExchangeCallback

type OnExchangeCallback func(error)

OnExchangeCallback is a function called on enabling will end

type Option

type Option struct {
	Type layers.DHCPOpt
	Data []byte
}

Option is a DHCP option field

func (*Option) AddByte

func (option *Option) AddByte(b byte)

AddByte ensures a specific byte is included in the data

Directories

Path Synopsis
cmd
dhclient command

Jump to

Keyboard shortcuts

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