sys_solaris.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright 2016 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. package ipv4
  5. import (
  6. "net"
  7. "syscall"
  8. "unsafe"
  9. )
  10. var (
  11. ctlOpts = [ctlMax]ctlOpt{
  12. ctlTTL: {sysIP_RECVTTL, 4, marshalTTL, parseTTL},
  13. ctlPacketInfo: {sysIP_PKTINFO, sizeofInetPktinfo, marshalPacketInfo, parsePacketInfo},
  14. }
  15. sockOpts = [ssoMax]sockOpt{
  16. ssoTOS: {sysIP_TOS, ssoTypeInt},
  17. ssoTTL: {sysIP_TTL, ssoTypeInt},
  18. ssoMulticastTTL: {sysIP_MULTICAST_TTL, ssoTypeByte},
  19. ssoMulticastInterface: {sysIP_MULTICAST_IF, ssoTypeInterface},
  20. ssoMulticastLoopback: {sysIP_MULTICAST_LOOP, ssoTypeByte},
  21. ssoReceiveTTL: {sysIP_RECVTTL, ssoTypeInt},
  22. ssoPacketInfo: {sysIP_RECVPKTINFO, ssoTypeInt},
  23. ssoHeaderPrepend: {sysIP_HDRINCL, ssoTypeInt},
  24. ssoJoinGroup: {sysMCAST_JOIN_GROUP, ssoTypeGroupReq},
  25. ssoLeaveGroup: {sysMCAST_LEAVE_GROUP, ssoTypeGroupReq},
  26. ssoJoinSourceGroup: {sysMCAST_JOIN_SOURCE_GROUP, ssoTypeGroupSourceReq},
  27. ssoLeaveSourceGroup: {sysMCAST_LEAVE_SOURCE_GROUP, ssoTypeGroupSourceReq},
  28. ssoBlockSourceGroup: {sysMCAST_BLOCK_SOURCE, ssoTypeGroupSourceReq},
  29. ssoUnblockSourceGroup: {sysMCAST_UNBLOCK_SOURCE, ssoTypeGroupSourceReq},
  30. }
  31. )
  32. func (pi *inetPktinfo) setIfindex(i int) {
  33. pi.Ifindex = uint32(i)
  34. }
  35. func (gr *groupReq) setGroup(grp net.IP) {
  36. sa := (*sockaddrInet)(unsafe.Pointer(uintptr(unsafe.Pointer(gr)) + 4))
  37. sa.Family = syscall.AF_INET
  38. copy(sa.Addr[:], grp)
  39. }
  40. func (gsr *groupSourceReq) setSourceGroup(grp, src net.IP) {
  41. sa := (*sockaddrInet)(unsafe.Pointer(uintptr(unsafe.Pointer(gsr)) + 4))
  42. sa.Family = syscall.AF_INET
  43. copy(sa.Addr[:], grp)
  44. sa = (*sockaddrInet)(unsafe.Pointer(uintptr(unsafe.Pointer(gsr)) + 260))
  45. sa.Family = syscall.AF_INET
  46. copy(sa.Addr[:], src)
  47. }