diff options
-rw-r--r-- | dhcpv4/server4/server.go | 105 | ||||
-rw-r--r-- | dhcpv6/dhcpv6.go | 2 | ||||
-rw-r--r-- | dhcpv6/nclient6/client.go | 1 | ||||
-rw-r--r-- | dhcpv6/server6/server.go | 105 |
4 files changed, 107 insertions, 106 deletions
diff --git a/dhcpv4/server4/server.go b/dhcpv4/server4/server.go index c50e6a5..4e6796f 100644 --- a/dhcpv4/server4/server.go +++ b/dhcpv4/server4/server.go @@ -1,3 +1,55 @@ +// Package server4 is a basic, extensible DHCPv4 server. +// +// To use the DHCPv4 server code you have to call NewServer with two arguments: +// - an interface to listen on, +// - an address to listen on, and +// - a handler function, that will be called every time a valid DHCPv4 packet is +// received. +// +// The address to listen on is used to know IP address, port and optionally the +// scope to create and UDP socket to listen on for DHCPv4 traffic. +// +// The handler is a function that takes as input a packet connection, that can +// be used to reply to the client; a peer address, that identifies the client +// sending the request, and the DHCPv4 packet itself. Just implement your +// custom logic in the handler. +// +// Optionally, NewServer can receive options that will modify the server +// object. Some options already exist, for example WithConn. If this option is +// passed with a valid connection, the listening address argument is ignored. +// +// Example program: +// +// package main +// +// import ( +// "log" +// "net" +// +// "github.com/insomniacslk/dhcp/dhcpv4" +// "github.com/insomniacslk/dhcp/dhcpv4/server4" +// ) +// +// func handler(conn net.PacketConn, peer net.Addr, m *dhcpv4.DHCPv4) { +// // this function will just print the received DHCPv4 message, without replying +// log.Print(m.Summary()) +// } +// +// func main() { +// laddr := net.UDPAddr{ +// IP: net.ParseIP("127.0.0.1"), +// Port: 67, +// } +// server, err := server4.NewServer("eth0", &laddr, handler) +// if err != nil { +// log.Fatal(err) +// } +// +// // This never returns. If you want to do other stuff, dump it into a +// // goroutine. +// server.Serve() +// } +// package server4 import ( @@ -8,59 +60,6 @@ import ( "github.com/insomniacslk/dhcp/dhcpv4" ) -/* - To use the DHCPv4 server code you have to call NewServer with two arguments: - - an address to listen on, and - - a handler function, that will be called every time a valid DHCPv4 packet is - received. - - The address to listen on is used to know IP address, port and optionally the - scope to create and UDP socket to listen on for DHCPv4 traffic. - - The handler is a function that takes as input a packet connection, that can be - used to reply to the client; a peer address, that identifies the client sending - the request, and the DHCPv4 packet itself. Just implement your custom logic in - the handler. - - Optionally, NewServer can receive options that will modify the server object. - Some options already exist, for example WithConn. If this option is passed with - a valid connection, the listening address argument is ignored. - - Example program: - - -package main - -import ( - "log" - "net" - - "github.com/insomniacslk/dhcp/dhcpv4" - "github.com/insomniacslk/dhcp/dhcpv4/server4" -) - -func handler(conn net.PacketConn, peer net.Addr, m *dhcpv4.DHCPv4) { - // this function will just print the received DHCPv4 message, without replying - log.Print(m.Summary()) -} - -func main() { - laddr := net.UDPAddr{ - IP: net.ParseIP("127.0.0.1"), - Port: 67, - } - server, err := server4.NewServer(&laddr, handler) - if err != nil { - log.Fatal(err) - } - - // This never returns. If you want to do other stuff, dump it into a - // goroutine. - server.Serve() -} - -*/ - // Handler is a type that defines the handler function to be called every time a // valid DHCPv4 message is received type Handler func(conn net.PacketConn, peer net.Addr, m *dhcpv4.DHCPv4) diff --git a/dhcpv6/dhcpv6.go b/dhcpv6/dhcpv6.go index 07995e0..670be56 100644 --- a/dhcpv6/dhcpv6.go +++ b/dhcpv6/dhcpv6.go @@ -1,3 +1,5 @@ +// Package dhcpv6 provides encoding and decoding of DHCPv6 messages and +// options. package dhcpv6 import ( diff --git a/dhcpv6/nclient6/client.go b/dhcpv6/nclient6/client.go index c40e6c8..49d9bbf 100644 --- a/dhcpv6/nclient6/client.go +++ b/dhcpv6/nclient6/client.go @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// Package nclient6 is a minimum-functionality client for DHCPv6. package nclient6 import ( diff --git a/dhcpv6/server6/server.go b/dhcpv6/server6/server.go index 058b0af..ca1aa96 100644 --- a/dhcpv6/server6/server.go +++ b/dhcpv6/server6/server.go @@ -1,58 +1,57 @@ +// Package server6 is a basic, extensible DHCPv6 server. +// +// To use the DHCPv6 server code you have to call NewServer with three arguments: +// - an interface to listen on, +// - an address to listen on, and +// - a handler function, that will be called every time a valid DHCPv6 packet is +// received. +// +// The address to listen on is used to know IP address, port and optionally the +// scope to create and UDP socket to listen on for DHCPv6 traffic. +// +// The handler is a function that takes as input a packet connection, that can be +// used to reply to the client; a peer address, that identifies the client sending +// the request, and the DHCPv6 packet itself. Just implement your custom logic in +// the handler. +// +// Optionally, NewServer can receive options that will modify the server object. +// Some options already exist, for example WithConn. If this option is passed with +// a valid connection, the listening address argument is ignored. +// +// Example program: +// +// package main +// +// import ( +// "log" +// "net" +// +// "github.com/insomniacslk/dhcp/dhcpv6" +// "github.com/insomniacslk/dhcp/dhcpv6/server6" +// ) +// +// func handler(conn net.PacketConn, peer net.Addr, m dhcpv6.DHCPv6) { +// // this function will just print the received DHCPv6 message, without replying +// log.Print(m.Summary()) +// } +// +// func main() { +// laddr := net.UDPAddr{ +// IP: net.ParseIP("::1"), +// Port: 547, +// } +// server, err := server6.NewServer("eth0", &laddr, handler) +// if err != nil { +// log.Fatal(err) +// } +// +// // This never returns. If you want to do other stuff, dump it into a +// // goroutine. +// server.Serve() +// } +// package server6 -/* - To use the DHCPv6 server code you have to call NewServer with two arguments: - - an address to listen on, and - - a handler function, that will be called every time a valid DHCPv6 packet is - received. - - The address to listen on is used to know IP address, port and optionally the - scope to create and UDP socket to listen on for DHCPv6 traffic. - - The handler is a function that takes as input a packet connection, that can be - used to reply to the client; a peer address, that identifies the client sending - the request, and the DHCPv6 packet itself. Just implement your custom logic in - the handler. - - Optionally, NewServer can receive options that will modify the server object. - Some options already exist, for example WithConn. If this option is passed with - a valid connection, the listening address argument is ignored. - - Example program: - - -package main - -import ( - "log" - "net" - - "github.com/insomniacslk/dhcp/dhcpv6" - "github.com/insomniacslk/dhcp/dhcpv6/server6" -) - -func handler(conn net.PacketConn, peer net.Addr, m dhcpv6.DHCPv6) { - // this function will just print the received DHCPv6 message, without replying - log.Print(m.Summary()) -} - -func main() { - laddr := net.UDPAddr{ - IP: net.ParseIP("::1"), - Port: 547, - } - server, err := server6.NewServer(&laddr, handler) - if err != nil { - log.Fatal(err) - } - - // This never returns. If you want to do other stuff, dump it into a - // goroutine. - server.Serve() -} - -*/ - import ( "log" "net" |