From b57e89f69a4367faa3b6a0e41063bf144145d762 Mon Sep 17 00:00:00 2001 From: Dmitri Goutnik <5332688+dmgk@users.noreply.github.com> Date: Wed, 13 Mar 2019 18:07:49 -0500 Subject: Add partial (client) binding support for BSD (#260) --- dhcpv4/bindtodevice_bsd.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 dhcpv4/bindtodevice_bsd.go (limited to 'dhcpv4/bindtodevice_bsd.go') 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) +} -- cgit v1.2.3