sys_ssmreq.go 1.2 KB

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