sockopt_ssmreq_unix.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 solaris
  5. package ipv4
  6. import (
  7. "net"
  8. "os"
  9. "unsafe"
  10. "golang.org/x/net/internal/iana"
  11. )
  12. var freebsd32o64 bool
  13. func setsockoptGroupReq(s uintptr, name int, ifi *net.Interface, grp net.IP) error {
  14. var gr groupReq
  15. if ifi != nil {
  16. gr.Interface = uint32(ifi.Index)
  17. }
  18. gr.setGroup(grp)
  19. var p unsafe.Pointer
  20. var l uint32
  21. if freebsd32o64 {
  22. var d [sizeofGroupReq + 4]byte
  23. s := (*[sizeofGroupReq]byte)(unsafe.Pointer(&gr))
  24. copy(d[:4], s[:4])
  25. copy(d[8:], s[4:])
  26. p = unsafe.Pointer(&d[0])
  27. l = sizeofGroupReq + 4
  28. } else {
  29. p = unsafe.Pointer(&gr)
  30. l = sizeofGroupReq
  31. }
  32. return os.NewSyscallError("setsockopt", setsockopt(s, iana.ProtocolIP, name, p, l))
  33. }
  34. func setsockoptGroupSourceReq(s uintptr, name int, ifi *net.Interface, grp, src net.IP) error {
  35. var gsr groupSourceReq
  36. if ifi != nil {
  37. gsr.Interface = uint32(ifi.Index)
  38. }
  39. gsr.setSourceGroup(grp, src)
  40. var p unsafe.Pointer
  41. var l uint32
  42. if freebsd32o64 {
  43. var d [sizeofGroupSourceReq + 4]byte
  44. s := (*[sizeofGroupSourceReq]byte)(unsafe.Pointer(&gsr))
  45. copy(d[:4], s[:4])
  46. copy(d[8:], s[4:])
  47. p = unsafe.Pointer(&d[0])
  48. l = sizeofGroupSourceReq + 4
  49. } else {
  50. p = unsafe.Pointer(&gsr)
  51. l = sizeofGroupSourceReq
  52. }
  53. return os.NewSyscallError("setsockopt", setsockopt(s, iana.ProtocolIP, name, p, l))
  54. }