control_rfc2292_unix.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Copyright 2013 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
  5. package ipv6
  6. import (
  7. "unsafe"
  8. "golang.org/x/net/internal/iana"
  9. "golang.org/x/net/internal/socket"
  10. )
  11. func marshal2292HopLimit(b []byte, cm *ControlMessage) []byte {
  12. m := socket.ControlMessage(b)
  13. m.MarshalHeader(iana.ProtocolIPv6, sysIPV6_2292HOPLIMIT, 4)
  14. if cm != nil {
  15. socket.NativeEndian.PutUint32(m.Data(4), uint32(cm.HopLimit))
  16. }
  17. return m.Next(4)
  18. }
  19. func marshal2292PacketInfo(b []byte, cm *ControlMessage) []byte {
  20. m := socket.ControlMessage(b)
  21. m.MarshalHeader(iana.ProtocolIPv6, sysIPV6_2292PKTINFO, sizeofInet6Pktinfo)
  22. if cm != nil {
  23. pi := (*inet6Pktinfo)(unsafe.Pointer(&m.Data(sizeofInet6Pktinfo)[0]))
  24. if ip := cm.Src.To16(); ip != nil && ip.To4() == nil {
  25. copy(pi.Addr[:], ip)
  26. }
  27. if cm.IfIndex > 0 {
  28. pi.setIfindex(cm.IfIndex)
  29. }
  30. }
  31. return m.Next(sizeofInet6Pktinfo)
  32. }
  33. func marshal2292NextHop(b []byte, cm *ControlMessage) []byte {
  34. m := socket.ControlMessage(b)
  35. m.MarshalHeader(iana.ProtocolIPv6, sysIPV6_2292NEXTHOP, sizeofSockaddrInet6)
  36. if cm != nil {
  37. sa := (*sockaddrInet6)(unsafe.Pointer(&m.Data(sizeofSockaddrInet6)[0]))
  38. sa.setSockaddr(cm.NextHop, cm.IfIndex)
  39. }
  40. return m.Next(sizeofSockaddrInet6)
  41. }