author | Mikio Hara
<mikioh.mikioh@gmail.com> 2016-08-24 21:25:47 UTC |
committer | Mikio Hara
<mikioh.mikioh@gmail.com> 2016-08-26 23:57:27 UTC |
parent | 7722dc0af88e49fdc0561de07fab960467f4727b |
ipv4/{sockopt_asmreq_unix.go => sockopt_asmreq_posix.go} | +1 | -1 |
ipv4/sockopt_asmreq_windows.go | +0 | -45 |
ipv4/{sockopt_unix.go => sockopt_posix.go} | +1 | -1 |
ipv4/sockopt_windows.go | +0 | -68 |
ipv4/syscall_windows.go | +18 | -0 |
diff --git a/ipv4/sockopt_asmreq_unix.go b/ipv4/sockopt_asmreq_posix.go similarity index 95% rename from ipv4/sockopt_asmreq_unix.go rename to ipv4/sockopt_asmreq_posix.go index 757097e..ef9b139 100644 --- a/ipv4/sockopt_asmreq_unix.go +++ b/ipv4/sockopt_asmreq_posix.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// +build darwin dragonfly freebsd netbsd openbsd +// +build darwin dragonfly freebsd netbsd openbsd windows package ipv4 diff --git a/ipv4/sockopt_asmreq_windows.go b/ipv4/sockopt_asmreq_windows.go deleted file mode 100644 index 9eda6fa..0000000 --- a/ipv4/sockopt_asmreq_windows.go +++ /dev/null @@ -1,45 +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" - "os" - "syscall" - "unsafe" - - "golang.org/x/net/internal/iana" -) - -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(syscall.Handle(s), iana.ProtocolIP, int32(name), (*byte)(unsafe.Pointer(&mreq)), int32(sysSizeofIPMreq))) -} - -func getsockoptInterface(s uintptr, name int) (*net.Interface, error) { - var b [4]byte - l := int32(4) - 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])) - if err != nil { - return nil, err - } - return ifi, nil -} - -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(syscall.Handle(s), iana.ProtocolIP, int32(name), (*byte)(unsafe.Pointer(&b[0])), 4)) -} diff --git a/ipv4/sockopt_unix.go b/ipv4/sockopt_posix.go similarity index 97% rename from ipv4/sockopt_unix.go rename to ipv4/sockopt_posix.go index fbb28df..0b7d6b6 100644 --- a/ipv4/sockopt_unix.go +++ b/ipv4/sockopt_posix.go @@ -2,7 +2,7 @@ // 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 +// +build darwin dragonfly freebsd linux netbsd openbsd windows package ipv4 diff --git a/ipv4/sockopt_windows.go b/ipv4/sockopt_windows.go deleted file mode 100644 index 3d4d9ad..0000000 --- a/ipv4/sockopt_windows.go +++ /dev/null @@ -1,68 +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" - "os" - "syscall" - "unsafe" - - "golang.org/x/net/internal/iana" -) - -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(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(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(syscall.Handle(s), iana.ProtocolIP, int32(opt.name), (*byte)(unsafe.Pointer(&i)), 4)) -} - -func getInterface(s uintptr, opt *sockOpt) (*net.Interface, error) { - if opt.name < 1 || opt.typ != ssoTypeInterface { - return nil, errOpNoSupport - } - return getsockoptInterface(s, opt.name) -} - -func setInterface(s uintptr, opt *sockOpt, ifi *net.Interface) error { - if opt.name < 1 || opt.typ != ssoTypeInterface { - return errOpNoSupport - } - return setsockoptInterface(s, opt.name, ifi) -} - -func getICMPFilter(s uintptr, opt *sockOpt) (*ICMPFilter, error) { - return nil, errOpNoSupport -} - -func setICMPFilter(s uintptr, opt *sockOpt, f *ICMPFilter) error { - return errOpNoSupport -} - -func setGroup(s uintptr, opt *sockOpt, ifi *net.Interface, grp net.IP) error { - if opt.name < 1 || opt.typ != ssoTypeIPMreq { - return errOpNoSupport - } - return setsockoptIPMreq(s, opt.name, ifi, grp) -} - -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_windows.go b/ipv4/syscall_windows.go new file mode 100644 index 0000000..0f42d22 --- /dev/null +++ b/ipv4/syscall_windows.go @@ -0,0 +1,18 @@ +// Copyright 2016 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 ( + "syscall" + "unsafe" +) + +func getsockopt(s uintptr, level, name int, v unsafe.Pointer, l *uint32) error { + return syscall.Getsockopt(syscall.Handle(s), int32(level), int32(name), (*byte)(v), (*int32)(unsafe.Pointer(l))) +} + +func setsockopt(s uintptr, level, name int, v unsafe.Pointer, l uint32) error { + return syscall.Setsockopt(syscall.Handle(s), int32(level), int32(name), (*byte)(v), int32(l)) +}