diff options
author | Pablo Mazzini <pmazzini@gmail.com> | 2021-08-09 20:22:16 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-09 20:22:16 +0100 |
commit | d4b282fe8d4cf3f8023e01e0f17cb74c510ad228 (patch) | |
tree | b83680e9f8c5ed61d9d51f44236c9d70201c3f7a /interfaces | |
parent | 427d11cea22a049c2369be32de0decb1157134fe (diff) |
[interfaces] darwin (#423)
Diffstat (limited to 'interfaces')
-rw-r--r-- | interfaces/bindtodevice_bsd.go | 5 | ||||
-rw-r--r-- | interfaces/bindtodevice_darwin.go | 19 |
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) +} |