payload_nocmsg.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. //go:build !aix && !darwin && !dragonfly && !freebsd && !linux && !netbsd && !openbsd && !solaris && !zos
  5. // +build !aix,!darwin,!dragonfly,!freebsd,!linux,!netbsd,!openbsd,!solaris,!zos
  6. package ipv4
  7. import "net"
  8. // ReadFrom reads a payload of the received IPv4 datagram, from the
  9. // endpoint c, copying the payload into b. It returns the number of
  10. // bytes copied into b, the control message cm and the source address
  11. // src of the received datagram.
  12. func (c *payloadHandler) ReadFrom(b []byte) (n int, cm *ControlMessage, src net.Addr, err error) {
  13. if !c.ok() {
  14. return 0, nil, nil, errInvalidConn
  15. }
  16. if n, src, err = c.PacketConn.ReadFrom(b); err != nil {
  17. return 0, nil, nil, err
  18. }
  19. return
  20. }
  21. // WriteTo writes a payload of the IPv4 datagram, to the destination
  22. // address dst through the endpoint c, copying the payload from b. It
  23. // returns the number of bytes written. The control message cm allows
  24. // the datagram path and the outgoing interface to be specified.
  25. // Currently only Darwin and Linux support this. The cm may be nil if
  26. // control of the outgoing datagram is not required.
  27. func (c *payloadHandler) WriteTo(b []byte, cm *ControlMessage, dst net.Addr) (n int, err error) {
  28. if !c.ok() {
  29. return 0, errInvalidConn
  30. }
  31. if dst == nil {
  32. return 0, errMissingAddress
  33. }
  34. return c.PacketConn.WriteTo(b, dst)
  35. }