summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAndrea Barberio <insomniac@slackware.it>2018-02-07 18:23:47 +0000
committerAndrea Barberio <insomniac@slackware.it>2018-02-07 18:44:00 +0000
commitd4666bc14118b32cc22ad68da36dbde8e3a93374 (patch)
tree44ed70b77cb3911dda30ad33dd595cf2527de8c6
parent7f7030121c9f6f75cfcdd8d3b58f5bd2143a6025 (diff)
Added OS-specific implementations for binding to a network device
-rw-r--r--dhcpv4/bindtodevice_darwin.go16
-rw-r--r--dhcpv4/bindtodevice_linux.go11
-rw-r--r--dhcpv4/client.go2
3 files changed, 28 insertions, 1 deletions
diff --git a/dhcpv4/bindtodevice_darwin.go b/dhcpv4/bindtodevice_darwin.go
new file mode 100644
index 0000000..e9580ce
--- /dev/null
+++ b/dhcpv4/bindtodevice_darwin.go
@@ -0,0 +1,16 @@
+// +build darwin
+
+package dhcpv4
+
+import (
+ "net"
+ "syscall"
+)
+
+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_BOUND_IF, iface.Index)
+}
diff --git a/dhcpv4/bindtodevice_linux.go b/dhcpv4/bindtodevice_linux.go
new file mode 100644
index 0000000..957744a
--- /dev/null
+++ b/dhcpv4/bindtodevice_linux.go
@@ -0,0 +1,11 @@
+// +build linux
+
+package dhcpv4
+
+import (
+ "syscall"
+)
+
+func BindToInterface(fd int, ifname string) error {
+ return syscall.BindToDevice(fd, ifname)
+}
diff --git a/dhcpv4/client.go b/dhcpv4/client.go
index 145a7ef..55f303d 100644
--- a/dhcpv4/client.go
+++ b/dhcpv4/client.go
@@ -75,7 +75,7 @@ func (c *Client) Exchange(ifname string, d *DHCPv4) ([]DHCPv4, error) {
if err != nil {
return conversation, err
}
- err = syscall.BindToDevice(fd, ifname)
+ err = BindToInterface(fd, ifname)
if err != nil {
return conversation, err
}