Index: src/pkg/net/iprawsock_posix.go |
=================================================================== |
--- a/src/pkg/net/iprawsock_posix.go |
+++ b/src/pkg/net/iprawsock_posix.go |
@@ -98,6 +98,25 @@ |
return n, uaddr.toAddr(), err |
} |
+// ReadMsgIP reads a packet from c, copying the payload into b and the |
+// associdated out-of-band data into oob. It returns the number of |
+// bytes copied into b, the number of bytes copied into oob, the flags |
+// that were set on the packet and the source address of the packet. |
+func (c *IPConn) ReadMsgIP(b, oob []byte) (n, oobn, flags int, addr *IPAddr, err error) { |
+ if !c.ok() { |
+ return 0, 0, 0, nil, syscall.EINVAL |
+ } |
+ var sa syscall.Sockaddr |
+ n, oobn, flags, sa, err = c.fd.ReadMsg(b, oob) |
+ switch sa := sa.(type) { |
+ case *syscall.SockaddrInet4: |
+ addr = &IPAddr{sa.Addr[0:]} |
+ case *syscall.SockaddrInet6: |
+ addr = &IPAddr{sa.Addr[0:]} |
+ } |
+ return |
+} |
+ |
// WriteToIP writes an IP packet to addr via c, copying the payload from b. |
// |
// WriteToIP can be made to time out and return |
@@ -127,6 +146,20 @@ |
return c.WriteToIP(b, a) |
} |
+// WriteMsgIP writes a packet to addr via c, copying the payload from |
+// b and the associated out-of-band data from oob. It returns the |
+// number of payload and out-of-band bytes written. |
+func (c *IPConn) WriteMsgIP(b, oob []byte, addr *IPAddr) (n, oobn int, err error) { |
+ if !c.ok() { |
+ return 0, 0, syscall.EINVAL |
+ } |
+ sa, err := addr.sockaddr(c.fd.family) |
+ if err != nil { |
+ return 0, 0, &OpError{"write", c.fd.net, addr, err} |
+ } |
+ return c.fd.WriteMsg(b, oob, sa) |
+} |
+ |
// DialIP connects to the remote address raddr on the network protocol netProto, |
// which must be "ip", "ip4", or "ip6" followed by a colon and a protocol number or name. |
func DialIP(netProto string, laddr, raddr *IPAddr) (*IPConn, error) { |