Skip to content

Commit

Permalink
Add partial (client) binding support for BSD (#260)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmgk authored and pmazzini committed Mar 13, 2019
1 parent 4795153 commit b57e89f
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions dhcpv4/bindtodevice_bsd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// +build freebsd openbsd netbsd

package dhcpv4

import (
"net"
"syscall"
)

// 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 syscall.SetsockoptInt(fd, syscall.IPPROTO_IP, syscall.IP_RECVIF, iface.Index)
}

0 comments on commit b57e89f

Please sign in to comment.