Skip to content

Commit

Permalink
Added example for DHCPv6 server
Browse files Browse the repository at this point in the history
  • Loading branch information
insomniacslk committed Nov 20, 2018
1 parent 0f072cd commit bbaa1a7
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
38 changes: 37 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,43 @@ $ go run main.go

## DHCPv6 server

TODO
A DHCPv6 server requires the user to implement a request handler. Basically the
user has to provide the logic to answer to each packet. The library offers a few
facilities to forge response packets, e.g. `NewAdvertiseFromSolicit`,
`NewReplyFromDHCPv6Message` and so on. Look at the source code to see what's
available.

An example server that will print (but not reply to) the client's request is
shown below:

```
package main
import (
"log"
"net"
"github.com/insomniacslk/dhcp/dhcpv6"
)
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: dhcpv6.DefaultServerPort,
}
server := dhcpv6.NewServer(laddr, handler)
defer server.Close()
if err := server.ActivateAndServe(); err != nil {
log.Panic(err)
}
}
```

## DHCPv4 client

Expand Down
2 changes: 1 addition & 1 deletion dhcpv6/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func handler(conn net.PacketConn, peer net.Addr, m dhcpv6.DHCPv6) {
func main() {
laddr := net.UDPAddr{
IP: net.ParseIP("::1"),
Port: 547,
Port: dhcpv6.DefaultServerPort,
}
server := dhcpv6.NewServer(laddr, handler)
Expand Down

0 comments on commit bbaa1a7

Please sign in to comment.