No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 

41 líneas
1.0 KiB

  1. // Copyright 2012 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 dragonfly freebsd netbsd openbsd
  5. package ipv4
  6. import (
  7. "net"
  8. "syscall"
  9. "unsafe"
  10. "golang.org/x/net/internal/iana"
  11. )
  12. func marshalDst(b []byte, cm *ControlMessage) []byte {
  13. m := (*syscall.Cmsghdr)(unsafe.Pointer(&b[0]))
  14. m.Level = iana.ProtocolIP
  15. m.Type = sysIP_RECVDSTADDR
  16. m.SetLen(syscall.CmsgLen(net.IPv4len))
  17. return b[syscall.CmsgSpace(net.IPv4len):]
  18. }
  19. func parseDst(cm *ControlMessage, b []byte) {
  20. cm.Dst = b[:net.IPv4len]
  21. }
  22. func marshalInterface(b []byte, cm *ControlMessage) []byte {
  23. m := (*syscall.Cmsghdr)(unsafe.Pointer(&b[0]))
  24. m.Level = iana.ProtocolIP
  25. m.Type = sysIP_RECVIF
  26. m.SetLen(syscall.CmsgLen(syscall.SizeofSockaddrDatalink))
  27. return b[syscall.CmsgSpace(syscall.SizeofSockaddrDatalink):]
  28. }
  29. func parseInterface(cm *ControlMessage, b []byte) {
  30. sadl := (*syscall.SockaddrDatalink)(unsafe.Pointer(&b[0]))
  31. cm.IfIndex = int(sadl.Index)
  32. }