mirror of
https://github.com/nadoo/glider.git
synced 2026-11-19 07:09:42 +08:00
dhcpd: support macOS and freebsd(not tested)
This commit is contained in:
1 parent
7c50915f20
commit
8b29af3c0c
12 files changed
+51
-30
No files matched your search
@@ -0,0 +1,27 @@
|
||||
package dhcpd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/insomniacslk/dhcp/dhcpv4/nclient4"
|
||||
|
||||
"github.com/nadoo/glider/log"
|
||||
)
|
||||
|
||||
func existsServer(iface string) (exists bool) {
|
||||
client, err := nclient4.New(iface)
|
||||
if err != nil {
|
||||
log.F("[dhcpd] failed in dhcp client creation: %s", err)
|
||||
return
|
||||
}
|
||||
defer client.Close()
|
||||
|
||||
ctx, _ := context.WithTimeout(context.Background(), 3*time.Second)
|
||||
_, err = client.Request(ctx)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
//go:build !linux
|
||||
// +build !linux
|
||||
|
||||
package dhcpd
|
||||
|
||||
func existsServer(iface string) (exists bool) {
|
||||
return false
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package dhcpd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net"
|
||||
"strconv"
|
||||
@@ -9,7 +8,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/insomniacslk/dhcp/dhcpv4"
|
||||
"github.com/insomniacslk/dhcp/dhcpv4/nclient4"
|
||||
"github.com/insomniacslk/dhcp/dhcpv4/server4"
|
||||
|
||||
"github.com/nadoo/glider/log"
|
||||
@@ -137,23 +135,6 @@ func handleDHCP(serverIP net.IP, mask net.IPMask, pool *Pool) server4.Handler {
|
||||
}
|
||||
}
|
||||
|
||||
func existsServer(iface string) (exists bool) {
|
||||
client, err := nclient4.New(iface)
|
||||
if err != nil {
|
||||
log.F("[dhcpd] failed in dhcp client creation: %s", err)
|
||||
return
|
||||
}
|
||||
defer client.Close()
|
||||
|
||||
ctx, _ := context.WithTimeout(context.Background(), 3*time.Second)
|
||||
_, err = client.Request(ctx)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func ifaceAddr(iface string) (net.IP, net.IPMask, net.HardwareAddr, error) {
|
||||
intf, err := net.InterfaceByName(iface)
|
||||
if err != nil {
|
||||
|
||||
Reference in new issue
Block a user