Commit 7722dc0a authored by Mikio Hara's avatar Mikio Hara

ipv6: use of internal/netreflect package

Change-Id: Idb2a2eb354c2835e6cae7e269730c599abb1c8d7
Reviewed-on: https://go-review.googlesource.com/27735
Run-TryBot: Mikio Hara <mikioh.mikioh@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarIan Lance Taylor <iant@golang.org>
parent 76252777
...@@ -9,13 +9,14 @@ import ( ...@@ -9,13 +9,14 @@ import (
"unsafe" "unsafe"
"golang.org/x/net/bpf" "golang.org/x/net/bpf"
"golang.org/x/net/internal/netreflect"
) )
// SetBPF attaches a BPF program to the connection. // SetBPF attaches a BPF program to the connection.
// //
// Only supported on Linux. // Only supported on Linux.
func (c *dgramOpt) SetBPF(filter []bpf.RawInstruction) error { func (c *dgramOpt) SetBPF(filter []bpf.RawInstruction) error {
fd, err := c.sysfd() s, err := netreflect.PacketSocketOf(c.PacketConn)
if err != nil { if err != nil {
return err return err
} }
...@@ -23,5 +24,5 @@ func (c *dgramOpt) SetBPF(filter []bpf.RawInstruction) error { ...@@ -23,5 +24,5 @@ func (c *dgramOpt) SetBPF(filter []bpf.RawInstruction) error {
Len: uint16(len(filter)), Len: uint16(len(filter)),
Filter: (*sysSockFilter)(unsafe.Pointer(&filter[0])), 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))))
} }
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
package ipv6 package ipv6
func setControlMessage(fd int, opt *rawOpt, cf ControlFlags, on bool) error { func setControlMessage(s uintptr, opt *rawOpt, cf ControlFlags, on bool) error {
return errOpNoSupport return errOpNoSupport
} }
......
...@@ -13,11 +13,11 @@ import ( ...@@ -13,11 +13,11 @@ import (
"golang.org/x/net/internal/iana" "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() opt.Lock()
defer opt.Unlock() defer opt.Unlock()
if cf&FlagTrafficClass != 0 && sockOpts[ssoReceiveTrafficClass].name > 0 { if cf&FlagTrafficClass != 0 && sockOpts[ssoReceiveTrafficClass].name > 0 {
if err := setInt(fd, &sockOpts[ssoReceiveTrafficClass], boolint(on)); err != nil { if err := setInt(s, &sockOpts[ssoReceiveTrafficClass], boolint(on)); err != nil {
return err return err
} }
if on { if on {
...@@ -27,7 +27,7 @@ func setControlMessage(fd int, opt *rawOpt, cf ControlFlags, on bool) error { ...@@ -27,7 +27,7 @@ func setControlMessage(fd int, opt *rawOpt, cf ControlFlags, on bool) error {
} }
} }
if cf&FlagHopLimit != 0 && sockOpts[ssoReceiveHopLimit].name > 0 { if cf&FlagHopLimit != 0 && sockOpts[ssoReceiveHopLimit].name > 0 {
if err := setInt(fd, &sockOpts[ssoReceiveHopLimit], boolint(on)); err != nil { if err := setInt(s, &sockOpts[ssoReceiveHopLimit], boolint(on)); err != nil {
return err return err
} }
if on { if on {
...@@ -37,7 +37,7 @@ func setControlMessage(fd int, opt *rawOpt, cf ControlFlags, on bool) error { ...@@ -37,7 +37,7 @@ func setControlMessage(fd int, opt *rawOpt, cf ControlFlags, on bool) error {
} }
} }
if cf&flagPacketInfo != 0 && sockOpts[ssoReceivePacketInfo].name > 0 { if cf&flagPacketInfo != 0 && sockOpts[ssoReceivePacketInfo].name > 0 {
if err := setInt(fd, &sockOpts[ssoReceivePacketInfo], boolint(on)); err != nil { if err := setInt(s, &sockOpts[ssoReceivePacketInfo], boolint(on)); err != nil {
return err return err
} }
if on { if on {
...@@ -47,7 +47,7 @@ func setControlMessage(fd int, opt *rawOpt, cf ControlFlags, on bool) error { ...@@ -47,7 +47,7 @@ func setControlMessage(fd int, opt *rawOpt, cf ControlFlags, on bool) error {
} }
} }
if cf&FlagPathMTU != 0 && sockOpts[ssoReceivePathMTU].name > 0 { if cf&FlagPathMTU != 0 && sockOpts[ssoReceivePathMTU].name > 0 {
if err := setInt(fd, &sockOpts[ssoReceivePathMTU], boolint(on)); err != nil { if err := setInt(s, &sockOpts[ssoReceivePathMTU], boolint(on)); err != nil {
return err return err
} }
if on { if on {
......
...@@ -6,7 +6,7 @@ package ipv6 ...@@ -6,7 +6,7 @@ package ipv6
import "syscall" 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 // TODO(mikio): implement this
return syscall.EWINDOWS return syscall.EWINDOWS
} }
......
...@@ -9,6 +9,8 @@ package ipv6 ...@@ -9,6 +9,8 @@ package ipv6
import ( import (
"net" "net"
"syscall" "syscall"
"golang.org/x/net/internal/netreflect"
) )
// MulticastHopLimit returns the hop limit field value for outgoing // MulticastHopLimit returns the hop limit field value for outgoing
...@@ -17,11 +19,11 @@ func (c *dgramOpt) MulticastHopLimit() (int, error) { ...@@ -17,11 +19,11 @@ func (c *dgramOpt) MulticastHopLimit() (int, error) {
if !c.ok() { if !c.ok() {
return 0, syscall.EINVAL return 0, syscall.EINVAL
} }
fd, err := c.sysfd() s, err := netreflect.PacketSocketOf(c.PacketConn)
if err != nil { if err != nil {
return 0, err return 0, err
} }
return getInt(fd, &sockOpts[ssoMulticastHopLimit]) return getInt(s, &sockOpts[ssoMulticastHopLimit])
} }
// SetMulticastHopLimit sets the hop limit field value for future // SetMulticastHopLimit sets the hop limit field value for future
...@@ -30,11 +32,11 @@ func (c *dgramOpt) SetMulticastHopLimit(hoplim int) error { ...@@ -30,11 +32,11 @@ func (c *dgramOpt) SetMulticastHopLimit(hoplim int) error {
if !c.ok() { if !c.ok() {
return syscall.EINVAL return syscall.EINVAL
} }
fd, err := c.sysfd() s, err := netreflect.PacketSocketOf(c.PacketConn)
if err != nil { if err != nil {
return err return err
} }
return setInt(fd, &sockOpts[ssoMulticastHopLimit], hoplim) return setInt(s, &sockOpts[ssoMulticastHopLimit], hoplim)
} }
// MulticastInterface returns the default interface for multicast // MulticastInterface returns the default interface for multicast
...@@ -43,11 +45,11 @@ func (c *dgramOpt) MulticastInterface() (*net.Interface, error) { ...@@ -43,11 +45,11 @@ func (c *dgramOpt) MulticastInterface() (*net.Interface, error) {
if !c.ok() { if !c.ok() {
return nil, syscall.EINVAL return nil, syscall.EINVAL
} }
fd, err := c.sysfd() s, err := netreflect.PacketSocketOf(c.PacketConn)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return getInterface(fd, &sockOpts[ssoMulticastInterface]) return getInterface(s, &sockOpts[ssoMulticastInterface])
} }
// SetMulticastInterface sets the default interface for future // SetMulticastInterface sets the default interface for future
...@@ -56,11 +58,11 @@ func (c *dgramOpt) SetMulticastInterface(ifi *net.Interface) error { ...@@ -56,11 +58,11 @@ func (c *dgramOpt) SetMulticastInterface(ifi *net.Interface) error {
if !c.ok() { if !c.ok() {
return syscall.EINVAL return syscall.EINVAL
} }
fd, err := c.sysfd() s, err := netreflect.PacketSocketOf(c.PacketConn)
if err != nil { if err != nil {
return err return err
} }
return setInterface(fd, &sockOpts[ssoMulticastInterface], ifi) return setInterface(s, &sockOpts[ssoMulticastInterface], ifi)
} }
// MulticastLoopback reports whether transmitted multicast packets // MulticastLoopback reports whether transmitted multicast packets
...@@ -69,11 +71,11 @@ func (c *dgramOpt) MulticastLoopback() (bool, error) { ...@@ -69,11 +71,11 @@ func (c *dgramOpt) MulticastLoopback() (bool, error) {
if !c.ok() { if !c.ok() {
return false, syscall.EINVAL return false, syscall.EINVAL
} }
fd, err := c.sysfd() s, err := netreflect.PacketSocketOf(c.PacketConn)
if err != nil { if err != nil {
return false, err return false, err
} }
on, err := getInt(fd, &sockOpts[ssoMulticastLoopback]) on, err := getInt(s, &sockOpts[ssoMulticastLoopback])
if err != nil { if err != nil {
return false, err return false, err
} }
...@@ -86,11 +88,11 @@ func (c *dgramOpt) SetMulticastLoopback(on bool) error { ...@@ -86,11 +88,11 @@ func (c *dgramOpt) SetMulticastLoopback(on bool) error {
if !c.ok() { if !c.ok() {
return syscall.EINVAL return syscall.EINVAL
} }
fd, err := c.sysfd() s, err := netreflect.PacketSocketOf(c.PacketConn)
if err != nil { if err != nil {
return err 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. // 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 { ...@@ -106,7 +108,7 @@ func (c *dgramOpt) JoinGroup(ifi *net.Interface, group net.Addr) error {
if !c.ok() { if !c.ok() {
return syscall.EINVAL return syscall.EINVAL
} }
fd, err := c.sysfd() s, err := netreflect.PacketSocketOf(c.PacketConn)
if err != nil { if err != nil {
return err return err
} }
...@@ -114,7 +116,7 @@ func (c *dgramOpt) JoinGroup(ifi *net.Interface, group net.Addr) error { ...@@ -114,7 +116,7 @@ func (c *dgramOpt) JoinGroup(ifi *net.Interface, group net.Addr) error {
if grp == nil { if grp == nil {
return errMissingAddress 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 // 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 { ...@@ -124,7 +126,7 @@ func (c *dgramOpt) LeaveGroup(ifi *net.Interface, group net.Addr) error {
if !c.ok() { if !c.ok() {
return syscall.EINVAL return syscall.EINVAL
} }
fd, err := c.sysfd() s, err := netreflect.PacketSocketOf(c.PacketConn)
if err != nil { if err != nil {
return err return err
} }
...@@ -132,7 +134,7 @@ func (c *dgramOpt) LeaveGroup(ifi *net.Interface, group net.Addr) error { ...@@ -132,7 +134,7 @@ func (c *dgramOpt) LeaveGroup(ifi *net.Interface, group net.Addr) error {
if grp == nil { if grp == nil {
return errMissingAddress return errMissingAddress
} }
return setGroup(fd, &sockOpts[ssoLeaveGroup], ifi, grp) return setGroup(s, &sockOpts[ssoLeaveGroup], ifi, grp)
} }
// JoinSourceSpecificGroup joins the source-specific group comprising // JoinSourceSpecificGroup joins the source-specific group comprising
...@@ -145,7 +147,7 @@ func (c *dgramOpt) JoinSourceSpecificGroup(ifi *net.Interface, group, source net ...@@ -145,7 +147,7 @@ func (c *dgramOpt) JoinSourceSpecificGroup(ifi *net.Interface, group, source net
if !c.ok() { if !c.ok() {
return syscall.EINVAL return syscall.EINVAL
} }
fd, err := c.sysfd() s, err := netreflect.PacketSocketOf(c.PacketConn)
if err != nil { if err != nil {
return err return err
} }
...@@ -157,7 +159,7 @@ func (c *dgramOpt) JoinSourceSpecificGroup(ifi *net.Interface, group, source net ...@@ -157,7 +159,7 @@ func (c *dgramOpt) JoinSourceSpecificGroup(ifi *net.Interface, group, source net
if src == nil { if src == nil {
return errMissingAddress 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 // LeaveSourceSpecificGroup leaves the source-specific group on the
...@@ -166,7 +168,7 @@ func (c *dgramOpt) LeaveSourceSpecificGroup(ifi *net.Interface, group, source ne ...@@ -166,7 +168,7 @@ func (c *dgramOpt) LeaveSourceSpecificGroup(ifi *net.Interface, group, source ne
if !c.ok() { if !c.ok() {
return syscall.EINVAL return syscall.EINVAL
} }
fd, err := c.sysfd() s, err := netreflect.PacketSocketOf(c.PacketConn)
if err != nil { if err != nil {
return err return err
} }
...@@ -178,7 +180,7 @@ func (c *dgramOpt) LeaveSourceSpecificGroup(ifi *net.Interface, group, source ne ...@@ -178,7 +180,7 @@ func (c *dgramOpt) LeaveSourceSpecificGroup(ifi *net.Interface, group, source ne
if src == nil { if src == nil {
return errMissingAddress 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 // ExcludeSourceSpecificGroup excludes the source-specific group from
...@@ -188,7 +190,7 @@ func (c *dgramOpt) ExcludeSourceSpecificGroup(ifi *net.Interface, group, source ...@@ -188,7 +190,7 @@ func (c *dgramOpt) ExcludeSourceSpecificGroup(ifi *net.Interface, group, source
if !c.ok() { if !c.ok() {
return syscall.EINVAL return syscall.EINVAL
} }
fd, err := c.sysfd() s, err := netreflect.PacketSocketOf(c.PacketConn)
if err != nil { if err != nil {
return err return err
} }
...@@ -200,7 +202,7 @@ func (c *dgramOpt) ExcludeSourceSpecificGroup(ifi *net.Interface, group, source ...@@ -200,7 +202,7 @@ func (c *dgramOpt) ExcludeSourceSpecificGroup(ifi *net.Interface, group, source
if src == nil { if src == nil {
return errMissingAddress return errMissingAddress
} }
return setSourceGroup(fd, &sockOpts[ssoBlockSourceGroup], ifi, grp, src) return setSourceGroup(s, &sockOpts[ssoBlockSourceGroup], ifi, grp, src)
} }
// IncludeSourceSpecificGroup includes the excluded source-specific // IncludeSourceSpecificGroup includes the excluded source-specific
...@@ -209,7 +211,7 @@ func (c *dgramOpt) IncludeSourceSpecificGroup(ifi *net.Interface, group, source ...@@ -209,7 +211,7 @@ func (c *dgramOpt) IncludeSourceSpecificGroup(ifi *net.Interface, group, source
if !c.ok() { if !c.ok() {
return syscall.EINVAL return syscall.EINVAL
} }
fd, err := c.sysfd() s, err := netreflect.PacketSocketOf(c.PacketConn)
if err != nil { if err != nil {
return err return err
} }
...@@ -221,7 +223,7 @@ func (c *dgramOpt) IncludeSourceSpecificGroup(ifi *net.Interface, group, source ...@@ -221,7 +223,7 @@ func (c *dgramOpt) IncludeSourceSpecificGroup(ifi *net.Interface, group, source
if src == nil { if src == nil {
return errMissingAddress return errMissingAddress
} }
return setSourceGroup(fd, &sockOpts[ssoUnblockSourceGroup], ifi, grp, src) return setSourceGroup(s, &sockOpts[ssoUnblockSourceGroup], ifi, grp, src)
} }
// Checksum reports whether the kernel will compute, store or verify a // Checksum reports whether the kernel will compute, store or verify a
...@@ -232,11 +234,11 @@ func (c *dgramOpt) Checksum() (on bool, offset int, err error) { ...@@ -232,11 +234,11 @@ func (c *dgramOpt) Checksum() (on bool, offset int, err error) {
if !c.ok() { if !c.ok() {
return false, 0, syscall.EINVAL return false, 0, syscall.EINVAL
} }
fd, err := c.sysfd() s, err := netreflect.PacketSocketOf(c.PacketConn)
if err != nil { if err != nil {
return false, 0, err return false, 0, err
} }
offset, err = getInt(fd, &sockOpts[ssoChecksum]) offset, err = getInt(s, &sockOpts[ssoChecksum])
if err != nil { if err != nil {
return false, 0, err return false, 0, err
} }
...@@ -253,14 +255,14 @@ func (c *dgramOpt) SetChecksum(on bool, offset int) error { ...@@ -253,14 +255,14 @@ func (c *dgramOpt) SetChecksum(on bool, offset int) error {
if !c.ok() { if !c.ok() {
return syscall.EINVAL return syscall.EINVAL
} }
fd, err := c.sysfd() s, err := netreflect.PacketSocketOf(c.PacketConn)
if err != nil { if err != nil {
return err return err
} }
if !on { if !on {
offset = -1 offset = -1
} }
return setInt(fd, &sockOpts[ssoChecksum], offset) return setInt(s, &sockOpts[ssoChecksum], offset)
} }
// ICMPFilter returns an ICMP filter. // ICMPFilter returns an ICMP filter.
...@@ -268,11 +270,11 @@ func (c *dgramOpt) ICMPFilter() (*ICMPFilter, error) { ...@@ -268,11 +270,11 @@ func (c *dgramOpt) ICMPFilter() (*ICMPFilter, error) {
if !c.ok() { if !c.ok() {
return nil, syscall.EINVAL return nil, syscall.EINVAL
} }
fd, err := c.sysfd() s, err := netreflect.PacketSocketOf(c.PacketConn)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return getICMPFilter(fd, &sockOpts[ssoICMPFilter]) return getICMPFilter(s, &sockOpts[ssoICMPFilter])
} }
// SetICMPFilter deploys the ICMP filter. // SetICMPFilter deploys the ICMP filter.
...@@ -280,9 +282,9 @@ func (c *dgramOpt) SetICMPFilter(f *ICMPFilter) error { ...@@ -280,9 +282,9 @@ func (c *dgramOpt) SetICMPFilter(f *ICMPFilter) error {
if !c.ok() { if !c.ok() {
return syscall.EINVAL return syscall.EINVAL
} }
fd, err := c.sysfd() s, err := netreflect.PacketSocketOf(c.PacketConn)
if err != nil { if err != nil {
return err return err
} }
return setICMPFilter(fd, &sockOpts[ssoICMPFilter], f) return setICMPFilter(s, &sockOpts[ssoICMPFilter], f)
} }
...@@ -8,6 +8,8 @@ import ( ...@@ -8,6 +8,8 @@ import (
"net" "net"
"syscall" "syscall"
"time" "time"
"golang.org/x/net/internal/netreflect"
) )
// A Conn represents a network endpoint that uses IPv6 transport. // A Conn represents a network endpoint that uses IPv6 transport.
...@@ -29,11 +31,11 @@ func (c *Conn) PathMTU() (int, error) { ...@@ -29,11 +31,11 @@ func (c *Conn) PathMTU() (int, error) {
if !c.genericOpt.ok() { if !c.genericOpt.ok() {
return 0, syscall.EINVAL return 0, syscall.EINVAL
} }
fd, err := c.genericOpt.sysfd() s, err := netreflect.SocketOf(c.genericOpt.Conn)
if err != nil { if err != nil {
return 0, err return 0, err
} }
_, mtu, err := getMTUInfo(fd, &sockOpts[ssoPathMTU]) _, mtu, err := getMTUInfo(s, &sockOpts[ssoPathMTU])
if err != nil { if err != nil {
return 0, err return 0, err
} }
...@@ -70,11 +72,11 @@ func (c *PacketConn) SetControlMessage(cf ControlFlags, on bool) error { ...@@ -70,11 +72,11 @@ func (c *PacketConn) SetControlMessage(cf ControlFlags, on bool) error {
if !c.payloadHandler.ok() { if !c.payloadHandler.ok() {
return syscall.EINVAL return syscall.EINVAL
} }
fd, err := c.payloadHandler.sysfd() s, err := netreflect.PacketSocketOf(c.dgramOpt.PacketConn)
if err != nil { if err != nil {
return err 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 // SetDeadline sets the read and write deadlines associated with the
......
...@@ -6,7 +6,11 @@ ...@@ -6,7 +6,11 @@
package ipv6 package ipv6
import "syscall" import (
"syscall"
"golang.org/x/net/internal/netreflect"
)
// TrafficClass returns the traffic class field value for outgoing // TrafficClass returns the traffic class field value for outgoing
// packets. // packets.
...@@ -14,11 +18,11 @@ func (c *genericOpt) TrafficClass() (int, error) { ...@@ -14,11 +18,11 @@ func (c *genericOpt) TrafficClass() (int, error) {
if !c.ok() { if !c.ok() {
return 0, syscall.EINVAL return 0, syscall.EINVAL
} }
fd, err := c.sysfd() s, err := netreflect.SocketOf(c.Conn)
if err != nil { if err != nil {
return 0, err return 0, err
} }
return getInt(fd, &sockOpts[ssoTrafficClass]) return getInt(s, &sockOpts[ssoTrafficClass])
} }
// SetTrafficClass sets the traffic class field value for future // SetTrafficClass sets the traffic class field value for future
...@@ -27,11 +31,11 @@ func (c *genericOpt) SetTrafficClass(tclass int) error { ...@@ -27,11 +31,11 @@ func (c *genericOpt) SetTrafficClass(tclass int) error {
if !c.ok() { if !c.ok() {
return syscall.EINVAL return syscall.EINVAL
} }
fd, err := c.sysfd() s, err := netreflect.SocketOf(c.Conn)
if err != nil { if err != nil {
return err return err
} }
return setInt(fd, &sockOpts[ssoTrafficClass], tclass) return setInt(s, &sockOpts[ssoTrafficClass], tclass)
} }
// HopLimit returns the hop limit field value for outgoing packets. // HopLimit returns the hop limit field value for outgoing packets.
...@@ -39,11 +43,11 @@ func (c *genericOpt) HopLimit() (int, error) { ...@@ -39,11 +43,11 @@ func (c *genericOpt) HopLimit() (int, error) {
if !c.ok() { if !c.ok() {
return 0, syscall.EINVAL return 0, syscall.EINVAL
} }
fd, err := c.sysfd() s, err := netreflect.SocketOf(c.Conn)
if err != nil { if err != nil {
return 0, err return 0, err
} }
return getInt(fd, &sockOpts[ssoHopLimit]) return getInt(s, &sockOpts[ssoHopLimit])
} }
// SetHopLimit sets the hop limit field value for future outgoing // SetHopLimit sets the hop limit field value for future outgoing
...@@ -52,9 +56,9 @@ func (c *genericOpt) SetHopLimit(hoplim int) error { ...@@ -52,9 +56,9 @@ func (c *genericOpt) SetHopLimit(hoplim int) error {
if !c.ok() { if !c.ok() {
return syscall.EINVAL return syscall.EINVAL
} }
fd, err := c.sysfd() s, err := netreflect.SocketOf(c.Conn)
if err != nil { if err != nil {
return err return err
} }
return setInt(fd, &sockOpts[ssoHopLimit], hoplim) return setInt(s, &sockOpts[ssoHopLimit], hoplim)
} }
// Copyright 2013 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 ipv6
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
}
// Copyright 2013 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 ipv6
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 sysfd(c net.Conn) (int, error) {
cv := reflect.ValueOf(c)
switch ce := cv.Elem(); ce.Kind() {
case reflect.Struct:
nfd := ce.FieldByName("conn").FieldByName("fd")
switch fe := nfd.Elem(); fe.Kind() {
case reflect.Struct:
fd := fe.FieldByName("sysfd")
return int(fd.Int()), nil
}
}
return 0, errInvalidConnType
}
// Copyright 2013 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 ipv6
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 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
}
...@@ -12,11 +12,11 @@ import ( ...@@ -12,11 +12,11 @@ import (
"unsafe" "unsafe"
) )
func setsockoptIPMreq(fd int, opt *sockOpt, ifi *net.Interface, grp net.IP) error { func setsockoptIPMreq(s uintptr, opt *sockOpt, ifi *net.Interface, grp net.IP) error {
var mreq sysIPv6Mreq var mreq sysIPv6Mreq
copy(mreq.Multiaddr[:], grp) copy(mreq.Multiaddr[:], grp)
if ifi != nil { if ifi != nil {
mreq.setIfindex(ifi.Index) mreq.setIfindex(ifi.Index)
} }
return os.NewSyscallError("setsockopt", setsockopt(fd, opt.level, opt.name, unsafe.Pointer(&mreq), sysSizeofIPv6Mreq)) return os.NewSyscallError("setsockopt", setsockopt(s, opt.level, opt.name, unsafe.Pointer(&mreq), sysSizeofIPv6Mreq))
} }
...@@ -11,11 +11,11 @@ import ( ...@@ -11,11 +11,11 @@ import (
"unsafe" "unsafe"
) )
func setsockoptIPMreq(fd syscall.Handle, opt *sockOpt, ifi *net.Interface, grp net.IP) error { func setsockoptIPMreq(s uintptr, opt *sockOpt, ifi *net.Interface, grp net.IP) error {
var mreq sysIPv6Mreq var mreq sysIPv6Mreq
copy(mreq.Multiaddr[:], grp) copy(mreq.Multiaddr[:], grp)
if ifi != nil { if ifi != nil {
mreq.setIfindex(ifi.Index) mreq.setIfindex(ifi.Index)
} }
return os.NewSyscallError("setsockopt", syscall.Setsockopt(fd, int32(opt.level), int32(opt.name), (*byte)(unsafe.Pointer(&mreq)), sysSizeofIPv6Mreq)) return os.NewSyscallError("setsockopt", syscall.Setsockopt(syscall.Handle(s), int32(opt.level), int32(opt.name), (*byte)(unsafe.Pointer(&mreq)), sysSizeofIPv6Mreq))
} }
...@@ -8,10 +8,10 @@ package ipv6 ...@@ -8,10 +8,10 @@ package ipv6
import "net" import "net"
func setsockoptGroupReq(fd int, opt *sockOpt, ifi *net.Interface, grp net.IP) error { func setsockoptGroupReq(s uintptr, opt *sockOpt, ifi *net.Interface, grp net.IP) error {
return errOpNoSupport return errOpNoSupport
} }
func setsockoptGroupSourceReq(fd int, opt *sockOpt, ifi *net.Interface, grp, src net.IP) error { func setsockoptGroupSourceReq(s uintptr, opt *sockOpt, ifi *net.Interface, grp, src net.IP) error {
return errOpNoSupport return errOpNoSupport
} }
...@@ -14,7 +14,7 @@ import ( ...@@ -14,7 +14,7 @@ import (
var freebsd32o64 bool var freebsd32o64 bool
func setsockoptGroupReq(fd int, opt *sockOpt, ifi *net.Interface, grp net.IP) error { func setsockoptGroupReq(s uintptr, opt *sockOpt, ifi *net.Interface, grp net.IP) error {
var gr sysGroupReq var gr sysGroupReq
if ifi != nil { if ifi != nil {
gr.Interface = uint32(ifi.Index) gr.Interface = uint32(ifi.Index)
...@@ -33,10 +33,10 @@ func setsockoptGroupReq(fd int, opt *sockOpt, ifi *net.Interface, grp net.IP) er ...@@ -33,10 +33,10 @@ func setsockoptGroupReq(fd int, opt *sockOpt, ifi *net.Interface, grp net.IP) er
p = unsafe.Pointer(&gr) p = unsafe.Pointer(&gr)
l = sysSizeofGroupReq l = sysSizeofGroupReq
} }
return os.NewSyscallError("setsockopt", setsockopt(fd, opt.level, opt.name, p, l)) return os.NewSyscallError("setsockopt", setsockopt(s, opt.level, opt.name, p, l))
} }
func setsockoptGroupSourceReq(fd int, opt *sockOpt, ifi *net.Interface, grp, src net.IP) error { func setsockoptGroupSourceReq(s uintptr, opt *sockOpt, ifi *net.Interface, grp, src net.IP) error {
var gsr sysGroupSourceReq var gsr sysGroupSourceReq
if ifi != nil { if ifi != nil {
gsr.Interface = uint32(ifi.Index) gsr.Interface = uint32(ifi.Index)
...@@ -55,5 +55,5 @@ func setsockoptGroupSourceReq(fd int, opt *sockOpt, ifi *net.Interface, grp, src ...@@ -55,5 +55,5 @@ func setsockoptGroupSourceReq(fd int, opt *sockOpt, ifi *net.Interface, grp, src
p = unsafe.Pointer(&gsr) p = unsafe.Pointer(&gsr)
l = sysSizeofGroupSourceReq l = sysSizeofGroupSourceReq
} }
return os.NewSyscallError("setsockopt", setsockopt(fd, opt.level, opt.name, p, l)) return os.NewSyscallError("setsockopt", setsockopt(s, opt.level, opt.name, p, l))
} }
...@@ -8,6 +8,6 @@ package ipv6 ...@@ -8,6 +8,6 @@ package ipv6
import "net" import "net"
func getMTUInfo(fd int, opt *sockOpt) (*net.Interface, int, error) { func getMTUInfo(s uintptr, opt *sockOpt) (*net.Interface, int, error) {
return nil, 0, errOpNoSupport return nil, 0, errOpNoSupport
} }
...@@ -12,33 +12,33 @@ import ( ...@@ -12,33 +12,33 @@ import (
"unsafe" "unsafe"
) )
func getInt(fd int, opt *sockOpt) (int, error) { func getInt(s uintptr, opt *sockOpt) (int, error) {
if opt.name < 1 || opt.typ != ssoTypeInt { if opt.name < 1 || opt.typ != ssoTypeInt {
return 0, errOpNoSupport return 0, errOpNoSupport
} }
var i int32 var i int32
l := uint32(4) l := uint32(4)
if err := getsockopt(fd, opt.level, opt.name, unsafe.Pointer(&i), &l); err != nil { if err := getsockopt(s, opt.level, opt.name, unsafe.Pointer(&i), &l); err != nil {
return 0, os.NewSyscallError("getsockopt", err) return 0, os.NewSyscallError("getsockopt", err)
} }
return int(i), nil 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 != ssoTypeInt { if opt.name < 1 || opt.typ != ssoTypeInt {
return errOpNoSupport return errOpNoSupport
} }
i := int32(v) i := int32(v)
return os.NewSyscallError("setsockopt", setsockopt(fd, opt.level, opt.name, unsafe.Pointer(&i), 4)) return os.NewSyscallError("setsockopt", setsockopt(s, opt.level, opt.name, unsafe.Pointer(&i), 4))
} }
func getInterface(fd int, opt *sockOpt) (*net.Interface, error) { func getInterface(s uintptr, opt *sockOpt) (*net.Interface, error) {
if opt.name < 1 || opt.typ != ssoTypeInterface { if opt.name < 1 || opt.typ != ssoTypeInterface {
return nil, errOpNoSupport return nil, errOpNoSupport
} }
var i int32 var i int32
l := uint32(4) l := uint32(4)
if err := getsockopt(fd, opt.level, opt.name, unsafe.Pointer(&i), &l); err != nil { if err := getsockopt(s, opt.level, opt.name, unsafe.Pointer(&i), &l); err != nil {
return nil, os.NewSyscallError("getsockopt", err) return nil, os.NewSyscallError("getsockopt", err)
} }
if i == 0 { if i == 0 {
...@@ -51,7 +51,7 @@ func getInterface(fd int, opt *sockOpt) (*net.Interface, error) { ...@@ -51,7 +51,7 @@ func getInterface(fd int, opt *sockOpt) (*net.Interface, error) {
return ifi, nil return ifi, nil
} }
func setInterface(fd int, opt *sockOpt, ifi *net.Interface) error { func setInterface(s uintptr, opt *sockOpt, ifi *net.Interface) error {
if opt.name < 1 || opt.typ != ssoTypeInterface { if opt.name < 1 || opt.typ != ssoTypeInterface {
return errOpNoSupport return errOpNoSupport
} }
...@@ -59,35 +59,35 @@ func setInterface(fd int, opt *sockOpt, ifi *net.Interface) error { ...@@ -59,35 +59,35 @@ func setInterface(fd int, opt *sockOpt, ifi *net.Interface) error {
if ifi != nil { if ifi != nil {
i = int32(ifi.Index) i = int32(ifi.Index)
} }
return os.NewSyscallError("setsockopt", setsockopt(fd, opt.level, opt.name, unsafe.Pointer(&i), 4)) return os.NewSyscallError("setsockopt", setsockopt(s, opt.level, opt.name, unsafe.Pointer(&i), 4))
} }
func getICMPFilter(fd int, opt *sockOpt) (*ICMPFilter, error) { func getICMPFilter(s uintptr, opt *sockOpt) (*ICMPFilter, error) {
if opt.name < 1 || opt.typ != ssoTypeICMPFilter { if opt.name < 1 || opt.typ != ssoTypeICMPFilter {
return nil, errOpNoSupport return nil, errOpNoSupport
} }
var f ICMPFilter var f ICMPFilter
l := uint32(sysSizeofICMPv6Filter) l := uint32(sysSizeofICMPv6Filter)
if err := getsockopt(fd, opt.level, opt.name, unsafe.Pointer(&f.sysICMPv6Filter), &l); err != nil { if err := getsockopt(s, opt.level, opt.name, unsafe.Pointer(&f.sysICMPv6Filter), &l); err != nil {
return nil, os.NewSyscallError("getsockopt", err) return nil, os.NewSyscallError("getsockopt", err)
} }
return &f, nil 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 { if opt.name < 1 || opt.typ != ssoTypeICMPFilter {
return errOpNoSupport return errOpNoSupport
} }
return os.NewSyscallError("setsockopt", setsockopt(fd, opt.level, opt.name, unsafe.Pointer(&f.sysICMPv6Filter), sysSizeofICMPv6Filter)) return os.NewSyscallError("setsockopt", setsockopt(s, opt.level, opt.name, unsafe.Pointer(&f.sysICMPv6Filter), sysSizeofICMPv6Filter))
} }
func getMTUInfo(fd int, opt *sockOpt) (*net.Interface, int, error) { func getMTUInfo(s uintptr, opt *sockOpt) (*net.Interface, int, error) {
if opt.name < 1 || opt.typ != ssoTypeMTUInfo { if opt.name < 1 || opt.typ != ssoTypeMTUInfo {
return nil, 0, errOpNoSupport return nil, 0, errOpNoSupport
} }
var mi sysIPv6Mtuinfo var mi sysIPv6Mtuinfo
l := uint32(sysSizeofIPv6Mtuinfo) l := uint32(sysSizeofIPv6Mtuinfo)
if err := getsockopt(fd, opt.level, opt.name, unsafe.Pointer(&mi), &l); err != nil { if err := getsockopt(s, opt.level, opt.name, unsafe.Pointer(&mi), &l); err != nil {
return nil, 0, os.NewSyscallError("getsockopt", err) return nil, 0, os.NewSyscallError("getsockopt", err)
} }
if mi.Addr.Scope_id == 0 { if mi.Addr.Scope_id == 0 {
...@@ -100,23 +100,23 @@ func getMTUInfo(fd int, opt *sockOpt) (*net.Interface, int, error) { ...@@ -100,23 +100,23 @@ func getMTUInfo(fd int, opt *sockOpt) (*net.Interface, int, error) {
return ifi, int(mi.Mtu), nil return ifi, int(mi.Mtu), nil
} }
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 { if opt.name < 1 {
return errOpNoSupport return errOpNoSupport
} }
switch opt.typ { switch opt.typ {
case ssoTypeIPMreq: case ssoTypeIPMreq:
return setsockoptIPMreq(fd, opt, ifi, grp) return setsockoptIPMreq(s, opt, ifi, grp)
case ssoTypeGroupReq: case ssoTypeGroupReq:
return setsockoptGroupReq(fd, opt, ifi, grp) return setsockoptGroupReq(s, opt, ifi, grp)
default: default:
return errOpNoSupport 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 { if opt.name < 1 || opt.typ != ssoTypeGroupSourceReq {
return errOpNoSupport return errOpNoSupport
} }
return setsockoptGroupSourceReq(fd, opt, ifi, grp, src) return setsockoptGroupSourceReq(s, opt, ifi, grp, src)
} }
...@@ -11,33 +11,33 @@ import ( ...@@ -11,33 +11,33 @@ import (
"unsafe" "unsafe"
) )
func getInt(fd syscall.Handle, opt *sockOpt) (int, error) { func getInt(s uintptr, opt *sockOpt) (int, error) {
if opt.name < 1 || opt.typ != ssoTypeInt { if opt.name < 1 || opt.typ != ssoTypeInt {
return 0, errOpNoSupport return 0, errOpNoSupport
} }
var i int32 var i int32
l := int32(4) l := int32(4)
if err := syscall.Getsockopt(fd, int32(opt.level), int32(opt.name), (*byte)(unsafe.Pointer(&i)), &l); err != nil { if err := syscall.Getsockopt(syscall.Handle(s), int32(opt.level), int32(opt.name), (*byte)(unsafe.Pointer(&i)), &l); err != nil {
return 0, os.NewSyscallError("getsockopt", err) return 0, os.NewSyscallError("getsockopt", err)
} }
return int(i), nil 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 { if opt.name < 1 || opt.typ != ssoTypeInt {
return errOpNoSupport return errOpNoSupport
} }
i := int32(v) i := int32(v)
return os.NewSyscallError("setsockopt", syscall.Setsockopt(fd, int32(opt.level), int32(opt.name), (*byte)(unsafe.Pointer(&i)), 4)) return os.NewSyscallError("setsockopt", syscall.Setsockopt(syscall.Handle(s), int32(opt.level), 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 { if opt.name < 1 || opt.typ != ssoTypeInterface {
return nil, errOpNoSupport return nil, errOpNoSupport
} }
var i int32 var i int32
l := int32(4) l := int32(4)
if err := syscall.Getsockopt(fd, int32(opt.level), int32(opt.name), (*byte)(unsafe.Pointer(&i)), &l); err != nil { if err := syscall.Getsockopt(syscall.Handle(s), int32(opt.level), int32(opt.name), (*byte)(unsafe.Pointer(&i)), &l); err != nil {
return nil, os.NewSyscallError("getsockopt", err) return nil, os.NewSyscallError("getsockopt", err)
} }
if i == 0 { if i == 0 {
...@@ -50,7 +50,7 @@ func getInterface(fd syscall.Handle, opt *sockOpt) (*net.Interface, error) { ...@@ -50,7 +50,7 @@ func getInterface(fd syscall.Handle, opt *sockOpt) (*net.Interface, error) {
return ifi, nil return ifi, nil
} }
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 { if opt.name < 1 || opt.typ != ssoTypeInterface {
return errOpNoSupport return errOpNoSupport
} }
...@@ -58,29 +58,29 @@ func setInterface(fd syscall.Handle, opt *sockOpt, ifi *net.Interface) error { ...@@ -58,29 +58,29 @@ func setInterface(fd syscall.Handle, opt *sockOpt, ifi *net.Interface) error {
if ifi != nil { if ifi != nil {
i = int32(ifi.Index) i = int32(ifi.Index)
} }
return os.NewSyscallError("setsockopt", syscall.Setsockopt(fd, int32(opt.level), int32(opt.name), (*byte)(unsafe.Pointer(&i)), 4)) return os.NewSyscallError("setsockopt", syscall.Setsockopt(syscall.Handle(s), int32(opt.level), int32(opt.name), (*byte)(unsafe.Pointer(&i)), 4))
} }
func getICMPFilter(fd syscall.Handle, opt *sockOpt) (*ICMPFilter, error) { func getICMPFilter(s uintptr, opt *sockOpt) (*ICMPFilter, error) {
return nil, errOpNoSupport return nil, errOpNoSupport
} }
func setICMPFilter(fd syscall.Handle, opt *sockOpt, f *ICMPFilter) error { func setICMPFilter(s uintptr, opt *sockOpt, f *ICMPFilter) error {
return errOpNoSupport return errOpNoSupport
} }
func getMTUInfo(fd syscall.Handle, opt *sockOpt) (*net.Interface, int, error) { func getMTUInfo(s uintptr, opt *sockOpt) (*net.Interface, int, error) {
return nil, 0, errOpNoSupport return nil, 0, 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 { if opt.name < 1 || opt.typ != ssoTypeIPMreq {
return errOpNoSupport return errOpNoSupport
} }
return setsockoptIPMreq(fd, opt, ifi, grp) return setsockoptIPMreq(s, opt, 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 // TODO(mikio): implement this
return errOpNoSupport return errOpNoSupport
} }
...@@ -16,15 +16,15 @@ const ( ...@@ -16,15 +16,15 @@ const (
func socketcall(call int, a0, a1, a2, a3, a4, a5 uintptr) (int, syscall.Errno) 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 { func getsockopt(s uintptr, 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 { if _, errno := socketcall(sysGETSOCKOPT, s, uintptr(level), uintptr(name), uintptr(v), uintptr(unsafe.Pointer(l)), 0); errno != 0 {
return error(errno) return error(errno)
} }
return nil return nil
} }
func setsockopt(fd, level, name int, v unsafe.Pointer, l uint32) error { func setsockopt(s uintptr, 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 { if _, errno := socketcall(sysSETSOCKOPT, s, uintptr(level), uintptr(name), uintptr(v), uintptr(l), 0); errno != 0 {
return error(errno) return error(errno)
} }
return nil return nil
......
...@@ -11,15 +11,15 @@ import ( ...@@ -11,15 +11,15 @@ import (
"unsafe" "unsafe"
) )
func getsockopt(fd, level, name int, v unsafe.Pointer, l *uint32) error { func getsockopt(s uintptr, 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 { 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 error(errno)
} }
return nil return nil
} }
func setsockopt(fd, level, name int, v unsafe.Pointer, l uint32) error { func setsockopt(s uintptr, 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 { if _, _, errno := syscall.Syscall6(syscall.SYS_SETSOCKOPT, s, uintptr(level), uintptr(name), uintptr(v), uintptr(l), 0); errno != 0 {
return error(errno) return error(errno)
} }
return nil return nil
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment