sockopt_ssmreq_unix.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Copyright 2014 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. // +build darwin freebsd linux
  5. package ipv6
  6. import (
  7. "net"
  8. "os"
  9. "unsafe"
  10. )
  11. var freebsd32o64 bool
  12. func setsockoptGroupReq(fd int, opt *sockOpt, ifi *net.Interface, grp net.IP) error {
  13. var gr sysGroupReq
  14. if ifi != nil {
  15. gr.Interface = uint32(ifi.Index)
  16. }
  17. gr.setGroup(grp)
  18. var p unsafe.Pointer
  19. var l uint32
  20. if freebsd32o64 {
  21. var d [sysSizeofGroupReq + 4]byte
  22. s := (*[sysSizeofGroupReq]byte)(unsafe.Pointer(&gr))
  23. copy(d[:4], s[:4])
  24. copy(d[8:], s[4:])
  25. p = unsafe.Pointer(&d[0])
  26. l = sysSizeofGroupReq + 4
  27. } else {
  28. p = unsafe.Pointer(&gr)
  29. l = sysSizeofGroupReq
  30. }
  31. return os.NewSyscallError("setsockopt", setsockopt(fd, opt.level, opt.name, p, l))
  32. }
  33. func setsockoptGroupSourceReq(fd int, opt *sockOpt, ifi *net.Interface, grp, src net.IP) error {
  34. var gsr sysGroupSourceReq
  35. if ifi != nil {
  36. gsr.Interface = uint32(ifi.Index)
  37. }
  38. gsr.setSourceGroup(grp, src)
  39. var p unsafe.Pointer
  40. var l uint32
  41. if freebsd32o64 {
  42. var d [sysSizeofGroupSourceReq + 4]byte
  43. s := (*[sysSizeofGroupSourceReq]byte)(unsafe.Pointer(&gsr))
  44. copy(d[:4], s[:4])
  45. copy(d[8:], s[4:])
  46. p = unsafe.Pointer(&d[0])
  47. l = sysSizeofGroupSourceReq + 4
  48. } else {
  49. p = unsafe.Pointer(&gsr)
  50. l = sysSizeofGroupSourceReq
  51. }
  52. return os.NewSyscallError("setsockopt", setsockopt(fd, opt.level, opt.name, p, l))
  53. }