git » go-net » commit 7625277

ipv4: use of internal/netreflect package

author Mikio Hara
2016-08-24 21:13:12 UTC
committer Mikio Hara
2016-08-26 23:50:02 UTC
parent 6c89f9617983ee917132513a791d8b5850fe90c5

ipv4: use of internal/netreflect package

Change-Id: Idffb7eace4d7913e7dfad2715d10dcd1762f83e4
Reviewed-on: https://go-review.googlesource.com/27733
Run-TryBot: Mikio Hara <mikioh.mikioh@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>

ipv4/bpfopt_linux.go +3 -2
ipv4/control_stub.go +1 -1
ipv4/control_unix.go +5 -5
ipv4/control_windows.go +1 -1
ipv4/dgramopt_posix.go +30 -28
ipv4/endpoint.go +10 -8
ipv4/genericopt_posix.go +13 -9
ipv4/helper_stub.go +0 -23
ipv4/helper_unix.go +0 -50
ipv4/helper_windows.go +0 -49
ipv4/sockopt_asmreq_stub.go +3 -3
ipv4/sockopt_asmreq_unix.go +6 -6
ipv4/sockopt_asmreq_windows.go +6 -6
ipv4/sockopt_asmreqn_stub.go +3 -3
ipv4/sockopt_asmreqn_unix.go +4 -4
ipv4/sockopt_ssmreq_stub.go +2 -2
ipv4/sockopt_ssmreq_unix.go +4 -4
ipv4/sockopt_stub.go +1 -1
ipv4/sockopt_unix.go +20 -20
ipv4/sockopt_windows.go +13 -13
ipv4/syscall_linux_386.go +4 -4
ipv4/syscall_unix.go +4 -4

diff --git a/ipv4/bpfopt_linux.go b/ipv4/bpfopt_linux.go
index f2d00b4..e9bbda9 100644
--- a/ipv4/bpfopt_linux.go
+++ b/ipv4/bpfopt_linux.go
@@ -9,13 +9,14 @@ import (
 	"unsafe"
 
 	"golang.org/x/net/bpf"
+	"golang.org/x/net/internal/netreflect"
 )
 
 // SetBPF attaches a BPF program to the connection.
 //
 // Only supported on Linux.
 func (c *dgramOpt) SetBPF(filter []bpf.RawInstruction) error {
-	fd, err := c.sysfd()
+	s, err := netreflect.PacketSocketOf(c.PacketConn)
 	if err != nil {
 		return err
 	}
@@ -23,5 +24,5 @@ func (c *dgramOpt) SetBPF(filter []bpf.RawInstruction) error {
 		Len:    uint16(len(filter)),
 		Filter: (*sysSockFilter)(unsafe.Pointer(&filter[0])),
 	}
-	return os.NewSyscallError("setsockopt", setsockopt(fd, sysSOL_SOCKET, sysSO_ATTACH_FILTER, unsafe.Pointer(&prog), uint32(unsafe.Sizeof(prog))))
+	return os.NewSyscallError("setsockopt", setsockopt(s, sysSOL_SOCKET, sysSO_ATTACH_FILTER, unsafe.Pointer(&prog), uint32(unsafe.Sizeof(prog))))
 }
diff --git a/ipv4/control_stub.go b/ipv4/control_stub.go
index 4d85071..5f5a1bd 100644
--- a/ipv4/control_stub.go
+++ b/ipv4/control_stub.go
@@ -6,7 +6,7 @@
 
 package ipv4
 
-func setControlMessage(fd int, opt *rawOpt, cf ControlFlags, on bool) error {
+func setControlMessage(s uintptr, opt *rawOpt, cf ControlFlags, on bool) error {
 	return errOpNoSupport
 }
 
diff --git a/ipv4/control_unix.go b/ipv4/control_unix.go
index 3000c52..6b6682d 100644
--- a/ipv4/control_unix.go
+++ b/ipv4/control_unix.go
@@ -14,11 +14,11 @@ import (
 	"golang.org/x/net/internal/iana"
 )
 
-func setControlMessage(fd int, opt *rawOpt, cf ControlFlags, on bool) error {
+func setControlMessage(s uintptr, opt *rawOpt, cf ControlFlags, on bool) error {
 	opt.Lock()
 	defer opt.Unlock()
 	if cf&FlagTTL != 0 && sockOpts[ssoReceiveTTL].name > 0 {
-		if err := setInt(fd, &sockOpts[ssoReceiveTTL], boolint(on)); err != nil {
+		if err := setInt(s, &sockOpts[ssoReceiveTTL], boolint(on)); err != nil {
 			return err
 		}
 		if on {
@@ -29,7 +29,7 @@ func setControlMessage(fd int, opt *rawOpt, cf ControlFlags, on bool) error {
 	}
 	if sockOpts[ssoPacketInfo].name > 0 {
 		if cf&(FlagSrc|FlagDst|FlagInterface) != 0 {
-			if err := setInt(fd, &sockOpts[ssoPacketInfo], boolint(on)); err != nil {
+			if err := setInt(s, &sockOpts[ssoPacketInfo], boolint(on)); err != nil {
 				return err
 			}
 			if on {
@@ -40,7 +40,7 @@ func setControlMessage(fd int, opt *rawOpt, cf ControlFlags, on bool) error {
 		}
 	} else {
 		if cf&FlagDst != 0 && sockOpts[ssoReceiveDst].name > 0 {
-			if err := setInt(fd, &sockOpts[ssoReceiveDst], boolint(on)); err != nil {
+			if err := setInt(s, &sockOpts[ssoReceiveDst], boolint(on)); err != nil {
 				return err
 			}
 			if on {
@@ -50,7 +50,7 @@ func setControlMessage(fd int, opt *rawOpt, cf ControlFlags, on bool) error {
 			}
 		}
 		if cf&FlagInterface != 0 && sockOpts[ssoReceiveInterface].name > 0 {
-			if err := setInt(fd, &sockOpts[ssoReceiveInterface], boolint(on)); err != nil {
+			if err := setInt(s, &sockOpts[ssoReceiveInterface], boolint(on)); err != nil {
 				return err
 			}
 			if on {
diff --git a/ipv4/control_windows.go b/ipv4/control_windows.go
index 800f637..49a113b 100644
--- a/ipv4/control_windows.go
+++ b/ipv4/control_windows.go
@@ -6,7 +6,7 @@ package ipv4
 
 import "syscall"
 
-func setControlMessage(fd syscall.Handle, opt *rawOpt, cf ControlFlags, on bool) error {
+func setControlMessage(s uintptr, opt *rawOpt, cf ControlFlags, on bool) error {
 	// TODO(mikio): implement this
 	return syscall.EWINDOWS
 }
diff --git a/ipv4/dgramopt_posix.go b/ipv4/dgramopt_posix.go
index 103c4f6..40b5e1c 100644
--- a/ipv4/dgramopt_posix.go
+++ b/ipv4/dgramopt_posix.go
@@ -9,6 +9,8 @@ package ipv4
 import (
 	"net"
 	"syscall"
+
+	"golang.org/x/net/internal/netreflect"
 )
 
 // MulticastTTL returns the time-to-live field value for outgoing
@@ -17,11 +19,11 @@ func (c *dgramOpt) MulticastTTL() (int, error) {
 	if !c.ok() {
 		return 0, syscall.EINVAL
 	}
-	fd, err := c.sysfd()
+	s, err := netreflect.PacketSocketOf(c.PacketConn)
 	if err != nil {
 		return 0, err
 	}
-	return getInt(fd, &sockOpts[ssoMulticastTTL])
+	return getInt(s, &sockOpts[ssoMulticastTTL])
 }
 
 // SetMulticastTTL sets the time-to-live field value for future
@@ -30,11 +32,11 @@ func (c *dgramOpt) SetMulticastTTL(ttl int) error {
 	if !c.ok() {
 		return syscall.EINVAL
 	}
-	fd, err := c.sysfd()
+	s, err := netreflect.PacketSocketOf(c.PacketConn)
 	if err != nil {
 		return err
 	}
-	return setInt(fd, &sockOpts[ssoMulticastTTL], ttl)
+	return setInt(s, &sockOpts[ssoMulticastTTL], ttl)
 }
 
 // MulticastInterface returns the default interface for multicast
@@ -43,11 +45,11 @@ func (c *dgramOpt) MulticastInterface() (*net.Interface, error) {
 	if !c.ok() {
 		return nil, syscall.EINVAL
 	}
-	fd, err := c.sysfd()
+	s, err := netreflect.PacketSocketOf(c.PacketConn)
 	if err != nil {
 		return nil, err
 	}
-	return getInterface(fd, &sockOpts[ssoMulticastInterface])
+	return getInterface(s, &sockOpts[ssoMulticastInterface])
 }
 
 // SetMulticastInterface sets the default interface for future
@@ -56,11 +58,11 @@ func (c *dgramOpt) SetMulticastInterface(ifi *net.Interface) error {
 	if !c.ok() {
 		return syscall.EINVAL
 	}
-	fd, err := c.sysfd()
+	s, err := netreflect.PacketSocketOf(c.PacketConn)
 	if err != nil {
 		return err
 	}
-	return setInterface(fd, &sockOpts[ssoMulticastInterface], ifi)
+	return setInterface(s, &sockOpts[ssoMulticastInterface], ifi)
 }
 
 // MulticastLoopback reports whether transmitted multicast packets
@@ -69,11 +71,11 @@ func (c *dgramOpt) MulticastLoopback() (bool, error) {
 	if !c.ok() {
 		return false, syscall.EINVAL
 	}
-	fd, err := c.sysfd()
+	s, err := netreflect.PacketSocketOf(c.PacketConn)
 	if err != nil {
 		return false, err
 	}
-	on, err := getInt(fd, &sockOpts[ssoMulticastLoopback])
+	on, err := getInt(s, &sockOpts[ssoMulticastLoopback])
 	if err != nil {
 		return false, err
 	}
@@ -86,11 +88,11 @@ func (c *dgramOpt) SetMulticastLoopback(on bool) error {
 	if !c.ok() {
 		return syscall.EINVAL
 	}
-	fd, err := c.sysfd()
+	s, err := netreflect.PacketSocketOf(c.PacketConn)
 	if err != nil {
 		return err
 	}
-	return setInt(fd, &sockOpts[ssoMulticastLoopback], boolint(on))
+	return setInt(s, &sockOpts[ssoMulticastLoopback], boolint(on))
 }
 
 // JoinGroup joins the group address group on the interface ifi.
@@ -106,7 +108,7 @@ func (c *dgramOpt) JoinGroup(ifi *net.Interface, group net.Addr) error {
 	if !c.ok() {
 		return syscall.EINVAL
 	}
-	fd, err := c.sysfd()
+	s, err := netreflect.PacketSocketOf(c.PacketConn)
 	if err != nil {
 		return err
 	}
@@ -114,7 +116,7 @@ func (c *dgramOpt) JoinGroup(ifi *net.Interface, group net.Addr) error {
 	if grp == nil {
 		return errMissingAddress
 	}
-	return setGroup(fd, &sockOpts[ssoJoinGroup], ifi, grp)
+	return setGroup(s, &sockOpts[ssoJoinGroup], ifi, grp)
 }
 
 // LeaveGroup leaves the group address group on the interface ifi
@@ -124,7 +126,7 @@ func (c *dgramOpt) LeaveGroup(ifi *net.Interface, group net.Addr) error {
 	if !c.ok() {
 		return syscall.EINVAL
 	}
-	fd, err := c.sysfd()
+	s, err := netreflect.PacketSocketOf(c.PacketConn)
 	if err != nil {
 		return err
 	}
@@ -132,7 +134,7 @@ func (c *dgramOpt) LeaveGroup(ifi *net.Interface, group net.Addr) error {
 	if grp == nil {
 		return errMissingAddress
 	}
-	return setGroup(fd, &sockOpts[ssoLeaveGroup], ifi, grp)
+	return setGroup(s, &sockOpts[ssoLeaveGroup], ifi, grp)
 }
 
 // JoinSourceSpecificGroup joins the source-specific group comprising
@@ -145,7 +147,7 @@ func (c *dgramOpt) JoinSourceSpecificGroup(ifi *net.Interface, group, source net
 	if !c.ok() {
 		return syscall.EINVAL
 	}
-	fd, err := c.sysfd()
+	s, err := netreflect.PacketSocketOf(c.PacketConn)
 	if err != nil {
 		return err
 	}
@@ -157,7 +159,7 @@ func (c *dgramOpt) JoinSourceSpecificGroup(ifi *net.Interface, group, source net
 	if src == nil {
 		return errMissingAddress
 	}
-	return setSourceGroup(fd, &sockOpts[ssoJoinSourceGroup], ifi, grp, src)
+	return setSourceGroup(s, &sockOpts[ssoJoinSourceGroup], ifi, grp, src)
 }
 
 // LeaveSourceSpecificGroup leaves the source-specific group on the
@@ -166,7 +168,7 @@ func (c *dgramOpt) LeaveSourceSpecificGroup(ifi *net.Interface, group, source ne
 	if !c.ok() {
 		return syscall.EINVAL
 	}
-	fd, err := c.sysfd()
+	s, err := netreflect.PacketSocketOf(c.PacketConn)
 	if err != nil {
 		return err
 	}
@@ -178,7 +180,7 @@ func (c *dgramOpt) LeaveSourceSpecificGroup(ifi *net.Interface, group, source ne
 	if src == nil {
 		return errMissingAddress
 	}
-	return setSourceGroup(fd, &sockOpts[ssoLeaveSourceGroup], ifi, grp, src)
+	return setSourceGroup(s, &sockOpts[ssoLeaveSourceGroup], ifi, grp, src)
 }
 
 // ExcludeSourceSpecificGroup excludes the source-specific group from
@@ -188,7 +190,7 @@ func (c *dgramOpt) ExcludeSourceSpecificGroup(ifi *net.Interface, group, source
 	if !c.ok() {
 		return syscall.EINVAL
 	}
-	fd, err := c.sysfd()
+	s, err := netreflect.PacketSocketOf(c.PacketConn)
 	if err != nil {
 		return err
 	}
@@ -200,7 +202,7 @@ func (c *dgramOpt) ExcludeSourceSpecificGroup(ifi *net.Interface, group, source
 	if src == nil {
 		return errMissingAddress
 	}
-	return setSourceGroup(fd, &sockOpts[ssoBlockSourceGroup], ifi, grp, src)
+	return setSourceGroup(s, &sockOpts[ssoBlockSourceGroup], ifi, grp, src)
 }
 
 // IncludeSourceSpecificGroup includes the excluded source-specific
@@ -209,7 +211,7 @@ func (c *dgramOpt) IncludeSourceSpecificGroup(ifi *net.Interface, group, source
 	if !c.ok() {
 		return syscall.EINVAL
 	}
-	fd, err := c.sysfd()
+	s, err := netreflect.PacketSocketOf(c.PacketConn)
 	if err != nil {
 		return err
 	}
@@ -221,7 +223,7 @@ func (c *dgramOpt) IncludeSourceSpecificGroup(ifi *net.Interface, group, source
 	if src == nil {
 		return errMissingAddress
 	}
-	return setSourceGroup(fd, &sockOpts[ssoUnblockSourceGroup], ifi, grp, src)
+	return setSourceGroup(s, &sockOpts[ssoUnblockSourceGroup], ifi, grp, src)
 }
 
 // ICMPFilter returns an ICMP filter.
@@ -230,11 +232,11 @@ func (c *dgramOpt) ICMPFilter() (*ICMPFilter, error) {
 	if !c.ok() {
 		return nil, syscall.EINVAL
 	}
-	fd, err := c.sysfd()
+	s, err := netreflect.PacketSocketOf(c.PacketConn)
 	if err != nil {
 		return nil, err
 	}
-	return getICMPFilter(fd, &sockOpts[ssoICMPFilter])
+	return getICMPFilter(s, &sockOpts[ssoICMPFilter])
 }
 
 // SetICMPFilter deploys the ICMP filter.
@@ -243,9 +245,9 @@ func (c *dgramOpt) SetICMPFilter(f *ICMPFilter) error {
 	if !c.ok() {
 		return syscall.EINVAL
 	}
-	fd, err := c.sysfd()
+	s, err := netreflect.PacketSocketOf(c.PacketConn)
 	if err != nil {
 		return err
 	}
-	return setICMPFilter(fd, &sockOpts[ssoICMPFilter], f)
+	return setICMPFilter(s, &sockOpts[ssoICMPFilter], f)
 }
diff --git a/ipv4/endpoint.go b/ipv4/endpoint.go
index bc45bf0..a8ca2ff 100644
--- a/ipv4/endpoint.go
+++ b/ipv4/endpoint.go
@@ -8,6 +8,8 @@ import (
 	"net"
 	"syscall"
 	"time"
+
+	"golang.org/x/net/internal/netreflect"
 )
 
 // A Conn represents a network endpoint that uses the IPv4 transport.
@@ -52,11 +54,11 @@ func (c *PacketConn) SetControlMessage(cf ControlFlags, on bool) error {
 	if !c.payloadHandler.ok() {
 		return syscall.EINVAL
 	}
-	fd, err := c.payloadHandler.sysfd()
+	s, err := netreflect.PacketSocketOf(c.dgramOpt.PacketConn)
 	if err != nil {
 		return err
 	}
-	return setControlMessage(fd, &c.payloadHandler.rawOpt, cf, on)
+	return setControlMessage(s, &c.payloadHandler.rawOpt, cf, on)
 }
 
 // SetDeadline sets the read and write deadlines associated with the
@@ -103,8 +105,8 @@ func NewPacketConn(c net.PacketConn) *PacketConn {
 		payloadHandler: payloadHandler{PacketConn: c},
 	}
 	if _, ok := c.(*net.IPConn); ok && sockOpts[ssoStripHeader].name > 0 {
-		if fd, err := p.payloadHandler.sysfd(); err == nil {
-			setInt(fd, &sockOpts[ssoStripHeader], boolint(true))
+		if s, err := netreflect.PacketSocketOf(c); err == nil {
+			setInt(s, &sockOpts[ssoStripHeader], boolint(true))
 		}
 	}
 	return p
@@ -126,11 +128,11 @@ func (c *RawConn) SetControlMessage(cf ControlFlags, on bool) error {
 	if !c.packetHandler.ok() {
 		return syscall.EINVAL
 	}
-	fd, err := c.packetHandler.sysfd()
+	s, err := netreflect.PacketSocketOf(c.dgramOpt.PacketConn)
 	if err != nil {
 		return err
 	}
-	return setControlMessage(fd, &c.packetHandler.rawOpt, cf, on)
+	return setControlMessage(s, &c.packetHandler.rawOpt, cf, on)
 }
 
 // SetDeadline sets the read and write deadlines associated with the
@@ -176,11 +178,11 @@ func NewRawConn(c net.PacketConn) (*RawConn, error) {
 		dgramOpt:      dgramOpt{PacketConn: c},
 		packetHandler: packetHandler{c: c.(*net.IPConn)},
 	}
-	fd, err := r.packetHandler.sysfd()
+	s, err := netreflect.PacketSocketOf(c)
 	if err != nil {
 		return nil, err
 	}
-	if err := setInt(fd, &sockOpts[ssoHeaderPrepend], boolint(true)); err != nil {
+	if err := setInt(s, &sockOpts[ssoHeaderPrepend], boolint(true)); err != nil {
 		return nil, err
 	}
 	return r, nil
diff --git a/ipv4/genericopt_posix.go b/ipv4/genericopt_posix.go
index fefa0be..53bc79f 100644
--- a/ipv4/genericopt_posix.go
+++ b/ipv4/genericopt_posix.go
@@ -6,18 +6,22 @@
 
 package ipv4
 
-import "syscall"
+import (
+	"syscall"
+
+	"golang.org/x/net/internal/netreflect"
+)
 
 // TOS returns the type-of-service field value for outgoing packets.
 func (c *genericOpt) TOS() (int, error) {
 	if !c.ok() {
 		return 0, syscall.EINVAL
 	}
-	fd, err := c.sysfd()
+	s, err := netreflect.SocketOf(c.Conn)
 	if err != nil {
 		return 0, err
 	}
-	return getInt(fd, &sockOpts[ssoTOS])
+	return getInt(s, &sockOpts[ssoTOS])
 }
 
 // SetTOS sets the type-of-service field value for future outgoing
@@ -26,11 +30,11 @@ func (c *genericOpt) SetTOS(tos int) error {
 	if !c.ok() {
 		return syscall.EINVAL
 	}
-	fd, err := c.sysfd()
+	s, err := netreflect.SocketOf(c.Conn)
 	if err != nil {
 		return err
 	}
-	return setInt(fd, &sockOpts[ssoTOS], tos)
+	return setInt(s, &sockOpts[ssoTOS], tos)
 }
 
 // TTL returns the time-to-live field value for outgoing packets.
@@ -38,11 +42,11 @@ func (c *genericOpt) TTL() (int, error) {
 	if !c.ok() {
 		return 0, syscall.EINVAL
 	}
-	fd, err := c.sysfd()
+	s, err := netreflect.SocketOf(c.Conn)
 	if err != nil {
 		return 0, err
 	}
-	return getInt(fd, &sockOpts[ssoTTL])
+	return getInt(s, &sockOpts[ssoTTL])
 }
 
 // SetTTL sets the time-to-live field value for future outgoing
@@ -51,9 +55,9 @@ func (c *genericOpt) SetTTL(ttl int) error {
 	if !c.ok() {
 		return syscall.EINVAL
 	}
-	fd, err := c.sysfd()
+	s, err := netreflect.SocketOf(c.Conn)
 	if err != nil {
 		return err
 	}
-	return setInt(fd, &sockOpts[ssoTTL], ttl)
+	return setInt(s, &sockOpts[ssoTTL], ttl)
 }
diff --git a/ipv4/helper_stub.go b/ipv4/helper_stub.go
deleted file mode 100644
index dc2120c..0000000
--- a/ipv4/helper_stub.go
+++ /dev/null
@@ -1,23 +0,0 @@
-// Copyright 2012 The Go Authors.  All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// +build nacl plan9 solaris
-
-package ipv4
-
-func (c *genericOpt) sysfd() (int, error) {
-	return 0, errOpNoSupport
-}
-
-func (c *dgramOpt) sysfd() (int, error) {
-	return 0, errOpNoSupport
-}
-
-func (c *payloadHandler) sysfd() (int, error) {
-	return 0, errOpNoSupport
-}
-
-func (c *packetHandler) sysfd() (int, error) {
-	return 0, errOpNoSupport
-}
diff --git a/ipv4/helper_unix.go b/ipv4/helper_unix.go
deleted file mode 100644
index 345ca7d..0000000
--- a/ipv4/helper_unix.go
+++ /dev/null
@@ -1,50 +0,0 @@
-// Copyright 2012 The Go Authors.  All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// +build darwin dragonfly freebsd linux netbsd openbsd
-
-package ipv4
-
-import (
-	"net"
-	"reflect"
-)
-
-func (c *genericOpt) sysfd() (int, error) {
-	switch p := c.Conn.(type) {
-	case *net.TCPConn, *net.UDPConn, *net.IPConn:
-		return sysfd(p)
-	}
-	return 0, errInvalidConnType
-}
-
-func (c *dgramOpt) sysfd() (int, error) {
-	switch p := c.PacketConn.(type) {
-	case *net.UDPConn, *net.IPConn:
-		return sysfd(p.(net.Conn))
-	}
-	return 0, errInvalidConnType
-}
-
-func (c *payloadHandler) sysfd() (int, error) {
-	return sysfd(c.PacketConn.(net.Conn))
-}
-
-func (c *packetHandler) sysfd() (int, error) {
-	return sysfd(c.c)
-}
-
-func sysfd(c net.Conn) (int, error) {
-	cv := reflect.ValueOf(c)
-	switch ce := cv.Elem(); ce.Kind() {
-	case reflect.Struct:
-		netfd := ce.FieldByName("conn").FieldByName("fd")
-		switch fe := netfd.Elem(); fe.Kind() {
-		case reflect.Struct:
-			fd := fe.FieldByName("sysfd")
-			return int(fd.Int()), nil
-		}
-	}
-	return 0, errInvalidConnType
-}
diff --git a/ipv4/helper_windows.go b/ipv4/helper_windows.go
deleted file mode 100644
index 322b2a5..0000000
--- a/ipv4/helper_windows.go
+++ /dev/null
@@ -1,49 +0,0 @@
-// Copyright 2012 The Go Authors.  All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package ipv4
-
-import (
-	"net"
-	"reflect"
-	"syscall"
-)
-
-func (c *genericOpt) sysfd() (syscall.Handle, error) {
-	switch p := c.Conn.(type) {
-	case *net.TCPConn, *net.UDPConn, *net.IPConn:
-		return sysfd(p)
-	}
-	return syscall.InvalidHandle, errInvalidConnType
-}
-
-func (c *dgramOpt) sysfd() (syscall.Handle, error) {
-	switch p := c.PacketConn.(type) {
-	case *net.UDPConn, *net.IPConn:
-		return sysfd(p.(net.Conn))
-	}
-	return syscall.InvalidHandle, errInvalidConnType
-}
-
-func (c *payloadHandler) sysfd() (syscall.Handle, error) {
-	return sysfd(c.PacketConn.(net.Conn))
-}
-
-func (c *packetHandler) sysfd() (syscall.Handle, error) {
-	return sysfd(c.c)
-}
-
-func sysfd(c net.Conn) (syscall.Handle, error) {
-	cv := reflect.ValueOf(c)
-	switch ce := cv.Elem(); ce.Kind() {
-	case reflect.Struct:
-		netfd := ce.FieldByName("conn").FieldByName("fd")
-		switch fe := netfd.Elem(); fe.Kind() {
-		case reflect.Struct:
-			fd := fe.FieldByName("sysfd")
-			return syscall.Handle(fd.Uint()), nil
-		}
-	}
-	return syscall.InvalidHandle, errInvalidConnType
-}
diff --git a/ipv4/sockopt_asmreq_stub.go b/ipv4/sockopt_asmreq_stub.go
index 4555152..9f7b655 100644
--- a/ipv4/sockopt_asmreq_stub.go
+++ b/ipv4/sockopt_asmreq_stub.go
@@ -8,14 +8,14 @@ package ipv4
 
 import "net"
 
-func setsockoptIPMreq(fd, name int, ifi *net.Interface, grp net.IP) error {
+func setsockoptIPMreq(s uintptr, name int, ifi *net.Interface, grp net.IP) error {
 	return errOpNoSupport
 }
 
-func getsockoptInterface(fd, name int) (*net.Interface, error) {
+func getsockoptInterface(s uintptr, name int) (*net.Interface, error) {
 	return nil, errOpNoSupport
 }
 
-func setsockoptInterface(fd, name int, ifi *net.Interface) error {
+func setsockoptInterface(s uintptr, name int, ifi *net.Interface) error {
 	return errOpNoSupport
 }
diff --git a/ipv4/sockopt_asmreq_unix.go b/ipv4/sockopt_asmreq_unix.go
index 7b5c329..757097e 100644
--- a/ipv4/sockopt_asmreq_unix.go
+++ b/ipv4/sockopt_asmreq_unix.go
@@ -14,18 +14,18 @@ import (
 	"golang.org/x/net/internal/iana"
 )
 
-func setsockoptIPMreq(fd, name int, ifi *net.Interface, grp net.IP) error {
+func setsockoptIPMreq(s uintptr, name int, ifi *net.Interface, grp net.IP) error {
 	mreq := sysIPMreq{Multiaddr: [4]byte{grp[0], grp[1], grp[2], grp[3]}}
 	if err := setIPMreqInterface(&mreq, ifi); err != nil {
 		return err
 	}
-	return os.NewSyscallError("setsockopt", setsockopt(fd, iana.ProtocolIP, name, unsafe.Pointer(&mreq), sysSizeofIPMreq))
+	return os.NewSyscallError("setsockopt", setsockopt(s, iana.ProtocolIP, name, unsafe.Pointer(&mreq), sysSizeofIPMreq))
 }
 
-func getsockoptInterface(fd, name int) (*net.Interface, error) {
+func getsockoptInterface(s uintptr, name int) (*net.Interface, error) {
 	var b [4]byte
 	l := uint32(4)
-	if err := getsockopt(fd, iana.ProtocolIP, name, unsafe.Pointer(&b[0]), &l); err != nil {
+	if err := getsockopt(s, iana.ProtocolIP, name, unsafe.Pointer(&b[0]), &l); err != nil {
 		return nil, os.NewSyscallError("getsockopt", err)
 	}
 	ifi, err := netIP4ToInterface(net.IPv4(b[0], b[1], b[2], b[3]))
@@ -35,12 +35,12 @@ func getsockoptInterface(fd, name int) (*net.Interface, error) {
 	return ifi, nil
 }
 
-func setsockoptInterface(fd, name int, ifi *net.Interface) error {
+func setsockoptInterface(s uintptr, name int, ifi *net.Interface) error {
 	ip, err := netInterfaceToIP4(ifi)
 	if err != nil {
 		return err
 	}
 	var b [4]byte
 	copy(b[:], ip)
-	return os.NewSyscallError("setsockopt", setsockopt(fd, iana.ProtocolIP, name, unsafe.Pointer(&b[0]), uint32(4)))
+	return os.NewSyscallError("setsockopt", setsockopt(s, iana.ProtocolIP, name, unsafe.Pointer(&b[0]), uint32(4)))
 }
diff --git a/ipv4/sockopt_asmreq_windows.go b/ipv4/sockopt_asmreq_windows.go
index 431930d..9eda6fa 100644
--- a/ipv4/sockopt_asmreq_windows.go
+++ b/ipv4/sockopt_asmreq_windows.go
@@ -13,18 +13,18 @@ import (
 	"golang.org/x/net/internal/iana"
 )
 
-func setsockoptIPMreq(fd syscall.Handle, name int, ifi *net.Interface, grp net.IP) error {
+func setsockoptIPMreq(s uintptr, name int, ifi *net.Interface, grp net.IP) error {
 	mreq := sysIPMreq{Multiaddr: [4]byte{grp[0], grp[1], grp[2], grp[3]}}
 	if err := setIPMreqInterface(&mreq, ifi); err != nil {
 		return err
 	}
-	return os.NewSyscallError("setsockopt", syscall.Setsockopt(fd, iana.ProtocolIP, int32(name), (*byte)(unsafe.Pointer(&mreq)), int32(sysSizeofIPMreq)))
+	return os.NewSyscallError("setsockopt", syscall.Setsockopt(syscall.Handle(s), iana.ProtocolIP, int32(name), (*byte)(unsafe.Pointer(&mreq)), int32(sysSizeofIPMreq)))
 }
 
-func getsockoptInterface(fd syscall.Handle, name int) (*net.Interface, error) {
+func getsockoptInterface(s uintptr, name int) (*net.Interface, error) {
 	var b [4]byte
 	l := int32(4)
-	if err := syscall.Getsockopt(fd, iana.ProtocolIP, int32(name), (*byte)(unsafe.Pointer(&b[0])), &l); err != nil {
+	if err := syscall.Getsockopt(syscall.Handle(s), iana.ProtocolIP, int32(name), (*byte)(unsafe.Pointer(&b[0])), &l); err != nil {
 		return nil, os.NewSyscallError("getsockopt", err)
 	}
 	ifi, err := netIP4ToInterface(net.IPv4(b[0], b[1], b[2], b[3]))
@@ -34,12 +34,12 @@ func getsockoptInterface(fd syscall.Handle, name int) (*net.Interface, error) {
 	return ifi, nil
 }
 
-func setsockoptInterface(fd syscall.Handle, name int, ifi *net.Interface) error {
+func setsockoptInterface(s uintptr, name int, ifi *net.Interface) error {
 	ip, err := netInterfaceToIP4(ifi)
 	if err != nil {
 		return err
 	}
 	var b [4]byte
 	copy(b[:], ip)
-	return os.NewSyscallError("setsockopt", syscall.Setsockopt(fd, iana.ProtocolIP, int32(name), (*byte)(unsafe.Pointer(&b[0])), 4))
+	return os.NewSyscallError("setsockopt", syscall.Setsockopt(syscall.Handle(s), iana.ProtocolIP, int32(name), (*byte)(unsafe.Pointer(&b[0])), 4))
 }
diff --git a/ipv4/sockopt_asmreqn_stub.go b/ipv4/sockopt_asmreqn_stub.go
index 332f403..0c7f0f8 100644
--- a/ipv4/sockopt_asmreqn_stub.go
+++ b/ipv4/sockopt_asmreqn_stub.go
@@ -2,16 +2,16 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build !darwin,!freebsd,!linux,!windows
+// +build !darwin,!freebsd,!linux
 
 package ipv4
 
 import "net"
 
-func getsockoptIPMreqn(fd, name int) (*net.Interface, error) {
+func getsockoptIPMreqn(s uintptr, name int) (*net.Interface, error) {
 	return nil, errOpNoSupport
 }
 
-func setsockoptIPMreqn(fd, name int, ifi *net.Interface, grp net.IP) error {
+func setsockoptIPMreqn(s uintptr, name int, ifi *net.Interface, grp net.IP) error {
 	return errOpNoSupport
 }
diff --git a/ipv4/sockopt_asmreqn_unix.go b/ipv4/sockopt_asmreqn_unix.go
index 1f2b9a1..9d4069f 100644
--- a/ipv4/sockopt_asmreqn_unix.go
+++ b/ipv4/sockopt_asmreqn_unix.go
@@ -14,10 +14,10 @@ import (
 	"golang.org/x/net/internal/iana"
 )
 
-func getsockoptIPMreqn(fd, name int) (*net.Interface, error) {
+func getsockoptIPMreqn(s uintptr, name int) (*net.Interface, error) {
 	var mreqn sysIPMreqn
 	l := uint32(sysSizeofIPMreqn)
-	if err := getsockopt(fd, iana.ProtocolIP, name, unsafe.Pointer(&mreqn), &l); err != nil {
+	if err := getsockopt(s, iana.ProtocolIP, name, unsafe.Pointer(&mreqn), &l); err != nil {
 		return nil, os.NewSyscallError("getsockopt", err)
 	}
 	if mreqn.Ifindex == 0 {
@@ -30,7 +30,7 @@ func getsockoptIPMreqn(fd, name int) (*net.Interface, error) {
 	return ifi, nil
 }
 
-func setsockoptIPMreqn(fd, name int, ifi *net.Interface, grp net.IP) error {
+func setsockoptIPMreqn(s uintptr, name int, ifi *net.Interface, grp net.IP) error {
 	var mreqn sysIPMreqn
 	if ifi != nil {
 		mreqn.Ifindex = int32(ifi.Index)
@@ -38,5 +38,5 @@ func setsockoptIPMreqn(fd, name int, ifi *net.Interface, grp net.IP) error {
 	if grp != nil {
 		mreqn.Multiaddr = [4]byte{grp[0], grp[1], grp[2], grp[3]}
 	}
-	return os.NewSyscallError("setsockopt", setsockopt(fd, iana.ProtocolIP, name, unsafe.Pointer(&mreqn), sysSizeofIPMreqn))
+	return os.NewSyscallError("setsockopt", setsockopt(s, iana.ProtocolIP, name, unsafe.Pointer(&mreqn), sysSizeofIPMreqn))
 }
diff --git a/ipv4/sockopt_ssmreq_stub.go b/ipv4/sockopt_ssmreq_stub.go
index 8546524..e2d98fd 100644
--- a/ipv4/sockopt_ssmreq_stub.go
+++ b/ipv4/sockopt_ssmreq_stub.go
@@ -8,10 +8,10 @@ package ipv4
 
 import "net"
 
-func setsockoptGroupReq(fd, name int, ifi *net.Interface, grp net.IP) error {
+func setsockoptGroupReq(s uintptr, name int, ifi *net.Interface, grp net.IP) error {
 	return errOpNoSupport
 }
 
-func setsockoptGroupSourceReq(fd, name int, ifi *net.Interface, grp, src net.IP) error {
+func setsockoptGroupSourceReq(s uintptr, name int, ifi *net.Interface, grp, src net.IP) error {
 	return errOpNoSupport
 }
diff --git a/ipv4/sockopt_ssmreq_unix.go b/ipv4/sockopt_ssmreq_unix.go
index 0a672b6..588e9b9 100644
--- a/ipv4/sockopt_ssmreq_unix.go
+++ b/ipv4/sockopt_ssmreq_unix.go
@@ -16,7 +16,7 @@ import (
 
 var freebsd32o64 bool
 
-func setsockoptGroupReq(fd, name int, ifi *net.Interface, grp net.IP) error {
+func setsockoptGroupReq(s uintptr, name int, ifi *net.Interface, grp net.IP) error {
 	var gr sysGroupReq
 	if ifi != nil {
 		gr.Interface = uint32(ifi.Index)
@@ -35,10 +35,10 @@ func setsockoptGroupReq(fd, name int, ifi *net.Interface, grp net.IP) error {
 		p = unsafe.Pointer(&gr)
 		l = sysSizeofGroupReq
 	}
-	return os.NewSyscallError("setsockopt", setsockopt(fd, iana.ProtocolIP, name, p, l))
+	return os.NewSyscallError("setsockopt", setsockopt(s, iana.ProtocolIP, name, p, l))
 }
 
-func setsockoptGroupSourceReq(fd, name int, ifi *net.Interface, grp, src net.IP) error {
+func setsockoptGroupSourceReq(s uintptr, name int, ifi *net.Interface, grp, src net.IP) error {
 	var gsr sysGroupSourceReq
 	if ifi != nil {
 		gsr.Interface = uint32(ifi.Index)
@@ -57,5 +57,5 @@ func setsockoptGroupSourceReq(fd, name int, ifi *net.Interface, grp, src net.IP)
 		p = unsafe.Pointer(&gsr)
 		l = sysSizeofGroupSourceReq
 	}
-	return os.NewSyscallError("setsockopt", setsockopt(fd, iana.ProtocolIP, name, p, l))
+	return os.NewSyscallError("setsockopt", setsockopt(s, iana.ProtocolIP, name, p, l))
 }
diff --git a/ipv4/sockopt_stub.go b/ipv4/sockopt_stub.go
index 9d19f5d..7cfe57c 100644
--- a/ipv4/sockopt_stub.go
+++ b/ipv4/sockopt_stub.go
@@ -6,6 +6,6 @@
 
 package ipv4
 
-func setInt(fd int, opt *sockOpt, v int) error {
+func setInt(s uintptr, opt *sockOpt, v int) error {
 	return errOpNoSupport
 }
diff --git a/ipv4/sockopt_unix.go b/ipv4/sockopt_unix.go
index f7acc6b..fbb28df 100644
--- a/ipv4/sockopt_unix.go
+++ b/ipv4/sockopt_unix.go
@@ -14,7 +14,7 @@ import (
 	"golang.org/x/net/internal/iana"
 )
 
-func getInt(fd int, opt *sockOpt) (int, error) {
+func getInt(s uintptr, opt *sockOpt) (int, error) {
 	if opt.name < 1 || (opt.typ != ssoTypeByte && opt.typ != ssoTypeInt) {
 		return 0, errOpNoSupport
 	}
@@ -26,7 +26,7 @@ func getInt(fd int, opt *sockOpt) (int, error) {
 		p = unsafe.Pointer(&b)
 		l = 1
 	}
-	if err := getsockopt(fd, iana.ProtocolIP, opt.name, p, &l); err != nil {
+	if err := getsockopt(s, iana.ProtocolIP, opt.name, p, &l); err != nil {
 		return 0, os.NewSyscallError("getsockopt", err)
 	}
 	if opt.typ == ssoTypeByte {
@@ -35,7 +35,7 @@ func getInt(fd int, opt *sockOpt) (int, error) {
 	return int(i), nil
 }
 
-func setInt(fd int, opt *sockOpt, v int) error {
+func setInt(s uintptr, opt *sockOpt, v int) error {
 	if opt.name < 1 || (opt.typ != ssoTypeByte && opt.typ != ssoTypeInt) {
 		return errOpNoSupport
 	}
@@ -48,75 +48,75 @@ func setInt(fd int, opt *sockOpt, v int) error {
 		p = unsafe.Pointer(&b)
 		l = 1
 	}
-	return os.NewSyscallError("setsockopt", setsockopt(fd, iana.ProtocolIP, opt.name, p, l))
+	return os.NewSyscallError("setsockopt", setsockopt(s, iana.ProtocolIP, opt.name, p, l))
 }
 
-func getInterface(fd int, opt *sockOpt) (*net.Interface, error) {
+func getInterface(s uintptr, opt *sockOpt) (*net.Interface, error) {
 	if opt.name < 1 {
 		return nil, errOpNoSupport
 	}
 	switch opt.typ {
 	case ssoTypeInterface:
-		return getsockoptInterface(fd, opt.name)
+		return getsockoptInterface(s, opt.name)
 	case ssoTypeIPMreqn:
-		return getsockoptIPMreqn(fd, opt.name)
+		return getsockoptIPMreqn(s, opt.name)
 	default:
 		return nil, errOpNoSupport
 	}
 }
 
-func setInterface(fd int, opt *sockOpt, ifi *net.Interface) error {
+func setInterface(s uintptr, opt *sockOpt, ifi *net.Interface) error {
 	if opt.name < 1 {
 		return errOpNoSupport
 	}
 	switch opt.typ {
 	case ssoTypeInterface:
-		return setsockoptInterface(fd, opt.name, ifi)
+		return setsockoptInterface(s, opt.name, ifi)
 	case ssoTypeIPMreqn:
-		return setsockoptIPMreqn(fd, opt.name, ifi, nil)
+		return setsockoptIPMreqn(s, opt.name, ifi, nil)
 	default:
 		return errOpNoSupport
 	}
 }
 
-func getICMPFilter(fd int, opt *sockOpt) (*ICMPFilter, error) {
+func getICMPFilter(s uintptr, opt *sockOpt) (*ICMPFilter, error) {
 	if opt.name < 1 || opt.typ != ssoTypeICMPFilter {
 		return nil, errOpNoSupport
 	}
 	var f ICMPFilter
 	l := uint32(sysSizeofICMPFilter)
-	if err := getsockopt(fd, iana.ProtocolReserved, opt.name, unsafe.Pointer(&f.sysICMPFilter), &l); err != nil {
+	if err := getsockopt(s, iana.ProtocolReserved, opt.name, unsafe.Pointer(&f.sysICMPFilter), &l); err != nil {
 		return nil, os.NewSyscallError("getsockopt", err)
 	}
 	return &f, nil
 }
 
-func setICMPFilter(fd int, opt *sockOpt, f *ICMPFilter) error {
+func setICMPFilter(s uintptr, opt *sockOpt, f *ICMPFilter) error {
 	if opt.name < 1 || opt.typ != ssoTypeICMPFilter {
 		return errOpNoSupport
 	}
-	return os.NewSyscallError("setsockopt", setsockopt(fd, iana.ProtocolReserved, opt.name, unsafe.Pointer(&f.sysICMPFilter), sysSizeofICMPFilter))
+	return os.NewSyscallError("setsockopt", setsockopt(s, iana.ProtocolReserved, opt.name, unsafe.Pointer(&f.sysICMPFilter), sysSizeofICMPFilter))
 }
 
-func setGroup(fd int, opt *sockOpt, ifi *net.Interface, grp net.IP) error {
+func setGroup(s uintptr, opt *sockOpt, ifi *net.Interface, grp net.IP) error {
 	if opt.name < 1 {
 		return errOpNoSupport
 	}
 	switch opt.typ {
 	case ssoTypeIPMreq:
-		return setsockoptIPMreq(fd, opt.name, ifi, grp)
+		return setsockoptIPMreq(s, opt.name, ifi, grp)
 	case ssoTypeIPMreqn:
-		return setsockoptIPMreqn(fd, opt.name, ifi, grp)
+		return setsockoptIPMreqn(s, opt.name, ifi, grp)
 	case ssoTypeGroupReq:
-		return setsockoptGroupReq(fd, opt.name, ifi, grp)
+		return setsockoptGroupReq(s, opt.name, ifi, grp)
 	default:
 		return errOpNoSupport
 	}
 }
 
-func setSourceGroup(fd int, opt *sockOpt, ifi *net.Interface, grp, src net.IP) error {
+func setSourceGroup(s uintptr, opt *sockOpt, ifi *net.Interface, grp, src net.IP) error {
 	if opt.name < 1 || opt.typ != ssoTypeGroupSourceReq {
 		return errOpNoSupport
 	}
-	return setsockoptGroupSourceReq(fd, opt.name, ifi, grp, src)
+	return setsockoptGroupSourceReq(s, opt.name, ifi, grp, src)
 }
diff --git a/ipv4/sockopt_windows.go b/ipv4/sockopt_windows.go
index c4c2441..3d4d9ad 100644
--- a/ipv4/sockopt_windows.go
+++ b/ipv4/sockopt_windows.go
@@ -13,56 +13,56 @@ import (
 	"golang.org/x/net/internal/iana"
 )
 
-func getInt(fd syscall.Handle, opt *sockOpt) (int, error) {
+func getInt(s uintptr, opt *sockOpt) (int, error) {
 	if opt.name < 1 || opt.typ != ssoTypeInt {
 		return 0, errOpNoSupport
 	}
 	var i int32
 	l := int32(4)
-	if err := syscall.Getsockopt(fd, iana.ProtocolIP, int32(opt.name), (*byte)(unsafe.Pointer(&i)), &l); err != nil {
+	if err := syscall.Getsockopt(syscall.Handle(s), iana.ProtocolIP, int32(opt.name), (*byte)(unsafe.Pointer(&i)), &l); err != nil {
 		return 0, os.NewSyscallError("getsockopt", err)
 	}
 	return int(i), nil
 }
 
-func setInt(fd syscall.Handle, opt *sockOpt, v int) error {
+func setInt(s uintptr, opt *sockOpt, v int) error {
 	if opt.name < 1 || opt.typ != ssoTypeInt {
 		return errOpNoSupport
 	}
 	i := int32(v)
-	return os.NewSyscallError("setsockopt", syscall.Setsockopt(fd, iana.ProtocolIP, int32(opt.name), (*byte)(unsafe.Pointer(&i)), 4))
+	return os.NewSyscallError("setsockopt", syscall.Setsockopt(syscall.Handle(s), iana.ProtocolIP, int32(opt.name), (*byte)(unsafe.Pointer(&i)), 4))
 }
 
-func getInterface(fd syscall.Handle, opt *sockOpt) (*net.Interface, error) {
+func getInterface(s uintptr, opt *sockOpt) (*net.Interface, error) {
 	if opt.name < 1 || opt.typ != ssoTypeInterface {
 		return nil, errOpNoSupport
 	}
-	return getsockoptInterface(fd, opt.name)
+	return getsockoptInterface(s, opt.name)
 }
 
-func setInterface(fd syscall.Handle, opt *sockOpt, ifi *net.Interface) error {
+func setInterface(s uintptr, opt *sockOpt, ifi *net.Interface) error {
 	if opt.name < 1 || opt.typ != ssoTypeInterface {
 		return errOpNoSupport
 	}
-	return setsockoptInterface(fd, opt.name, ifi)
+	return setsockoptInterface(s, opt.name, ifi)
 }
 
-func getICMPFilter(fd syscall.Handle, opt *sockOpt) (*ICMPFilter, error) {
+func getICMPFilter(s uintptr, opt *sockOpt) (*ICMPFilter, error) {
 	return nil, errOpNoSupport
 }
 
-func setICMPFilter(fd syscall.Handle, opt *sockOpt, f *ICMPFilter) error {
+func setICMPFilter(s uintptr, opt *sockOpt, f *ICMPFilter) error {
 	return errOpNoSupport
 }
 
-func setGroup(fd syscall.Handle, opt *sockOpt, ifi *net.Interface, grp net.IP) error {
+func setGroup(s uintptr, opt *sockOpt, ifi *net.Interface, grp net.IP) error {
 	if opt.name < 1 || opt.typ != ssoTypeIPMreq {
 		return errOpNoSupport
 	}
-	return setsockoptIPMreq(fd, opt.name, ifi, grp)
+	return setsockoptIPMreq(s, opt.name, ifi, grp)
 }
 
-func setSourceGroup(fd syscall.Handle, opt *sockOpt, ifi *net.Interface, grp, src net.IP) error {
+func setSourceGroup(s uintptr, opt *sockOpt, ifi *net.Interface, grp, src net.IP) error {
 	// TODO(mikio): implement this
 	return errOpNoSupport
 }
diff --git a/ipv4/syscall_linux_386.go b/ipv4/syscall_linux_386.go
index 07a3a28..84f60bf 100644
--- a/ipv4/syscall_linux_386.go
+++ b/ipv4/syscall_linux_386.go
@@ -16,15 +16,15 @@ const (
 
 func socketcall(call int, a0, a1, a2, a3, a4, a5 uintptr) (int, syscall.Errno)
 
-func getsockopt(fd, level, name int, v unsafe.Pointer, l *uint32) error {
-	if _, errno := socketcall(sysGETSOCKOPT, uintptr(fd), uintptr(level), uintptr(name), uintptr(v), uintptr(unsafe.Pointer(l)), 0); errno != 0 {
+func getsockopt(s uintptr, level, name int, v unsafe.Pointer, l *uint32) error {
+	if _, errno := socketcall(sysGETSOCKOPT, s, uintptr(level), uintptr(name), uintptr(v), uintptr(unsafe.Pointer(l)), 0); errno != 0 {
 		return error(errno)
 	}
 	return nil
 }
 
-func setsockopt(fd, level, name int, v unsafe.Pointer, l uint32) error {
-	if _, errno := socketcall(sysSETSOCKOPT, uintptr(fd), uintptr(level), uintptr(name), uintptr(v), uintptr(l), 0); errno != 0 {
+func setsockopt(s uintptr, level, name int, v unsafe.Pointer, l uint32) error {
+	if _, errno := socketcall(sysSETSOCKOPT, s, uintptr(level), uintptr(name), uintptr(v), uintptr(l), 0); errno != 0 {
 		return error(errno)
 	}
 	return nil
diff --git a/ipv4/syscall_unix.go b/ipv4/syscall_unix.go
index 88a41b0..d952763 100644
--- a/ipv4/syscall_unix.go
+++ b/ipv4/syscall_unix.go
@@ -11,15 +11,15 @@ import (
 	"unsafe"
 )
 
-func getsockopt(fd, level, name int, v unsafe.Pointer, l *uint32) error {
-	if _, _, errno := syscall.Syscall6(syscall.SYS_GETSOCKOPT, uintptr(fd), uintptr(level), uintptr(name), uintptr(v), uintptr(unsafe.Pointer(l)), 0); errno != 0 {
+func getsockopt(s uintptr, level, name int, v unsafe.Pointer, l *uint32) error {
+	if _, _, errno := syscall.Syscall6(syscall.SYS_GETSOCKOPT, s, uintptr(level), uintptr(name), uintptr(v), uintptr(unsafe.Pointer(l)), 0); errno != 0 {
 		return error(errno)
 	}
 	return nil
 }
 
-func setsockopt(fd, level, name int, v unsafe.Pointer, l uint32) error {
-	if _, _, errno := syscall.Syscall6(syscall.SYS_SETSOCKOPT, uintptr(fd), uintptr(level), uintptr(name), uintptr(v), uintptr(l), 0); errno != 0 {
+func setsockopt(s uintptr, level, name int, v unsafe.Pointer, l uint32) error {
+	if _, _, errno := syscall.Syscall6(syscall.SYS_SETSOCKOPT, s, uintptr(level), uintptr(name), uintptr(v), uintptr(l), 0); errno != 0 {
 		return error(errno)
 	}
 	return nil