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.
6 // +build !nacl,!plan9,!windows
12 func (c *payloadHandler) readFrom(b []byte) (n int, cm *ControlMessage, src net.Addr, err error) {
14 oob := NewControlMessage(c.rawOpt.cflags)
17 switch c := c.PacketConn.(type) {
19 if n, nn, _, src, err = c.ReadMsgUDP(b, oob); err != nil {
20 return 0, nil, nil, err
23 if n, nn, _, src, err = c.ReadMsgIP(b, oob); err != nil {
24 return 0, nil, nil, err
27 return 0, nil, nil, &net.OpError{Op: "read", Net: c.LocalAddr().Network(), Source: c.LocalAddr(), Err: errInvalidConnType}
30 cm = new(ControlMessage)
31 if err = cm.Parse(oob[:nn]); err != nil {
32 return 0, nil, nil, &net.OpError{Op: "read", Net: c.PacketConn.LocalAddr().Network(), Source: c.PacketConn.LocalAddr(), Err: err}
36 cm.Src = netAddrToIP16(src)
41 func (c *payloadHandler) writeTo(b []byte, cm *ControlMessage, dst net.Addr) (n int, err error) {
44 return 0, &net.OpError{Op: "write", Net: c.PacketConn.LocalAddr().Network(), Source: c.PacketConn.LocalAddr(), Err: errMissingAddress}
46 switch c := c.PacketConn.(type) {
48 n, _, err = c.WriteMsgUDP(b, oob, dst.(*net.UDPAddr))
50 n, _, err = c.WriteMsgIP(b, oob, dst.(*net.IPAddr))
52 return 0, &net.OpError{Op: "write", Net: c.LocalAddr().Network(), Source: c.LocalAddr(), Addr: opAddr(dst), Err: errInvalidConnType}