summaryrefslogtreecommitdiffhomepage
path: root/dhcpv4/bindtodevice_bsd.go
diff options
context:
space:
mode:
authorDmitri Goutnik <5332688+dmgk@users.noreply.github.com>2019-03-13 18:07:49 -0500
committerPablo Mazzini <pmazzini@gmail.com>2019-03-13 23:07:49 +0000
commitb57e89f69a4367faa3b6a0e41063bf144145d762 (patch)
tree1902295f9c879f31b27dcd26262019e65193e9ba /dhcpv4/bindtodevice_bsd.go
parent47951531f8c905cc79209028dd08a8894763043e (diff)
Add partial (client) binding support for BSD (#260)
Diffstat (limited to 'dhcpv4/bindtodevice_bsd.go')
-rw-r--r--dhcpv4/bindtodevice_bsd.go18
1 files changed, 18 insertions, 0 deletions
diff --git a/dhcpv4/bindtodevice_bsd.go b/dhcpv4/bindtodevice_bsd.go
new file mode 100644
index 0000000..0f1b581
--- /dev/null
+++ b/dhcpv4/bindtodevice_bsd.go
@@ -0,0 +1,18 @@
+// +build freebsd openbsd netbsd
+
+package dhcpv4
+
+import (
+ "net"
+ "syscall"
+)
+
+// BindToInterface emulates linux's SO_BINDTODEVICE option for a socket by using
+// IP_RECVIF.
+func BindToInterface(fd int, ifname string) error {
+ iface, err := net.InterfaceByName(ifname)
+ if err != nil {
+ return err
+ }
+ return syscall.SetsockoptInt(fd, syscall.IPPROTO_IP, syscall.IP_RECVIF, iface.Index)
+}