// Connect implements tcpip.Endpoint.Connect.
Connect implements tcpip.Endpoint.Connect.
// Connect implements tcpip . Endpoint . Connect .
func (e *endpoint) Connect(addr tcpip.FullAddress) tcpip.Error {
	if e.TransportEndpointInfo.NetProto == header.IPv6ProtocolNumber && len(addr.Addr) != header.IPv6AddressSize {
		return &tcpip.ErrAddressFamilyNotSupported{}
	}
	e.mu.Lock()
	defer e.mu.Unlock()
	if e.closed {
		return &tcpip.ErrInvalidEndpointState{}
	}
	nic := addr.NIC
	if e.bound {
		if e.BindNICID == 0 {
		} else if addr.NIC == 0 {
			nic = e.BindNICID
		} else if addr.NIC != e.BindNICID {
			return &tcpip.ErrInvalidEndpointState{}
		}
	}
	route, err := e.stack.FindRoute(nic, "", addr.Addr, e.NetProto, false)
	if err != nil {
		return err
	}
	if e.associated {
		if err := e.stack.RegisterRawTransportEndpoint(e.NetProto, e.TransProto, e); err != nil {
			route.Release()
			return err
		}
		e.stack.UnregisterRawTransportEndpoint(e.NetProto, e.TransProto, e)
		e.RegisterNICID = nic
	}
	if e.route != nil {
		e.route.Release()
	}
	e.route = route
	e.connected = true
	return nil
}
func ( e * endpoint ) Connect ( addr tcpip . FullAddress ) tcpip . Error { if e . TransportEndpointInfo . NetProto == header . IPv6ProtocolNumber && len ( addr . Addr ) != header . IPv6AddressSize { return & tcpip . ErrAddressFamilyNotSupported { } } e . mu . Lock ( ) defer e . mu . Unlock ( ) if e . closed { return & tcpip . ErrInvalidEndpointState { } } nic := addr . NIC if e . bound { if e . BindNICID == 0 { } else if addr . NIC == 0 { nic = e . BindNICID } else if addr . NIC != e . BindNICID { return & tcpip . ErrInvalidEndpointState { } } } route , err := e . stack . FindRoute ( nic , " " , addr . Addr , e . NetProto , false ) if err != nil { return err } if e . associated { if err := e . stack . RegisterRawTransportEndpoint ( e . NetProto , e . TransProto , e ) ; err != nil { route . Release ( ) return err } e . stack . UnregisterRawTransportEndpoint ( e . NetProto , e . TransProto , e ) e . RegisterNICID = nic } if e . route != nil { e . route . Release ( ) } e . route = route e . connected = true return nil }
Connect implements tcpip.Endpoint.Connect.
Connect implements tcpip . Endpoint . Connect .
// Raw sockets do not support connecting to a IPv4 address on a IPv6 endpoint. // If we're bound, but not to a specific NIC, the NIC // in addr will be used. Nothing to do here. // If we're bound to a specific NIC, but addr doesn't // specify a NIC, use the bound NIC. // We're bound and addr specifies a NIC. They must be // the same. // Find a route to the destination. // Re-register the endpoint with the appropriate NIC. // If the endpoint was previously connected then release any previous route.