payload_nocmsg.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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 !aix,!darwin,!dragonfly,!freebsd,!linux,!netbsd,!openbsd,!solaris
  5. package ipv6
  6. import "net"
  7. // ReadFrom reads a payload of the received IPv6 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. if n, src, err = c.PacketConn.ReadFrom(b); err != nil {
  16. return 0, nil, nil, err
  17. }
  18. return
  19. }
  20. // WriteTo writes a payload of the IPv6 datagram, to the destination
  21. // address dst through the endpoint c, copying the payload from b. It
  22. // returns the number of bytes written. The control message cm allows
  23. // the IPv6 header fields and the datagram path to be specified. The
  24. // cm may be nil if control of the outgoing datagram is not required.
  25. func (c *payloadHandler) WriteTo(b []byte, cm *ControlMessage, dst net.Addr) (n int, err error) {
  26. if !c.ok() {
  27. return 0, errInvalidConn
  28. }
  29. if dst == nil {
  30. return 0, errMissingAddress
  31. }
  32. return c.PacketConn.WriteTo(b, dst)
  33. }