sys_ssmreq.go 1.3 KB

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