payload_cmsg.go 1.2 KB

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