dhclient

package module
v0.0.0-...-5fe3231 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2023 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 Callback

type Callback func(*Lease)

Callback is a function called on certain events

type Client

type Client struct {
	Hostname    string
	Iface       *net.Interface
	Lease       *Lease   // The current lease
	OnBound     Callback // On renew or rebound
	OnExpire    Callback // On expiration of a lease
	DHCPOptions []Option // List of options to send on discovery and requests
	// contains filtered or unexported fields
}

Client is a DHCP client instance

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) 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

func (*Client) Start

func (client *Client) Start()

Start starts the client

func (*Client) Stop

func (client *Client) Stop()

Stop stops the client

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 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

Jump to

Keyboard shortcuts

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