sockopt_windows.go 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // Copyright 2013 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package ipv6
  5. import (
  6. "net"
  7. "os"
  8. "syscall"
  9. "unsafe"
  10. )
  11. func getInt(fd syscall.Handle, opt *sockOpt) (int, error) {
  12. if opt.name < 1 || opt.typ != ssoTypeInt {
  13. return 0, errOpNoSupport
  14. }
  15. var i int32
  16. l := int32(4)
  17. if err := syscall.Getsockopt(fd, int32(opt.level), int32(opt.name), (*byte)(unsafe.Pointer(&i)), &l); err != nil {
  18. return 0, os.NewSyscallError("getsockopt", err)
  19. }
  20. return int(i), nil
  21. }
  22. func setInt(fd syscall.Handle, opt *sockOpt, v int) error {
  23. if opt.name < 1 || opt.typ != ssoTypeInt {
  24. return errOpNoSupport
  25. }
  26. i := int32(v)
  27. return os.NewSyscallError("setsockopt", syscall.Setsockopt(fd, int32(opt.level), int32(opt.name), (*byte)(unsafe.Pointer(&i)), 4))
  28. }
  29. func getInterface(fd syscall.Handle, opt *sockOpt) (*net.Interface, error) {
  30. if opt.name < 1 || opt.typ != ssoTypeInterface {
  31. return nil, errOpNoSupport
  32. }
  33. var i int32
  34. l := int32(4)
  35. if err := syscall.Getsockopt(fd, int32(opt.level), int32(opt.name), (*byte)(unsafe.Pointer(&i)), &l); err != nil {
  36. return nil, os.NewSyscallError("getsockopt", err)
  37. }
  38. if i == 0 {
  39. return nil, nil
  40. }
  41. ifi, err := net.InterfaceByIndex(int(i))
  42. if err != nil {
  43. return nil, err
  44. }
  45. return ifi, nil
  46. }
  47. func setInterface(fd syscall.Handle, opt *sockOpt, ifi *net.Interface) error {
  48. if opt.name < 1 || opt.typ != ssoTypeInterface {
  49. return errOpNoSupport
  50. }
  51. var i int32
  52. if ifi != nil {
  53. i = int32(ifi.Index)
  54. }
  55. return os.NewSyscallError("setsockopt", syscall.Setsockopt(fd, int32(opt.level), int32(opt.name), (*byte)(unsafe.Pointer(&i)), 4))
  56. }
  57. func getICMPFilter(fd syscall.Handle, opt *sockOpt) (*ICMPFilter, error) {
  58. return nil, errOpNoSupport
  59. }
  60. func setICMPFilter(fd syscall.Handle, opt *sockOpt, f *ICMPFilter) error {
  61. return errOpNoSupport
  62. }
  63. func getMTUInfo(fd syscall.Handle, opt *sockOpt) (*net.Interface, int, error) {
  64. return nil, 0, errOpNoSupport
  65. }
  66. func setGroup(fd syscall.Handle, opt *sockOpt, ifi *net.Interface, grp net.IP) error {
  67. if opt.name < 1 || opt.typ != ssoTypeIPMreq {
  68. return errOpNoSupport
  69. }
  70. return setsockoptIPMreq(fd, opt, ifi, grp)
  71. }
  72. func setSourceGroup(fd syscall.Handle, opt *sockOpt, ifi *net.Interface, grp, src net.IP) error {
  73. // TODO(mikio): implement this
  74. return errOpNoSupport
  75. }