dhcp4server

package module
v0.0.0-...-7d4a0a7 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2018 License: MPL-2.0 Imports: 9 Imported by: 1

README

dhcp4server GoDoc Coverage Status Codeship Status for d2g/dhcp4server

DHCP Server

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func DNSServers

func DNSServers(dnss []net.IP) func(*Server) error

Set the DNS servers.

func DefaultGateway

func DefaultGateway(r net.IP) func(*Server) error

Set the Default Gateway Address.

func IP

func IP(i net.IP) func(*Server) error

Set the Server IP

func IgnoreHardwareAddresses

func IgnoreHardwareAddresses(h []net.HardwareAddr) func(*Server) error

Set Ignore Hardware Addresses

func IgnoreIPs

func IgnoreIPs(ips []net.IP) func(*Server) error

Set Ignore IPs

func LeaseDuration

func LeaseDuration(d time.Duration) func(*Server) error

Set Lease Duration

func LeasePool

func LeasePool(p leasepool.LeasePool) func(*Server) error

Set LeasePool

func SetLocalAddr

func SetLocalAddr(a net.UDPAddr) func(*Server) error

Set The Local Address

func SetRemoteAddr

func SetRemoteAddr(a net.UDPAddr) func(*Server) error

Set The Remote Address

func SubnetMask

func SubnetMask(m net.IP) func(*Server) error

Set the Subnet Mask

Types

type Server

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

* The DHCP Server Structure

Example

* Example Server :D

package main

import (
	"log"
	"net"

	"github.com/d2g/dhcp4"
	"github.com/d2g/dhcp4server"
	"github.com/d2g/dhcp4server/leasepool"
	"github.com/d2g/dhcp4server/leasepool/memorypool"
)

func main() {

	//Create a Lease Pool We're going to use a memory pool
	//Remember the memory is cleared on restart so you will reissue the same IP Addresses.
	myMemoryLeasePool := memorypool.MemoryPool{}

	//Lets add a list of IPs to the pool these will be served to the clients so make sure they work for you.
	// So Create Array of IPs 192.168.1.1 to 192.168.1.30
	for i := 0; i < 30; i++ {
		err := myMemoryLeasePool.AddLease(leasepool.Lease{IP: dhcp4.IPAdd(net.IPv4(192, 168, 1, 1), i)})
		if err != nil {
			log.Fatalln("Error Adding IP to pool:" + err.Error())
		}
	}

	// We set the port numbers to over 1024 (1067 & 1068) as the automated test don't have root access
	tServer, err := dhcp4server.New(
		net.IPv4(192, 168, 1, 201),
		&myMemoryLeasePool,
		dhcp4server.SetLocalAddr(net.UDPAddr{IP: net.IPv4(0, 0, 0, 0), Port: 1067}),
		dhcp4server.SetRemoteAddr(net.UDPAddr{IP: net.IPv4bcast, Port: 1068}),
	)
	if err != nil {
		log.Fatalln("Error Configuring Server:" + err.Error())
	}

	//Start the Server...
	err = tServer.ListenAndServe()
	if err != nil {
		log.Fatalln("Error Starting Server:" + err.Error())
	}
}
Output:

func New

func New(ip net.IP, l leasepool.LeasePool, options ...func(*Server) error) (*Server, error)

Create A New Server

func (*Server) AcknowledgementPacket

func (s *Server) AcknowledgementPacket(requestPacket dhcp4.Packet) dhcp4.Packet

* Create DHCP Acknowledgement

func (*Server) DeclinePacket

func (s *Server) DeclinePacket(requestPacket dhcp4.Packet) dhcp4.Packet

* Create DHCP Decline

func (*Server) GC

func (s *Server) GC() error

* Garbage Collection * Run Garbage Collection On Your Leases To Free Expired Leases.

func (*Server) GetLease

func (s *Server) GetLease(packet dhcp4.Packet) (found bool, lease leasepool.Lease, err error)

* Get Lease tries to work out the best lease for the packet supplied. * Taking into account all Requested IP, Exisitng MACAddresses and Free leases.

func (*Server) ListenAndServe

func (s *Server) ListenAndServe() error

* Start The DHCP Server

func (*Server) OfferPacket

func (s *Server) OfferPacket(discoverPacket dhcp4.Packet) dhcp4.Packet

* Create DHCP Offer Packet

func (*Server) ServeDHCP

func (s *Server) ServeDHCP(packet dhcp4.Packet) (dhcp4.Packet, error)

func (*Server) Shutdown

func (s *Server) Shutdown()

* Shutdown The Server Gracefully

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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