dhcp

package
v1.6.20 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxUDPReceivedPacketSize = 8192
)

Variables

View Source
var (
	DefaultReadTimeout = 3 * time.Second
	DefaultTimeout     = 3 * time.Second
)

Functions

func BindToInterface

func BindToInterface(fd int, ifname string) error

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 MakeRawUDPPacket

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

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

func NewReadSocket

func NewReadSocket(ifname string, timeout time.Duration) (io.ReadCloser, error)

returns a reader which should always be closed, even if we return an error

func NewWriteSocket

func NewWriteSocket(ifname string, remoteAddr unix.SockaddrInet4) (io.WriteCloser, error)

Linux specific returns a writer which should always be closed, even if we return an error

Types

type DHCP

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

func New

func New(logger *zap.Logger) *DHCP

func (*DHCP) DiscoverRequest

func (c *DHCP) DiscoverRequest(ctx context.Context, mac net.HardwareAddr, ifname string) error

Issues a DHCP Discover packet from the nic specified by mac and name ifname Returns nil if a reply to the transaction was received, or error if time out Does not return the DHCP Offer that was received from the DHCP server

type Socket

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

func (*Socket) Close

func (s *Socket) Close() error

func (*Socket) Read

func (s *Socket) Read(p []byte) (n int, err error)

func (*Socket) Write

func (s *Socket) Write(packetBytes []byte) (int, error)

type TransactionID

type TransactionID [4]byte

TransactionID represents a 4-byte DHCP transaction ID as defined in RFC 951, Section 3.

The TransactionID is used to match DHCP replies to their original request.

func GenerateTransactionID

func GenerateTransactionID() (TransactionID, error)

GenerateTransactionID generates a random 32-bits number suitable for use as TransactionID

Jump to

Keyboard shortcuts

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