diff options
Diffstat (limited to 'interfaces/bindtodevice_darwin.go')
-rw-r--r-- | interfaces/bindtodevice_darwin.go | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/interfaces/bindtodevice_darwin.go b/interfaces/bindtodevice_darwin.go new file mode 100644 index 0000000..5ddfc0e --- /dev/null +++ b/interfaces/bindtodevice_darwin.go @@ -0,0 +1,19 @@ +// +build darwin + +package interfaces + +import ( + "net" + + "golang.org/x/sys/unix" +) + +// BindToInterface emulates linux's SO_BINDTODEVICE option for a socket by using +// IP_BOUND_IF. +func BindToInterface(fd int, ifname string) error { + iface, err := net.InterfaceByName(ifname) + if err != nil { + return err + } + return unix.SetsockoptInt(fd, unix.IPPROTO_IP, unix.IP_BOUND_IF, iface.Index) +} |