You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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