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.
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 nb := make([]byte, maxHeaderLen+len(b))
24 if n, nn, _, src, err = c.ReadMsgIP(nb, oob); err != nil {
25 return 0, nil, nil, err
27 hdrlen := int(nb[0]&0x0f) << 2
31 return 0, nil, nil, &net.OpError{Op: "read", Net: c.LocalAddr().Network(), Source: c.LocalAddr(), Err: errInvalidConnType}
34 cm = new(ControlMessage)
35 if err = cm.Parse(oob[:nn]); err != nil {
36 return 0, nil, nil, &net.OpError{Op: "read", Net: c.PacketConn.LocalAddr().Network(), Source: c.PacketConn.LocalAddr(), Err: err}
40 cm.Src = netAddrToIP4(src)
45 func (c *payloadHandler) writeTo(b []byte, cm *ControlMessage, dst net.Addr) (n int, err error) {
48 return 0, &net.OpError{Op: "write", Net: c.PacketConn.LocalAddr().Network(), Source: c.PacketConn.LocalAddr(), Err: errMissingAddress}
50 switch c := c.PacketConn.(type) {
52 n, _, err = c.WriteMsgUDP(b, oob, dst.(*net.UDPAddr))
54 n, _, err = c.WriteMsgIP(b, oob, dst.(*net.IPAddr))
56 return 0, &net.OpError{Op: "write", Net: c.LocalAddr().Network(), Source: c.LocalAddr(), Addr: opAddr(dst), Err: errInvalidConnType}