Debian Codegraph @

interfaces/bindtodevice_bsd.go

raw
1 // +build aix freebsd openbsd netbsd dragonfly
2
3 package interfaces
4
5 import (
6 "net"
7
8 "golang.org/x/sys/unix"
9 )
10
11 // BindToInterface emulates linux's SO_BINDTODEVICE option for a socket by using
12 // IP_RECVIF.
13 func BindToInterface(fd int, ifname string) error {
14 iface, err := net.InterfaceByName(ifname)
15 if err != nil {
16 return err
17 }
18 return unix.SetsockoptInt(fd, unix.IPPROTO_IP, unix.IP_RECVIF, iface.Index)
19 }