summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--interfaces/bindtodevice_bsd.go5
-rw-r--r--interfaces/bindtodevice_darwin.go19
2 files changed, 22 insertions, 2 deletions
diff --git a/interfaces/bindtodevice_bsd.go b/interfaces/bindtodevice_bsd.go
index 50e21c6..226e2a8 100644
--- a/interfaces/bindtodevice_bsd.go
+++ b/interfaces/bindtodevice_bsd.go
@@ -1,10 +1,11 @@
-// +build aix freebsd openbsd netbsd darwin
+// +build aix freebsd openbsd netbsd
package interfaces
import (
"net"
- "syscall"
+
+ "golang.org/x/sys/unix"
)
// BindToInterface emulates linux's SO_BINDTODEVICE option for a socket by using
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)
+}