2017-06-04 14:47:24 +02:00
|
|
|
// Copyright 2012 The Go Authors. All rights reserved.
|
2017-06-04 14:07:03 +02:00
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2017-06-04 14:47:24 +02:00
|
|
|
// +build !nacl,!plan9,!windows
|
2017-06-04 14:07:03 +02:00
|
|
|
|
|
|
|
package ipv4
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net"
|
|
|
|
"syscall"
|
|
|
|
)
|
|
|
|
|
|
|
|
// ReadFrom reads a payload of the received IPv4 datagram, from the
|
2017-06-04 14:47:24 +02:00
|
|
|
// endpoint c, copying the payload into b. It returns the number of
|
2017-06-04 14:07:03 +02:00
|
|
|
// bytes copied into b, the control message cm and the source address
|
|
|
|
// src of the received datagram.
|
|
|
|
func (c *payloadHandler) ReadFrom(b []byte) (n int, cm *ControlMessage, src net.Addr, err error) {
|
|
|
|
if !c.ok() {
|
|
|
|
return 0, nil, nil, syscall.EINVAL
|
|
|
|
}
|
2017-06-04 14:47:24 +02:00
|
|
|
return c.readFrom(b)
|
2017-06-04 14:07:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// WriteTo writes a payload of the IPv4 datagram, to the destination
|
2017-06-04 14:47:24 +02:00
|
|
|
// address dst through the endpoint c, copying the payload from b. It
|
|
|
|
// returns the number of bytes written. The control message cm allows
|
2017-06-04 14:07:03 +02:00
|
|
|
// the datagram path and the outgoing interface to be specified.
|
2017-06-04 14:47:24 +02:00
|
|
|
// Currently only Darwin and Linux support this. The cm may be nil if
|
2017-06-04 14:07:03 +02:00
|
|
|
// control of the outgoing datagram is not required.
|
|
|
|
func (c *payloadHandler) WriteTo(b []byte, cm *ControlMessage, dst net.Addr) (n int, err error) {
|
|
|
|
if !c.ok() {
|
|
|
|
return 0, syscall.EINVAL
|
|
|
|
}
|
2017-06-04 14:47:24 +02:00
|
|
|
return c.writeTo(b, cm, dst)
|
2017-06-04 14:07:03 +02:00
|
|
|
}
|