d57f05c1077ec821b65a05cbf9a644c53ca9f316
[platform/core/system/edge-orchestration.git] / vendor / golang.org / x / net / ipv4 / payload_nocmsg.go
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 // +build !darwin,!dragonfly,!freebsd,!linux,!netbsd,!openbsd,!solaris
6
7 package ipv4
8
9 import "net"
10
11 // ReadFrom reads a payload of the received IPv4 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 IPv4 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 datagram path and the outgoing interface to be specified.
29 // Currently only Darwin and Linux support this. The cm may be nil if
30 // control of the outgoing datagram is not required.
31 func (c *payloadHandler) WriteTo(b []byte, cm *ControlMessage, dst net.Addr) (n int, err error) {
32         if !c.ok() {
33                 return 0, errInvalidConn
34         }
35         if dst == nil {
36                 return 0, errMissingAddress
37         }
38         return c.PacketConn.WriteTo(b, dst)
39 }