diff options
author | Chris Koch <chrisko@google.com> | 2020-09-16 00:27:19 -0700 |
---|---|---|
committer | Chris K <c@chrisko.ch> | 2020-09-16 08:00:50 -0700 |
commit | a0be48d916fffb667bbc621f178d5f8e0a753633 (patch) | |
tree | 02bdda727d79a0e2f06f8e3206820e1106923f6a /dhcpv4 | |
parent | 1301300a8d9b25942cf9c3c4f9f77cb8906d4c49 (diff) |
docs: fix package comments
Signed-off-by: Chris Koch <chrisko@google.com>
Diffstat (limited to 'dhcpv4')
-rw-r--r-- | dhcpv4/server4/server.go | 105 |
1 files changed, 52 insertions, 53 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) |