File: bindtodevice_bsd.go

package info (click to toggle)
golang-github-insomniacslk-dhcp 0.0~git20250417.5f8cf70-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental, forky, sid
  • size: 1,096 kB
  • sloc: makefile: 3
file content (19 lines) | stat: -rw-r--r-- 415 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// +build aix freebsd openbsd netbsd dragonfly

package interfaces

import (
	"net"

	"golang.org/x/sys/unix"
)

// BindToInterface emulates linux's SO_BINDTODEVICE option for a socket by using
// IP_RECVIF.
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_RECVIF, iface.Index)
}