Documentation ¶
Index ¶
- func DNSServers(dnss []net.IP) func(*Server) error
- func DefaultGateway(r net.IP) func(*Server) error
- func IP(i net.IP) func(*Server) error
- func IgnoreHardwareAddresses(h []net.HardwareAddr) func(*Server) error
- func IgnoreIPs(ips []net.IP) func(*Server) error
- func LeaseDuration(d time.Duration) func(*Server) error
- func LeasePool(p leasepool.LeasePool) func(*Server) error
- func SetLocalAddr(a net.UDPAddr) func(*Server) error
- func SetRemoteAddr(a net.UDPAddr) func(*Server) error
- func SubnetMask(m net.IP) func(*Server) error
- type Server
- func (s *Server) AcknowledgementPacket(requestPacket dhcp4.Packet) dhcp4.Packet
- func (s *Server) DeclinePacket(requestPacket dhcp4.Packet) dhcp4.Packet
- func (s *Server) GC() error
- func (s *Server) GetLease(packet dhcp4.Packet) (found bool, lease leasepool.Lease, err error)
- func (s *Server) ListenAndServe() error
- func (s *Server) OfferPacket(discoverPacket dhcp4.Packet) dhcp4.Packet
- func (s *Server) ServeDHCP(packet dhcp4.Packet) (dhcp4.Packet, error)
- func (s *Server) Shutdown()
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultGateway ¶
Set the Default Gateway Address.
func IgnoreHardwareAddresses ¶
func IgnoreHardwareAddresses(h []net.HardwareAddr) func(*Server) error
Set Ignore Hardware Addresses
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 (*Server) AcknowledgementPacket ¶
* Create DHCP Acknowledgement
func (*Server) DeclinePacket ¶
* Create DHCP Decline
func (*Server) GC ¶
* Garbage Collection * Run Garbage Collection On Your Leases To Free Expired Leases.
func (*Server) GetLease ¶
* 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) OfferPacket ¶
* Create DHCP Offer Packet
Click to show internal directories.
Click to hide internal directories.