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.
5
// +build !nacl,!plan9,!windows
14
// ReadFrom reads a payload of the received IPv6 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.
18
func (c *payloadHandler) ReadFrom(b []byte) (n int, cm *ControlMessage, src net.Addr, err error) {
20
return 0, nil, nil, syscall.EINVAL
22
oob := newControlMessage(&c.rawOpt)
24
switch c := c.PacketConn.(type) {
26
if n, oobn, _, src, err = c.ReadMsgUDP(b, oob); err != nil {
27
return 0, nil, nil, err
30
if n, oobn, _, src, err = c.ReadMsgIP(b, oob); err != nil {
31
return 0, nil, nil, err
34
return 0, nil, nil, errInvalidConnType
36
if cm, err = parseControlMessage(oob[:oobn]); err != nil {
37
return 0, nil, nil, err
40
cm.Src = netAddrToIP16(src)
45
// WriteTo writes a payload of the IPv6 datagram, to the destination
46
// address dst through the endpoint c, copying the payload from b. It
47
// returns the number of bytes written. The control message cm allows
48
// the IPv6 header fields and the datagram path to be specified. The
49
// cm may be nil if control of the outgoing datagram is not required.
50
func (c *payloadHandler) WriteTo(b []byte, cm *ControlMessage, dst net.Addr) (n int, err error) {
52
return 0, syscall.EINVAL
54
oob := marshalControlMessage(cm)
56
return 0, errMissingAddress
58
switch c := c.PacketConn.(type) {
60
n, _, err = c.WriteMsgUDP(b, oob, dst.(*net.UDPAddr))
62
n, _, err = c.WriteMsgIP(b, oob, dst.(*net.IPAddr))
64
return 0, errInvalidConnType