From 03effab345e2bc9e77926a64acd426f71b5004cd Mon Sep 17 00:00:00 2001 From: Eugene Bujak Date: Fri, 28 Dec 2018 21:01:16 +0300 Subject: [PATCH] Start DHCP on launch if it's enabled in config. --- app.go | 5 +++++ dhcp.go | 10 +++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/app.go b/app.go index bbe36359..0bfb6e1b 100644 --- a/app.go +++ b/app.go @@ -192,6 +192,11 @@ func main() { log.Fatal(err) } + err = startDHCPServer() + if err != nil { + log.Fatal(err) + } + URL := fmt.Sprintf("http://%s", address) log.Println("Go to " + URL) log.Fatal(http.ListenAndServe(address, nil)) diff --git a/dhcp.go b/dhcp.go index d025b6b5..66be4714 100644 --- a/dhcp.go +++ b/dhcp.go @@ -6,6 +6,7 @@ import ( "net/http" "github.com/AdguardTeam/AdGuardHome/dhcpd" + "github.com/joomcode/errorx" ) var dhcpServer = dhcpd.Server{} @@ -107,7 +108,6 @@ func handleDHCPInterfaces(w http.ResponseWriter, r *http.Request) { } } -// implement func handleDHCPFindActiveServer(w http.ResponseWriter, r *http.Request) { found, err := dhcpd.CheckIfOtherDHCPServersPresent(config.DHCP.InterfaceName) result := map[string]interface{}{} @@ -123,3 +123,11 @@ func handleDHCPFindActiveServer(w http.ResponseWriter, r *http.Request) { return } } + +func startDHCPServer() error { + err := dhcpServer.Start(&config.DHCP) + if err != nil { + return errorx.Decorate(err, "Couldn't start DHCP server") + } + return nil +}