sys_linux.go 1.8 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. package ipv4
  5. import (
  6. "net"
  7. "syscall"
  8. "unsafe"
  9. )
  10. var (
  11. ctlOpts = [ctlMax]ctlOpt{
  12. ctlTTL: {sysIP_TTL, 1, 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, ssoTypeInt},
  19. ssoMulticastInterface: {sysIP_MULTICAST_IF, ssoTypeIPMreqn},
  20. ssoMulticastLoopback: {sysIP_MULTICAST_LOOP, ssoTypeInt},
  21. ssoReceiveTTL: {sysIP_RECVTTL, ssoTypeInt},
  22. ssoPacketInfo: {sysIP_PKTINFO, ssoTypeInt},
  23. ssoHeaderPrepend: {sysIP_HDRINCL, ssoTypeInt},
  24. ssoICMPFilter: {sysICMP_FILTER, ssoTypeICMPFilter},
  25. ssoJoinGroup: {sysMCAST_JOIN_GROUP, ssoTypeGroupReq},
  26. ssoLeaveGroup: {sysMCAST_LEAVE_GROUP, ssoTypeGroupReq},
  27. ssoJoinSourceGroup: {sysMCAST_JOIN_SOURCE_GROUP, ssoTypeGroupSourceReq},
  28. ssoLeaveSourceGroup: {sysMCAST_LEAVE_SOURCE_GROUP, ssoTypeGroupSourceReq},
  29. ssoBlockSourceGroup: {sysMCAST_BLOCK_SOURCE, ssoTypeGroupSourceReq},
  30. ssoUnblockSourceGroup: {sysMCAST_UNBLOCK_SOURCE, ssoTypeGroupSourceReq},
  31. }
  32. )
  33. func (pi *inetPktinfo) setIfindex(i int) {
  34. pi.Ifindex = int32(i)
  35. }
  36. func (gr *groupReq) setGroup(grp net.IP) {
  37. sa := (*sockaddrInet)(unsafe.Pointer(&gr.Group))
  38. sa.Family = syscall.AF_INET
  39. copy(sa.Addr[:], grp)
  40. }
  41. func (gsr *groupSourceReq) setSourceGroup(grp, src net.IP) {
  42. sa := (*sockaddrInet)(unsafe.Pointer(&gsr.Group))
  43. sa.Family = syscall.AF_INET
  44. copy(sa.Addr[:], grp)
  45. sa = (*sockaddrInet)(unsafe.Pointer(&gsr.Source))
  46. sa.Family = syscall.AF_INET
  47. copy(sa.Addr[:], src)
  48. }