dhcpd: check server existence on more platforms

This commit is contained in:
nadoo committed 2022-02-23 17:48:43 +08:00
1 parent f96ad73c7d
commit 1f196c9cf5
12 files changed
+144 -86

No files matched your search

+21
View File
@@ -0,0 +1,21 @@
package sockopt
import (
"net"
"syscall"
"golang.org/x/sys/unix"
)
func BindControl(iface *net.Interface) func(network, address string, c syscall.RawConn) error {
return func(network, address string, c syscall.RawConn) (err error) {
return c.Control(func(fd uintptr) {
switch network {
case "tcp4", "udp4":
err = unix.SetsockoptInt(int(fd), unix.IPPROTO_IP, unix.IP_BOUND_IF, iface.Index)
case "tcp6", "udp6":
err = unix.SetsockoptInt(int(fd), unix.IPPROTO_IPV6, unix.IPV6_BOUND_IF, iface.Index)
}
})
}
}
+2 -2
View File
@@ -8,9 +8,9 @@ import (
)
func BindControl(iface *net.Interface) func(network, address string, c syscall.RawConn) error {
return func(network, address string, c syscall.RawConn) error {
return func(network, address string, c syscall.RawConn) (err error) {
return c.Control(func(fd uintptr) {
unix.BindToDevice(int(fd), iface.Name)
err = unix.BindToDevice(int(fd), iface.Name)
})
}
}
+2 -2
View File
@@ -1,5 +1,5 @@
//go:build !linux
// +build !linux
//go:build !linux && !darwin
// +build !linux,!darwin
package sockopt