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