Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[interfaces] darwin #423

Merged
merged 4 commits into from
Aug 9, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions interfaces/bindtodevice_bsd.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down
19 changes: 19 additions & 0 deletions interfaces/bindtodevice_darwin.go
Original file line number Diff line number Diff line change
@@ -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)
}