sys_ssmreq.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. //go:build aix || darwin || freebsd || linux || solaris || zos
  5. // +build aix darwin freebsd linux solaris zos
  6. package ipv6
  7. import (
  8. "net"
  9. "unsafe"
  10. "golang.org/x/net/internal/socket"
  11. )
  12. var compatFreeBSD32 bool // 386 emulation on amd64
  13. func (so *sockOpt) setGroupReq(c *socket.Conn, 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 b []byte
  20. if compatFreeBSD32 {
  21. var d [sizeofGroupReq + 4]byte
  22. s := (*[sizeofGroupReq]byte)(unsafe.Pointer(&gr))
  23. copy(d[:4], s[:4])
  24. copy(d[8:], s[4:])
  25. b = d[:]
  26. } else {
  27. b = (*[sizeofGroupReq]byte)(unsafe.Pointer(&gr))[:sizeofGroupReq]
  28. }
  29. return so.Set(c, b)
  30. }
  31. func (so *sockOpt) setGroupSourceReq(c *socket.Conn, ifi *net.Interface, grp, src net.IP) error {
  32. var gsr groupSourceReq
  33. if ifi != nil {
  34. gsr.Interface = uint32(ifi.Index)
  35. }
  36. gsr.setSourceGroup(grp, src)
  37. var b []byte
  38. if compatFreeBSD32 {
  39. var d [sizeofGroupSourceReq + 4]byte
  40. s := (*[sizeofGroupSourceReq]byte)(unsafe.Pointer(&gsr))
  41. copy(d[:4], s[:4])
  42. copy(d[8:], s[4:])
  43. b = d[:]
  44. } else {
  45. b = (*[sizeofGroupSourceReq]byte)(unsafe.Pointer(&gsr))[:sizeofGroupSourceReq]
  46. }
  47. return so.Set(c, b)
  48. }