// Write implements tcpip.Endpoint.Write.
Write implements tcpip.Endpoint.Write.
// Write implements tcpip . Endpoint . Write .
func (e *endpoint) Write(p tcpip.Payloader, opts tcpip.WriteOptions) (int64, tcpip.Error) {
	if !e.associated && e.TransportEndpointInfo.NetProto == header.IPv6ProtocolNumber {
		return 0, &tcpip.ErrInvalidOptionValue{}
	}
	if opts.To != nil {
		if e.TransportEndpointInfo.NetProto == header.IPv6ProtocolNumber && len(opts.To.Addr) != header.IPv6AddressSize {
			return 0, &tcpip.ErrInvalidOptionValue{}
		}
	}
	n, err := e.write(p, opts)
	switch err.(type) {
	case nil:
		e.stats.PacketsSent.Increment()
	case *tcpip.ErrMessageTooLong, *tcpip.ErrInvalidOptionValue:
		e.stats.WriteErrors.InvalidArgs.Increment()
	case *tcpip.ErrClosedForSend:
		e.stats.WriteErrors.WriteClosed.Increment()
	case *tcpip.ErrInvalidEndpointState:
		e.stats.WriteErrors.InvalidEndpointState.Increment()
	case *tcpip.ErrNoRoute, *tcpip.ErrBroadcastDisabled, *tcpip.ErrNetworkUnreachable:
		e.stats.SendErrors.NoRoute.Increment()
	default:
		e.stats.SendErrors.SendToNetworkFailed.Increment()
	}
	return n, err
}
func ( e * endpoint ) Write ( p tcpip . Payloader , opts tcpip . WriteOptions ) ( int64 , tcpip . Error ) { if ! e . associated && e . TransportEndpointInfo . NetProto == header . IPv6ProtocolNumber { return 0 , & tcpip . ErrInvalidOptionValue { } } if opts . To != nil { if e . TransportEndpointInfo . NetProto == header . IPv6ProtocolNumber && len ( opts . To . Addr ) != header . IPv6AddressSize { return 0 , & tcpip . ErrInvalidOptionValue { } } } n , err := e . write ( p , opts ) switch err . ( type ) { case nil : e . stats . PacketsSent . Increment ( ) case * tcpip . ErrMessageTooLong , * tcpip . ErrInvalidOptionValue : e . stats . WriteErrors . InvalidArgs . Increment ( ) case * tcpip . ErrClosedForSend : e . stats . WriteErrors . WriteClosed . Increment ( ) case * tcpip . ErrInvalidEndpointState : e . stats . WriteErrors . InvalidEndpointState . Increment ( ) case * tcpip . ErrNoRoute , * tcpip . ErrBroadcastDisabled , * tcpip . ErrNetworkUnreachable : e . stats . SendErrors . NoRoute . Increment ( ) default : e . stats . SendErrors . SendToNetworkFailed . Increment ( ) } return n , err }
Write implements tcpip.Endpoint.Write.
Write implements tcpip . Endpoint . Write .
// We can create, but not write to, unassociated IPv6 endpoints. // Raw sockets do not support sending to a IPv4 address on a IPv6 endpoint. // Errors indicating any problem with IP routing of the packet. // For all other errors when writing to the network layer.