github.com/Andyfoo/golang/x/net@v0.0.0-20190901054642-57c1bf301704/ipv6/payload_nocmsg.go (about) 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 5 // +build !aix,!darwin,!dragonfly,!freebsd,!linux,!netbsd,!openbsd,!solaris 6 7 package ipv6 8 9 import "net" 10 11 // ReadFrom reads a payload of the received IPv6 datagram, from the 12 // endpoint c, copying the payload into b. It returns the number of 13 // bytes copied into b, the control message cm and the source address 14 // src of the received datagram. 15 func (c *payloadHandler) ReadFrom(b []byte) (n int, cm *ControlMessage, src net.Addr, err error) { 16 if !c.ok() { 17 return 0, nil, nil, errInvalidConn 18 } 19 if n, src, err = c.PacketConn.ReadFrom(b); err != nil { 20 return 0, nil, nil, err 21 } 22 return 23 } 24 25 // WriteTo writes a payload of the IPv6 datagram, to the destination 26 // address dst through the endpoint c, copying the payload from b. It 27 // returns the number of bytes written. The control message cm allows 28 // the IPv6 header fields and the datagram path to be specified. The 29 // cm may be nil if control of the outgoing datagram is not required. 30 func (c *payloadHandler) WriteTo(b []byte, cm *ControlMessage, dst net.Addr) (n int, err error) { 31 if !c.ok() { 32 return 0, errInvalidConn 33 } 34 if dst == nil { 35 return 0, errMissingAddress 36 } 37 return c.PacketConn.WriteTo(b, dst) 38 }