Start DHCP on launch if it's enabled in config.

This commit is contained in:
Eugene Bujak 2018-12-28 21:01:16 +03:00
parent f868fdbf7a
commit 03effab345
2 changed files with 14 additions and 1 deletions

5
app.go
View File

@ -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))

10
dhcp.go
View File

@ -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
}