blob: 3f06d76063397bdbfa658d5a49452019aade5155 [file] [log] [blame]
David K. Bainbridge215e0242017-09-05 23:18:24 -07001// 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 !nacl,!plan9,!windows
6
7package ipv4
8
9import (
10 "net"
11 "syscall"
12)
13
14// ReadFrom reads a payload of the received IPv4 datagram, from the
15// endpoint c, copying the payload into b. It returns the number of
16// bytes copied into b, the control message cm and the source address
17// src of the received datagram.
18func (c *payloadHandler) ReadFrom(b []byte) (n int, cm *ControlMessage, src net.Addr, err error) {
19 if !c.ok() {
20 return 0, nil, nil, syscall.EINVAL
21 }
22 return c.readFrom(b)
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.
31func (c *payloadHandler) WriteTo(b []byte, cm *ControlMessage, dst net.Addr) (n int, err error) {
32 if !c.ok() {
33 return 0, syscall.EINVAL
34 }
35 return c.writeTo(b, cm, dst)
36}