|
||
In order to communicate with a remote host through a socket, a protocol must establish:
the IP address and port of the socket
a route to the remote host
a network interface by which to access that route
The actions to do this are performed when:
a TCP socket is connected with
RSocket::Connect()
a UDP socket is written to with RSocket::Send()
,
RSocket::Write()
, or RSocket::SendTo()
a UDP socket is ‘connected’ with
RSocket::Connect()
The standard steps are as follows:
The IP routing table is checked to see if a route to the destination exists. If there is no route (including no default route), then the protocol attempts to invoke its default dial-up interface.
If dial-up is successful, PPP is invoked to establish a connection to the remote peer.
In its set-up stage, PPP obtains a local IP address from the remote peer (if so configured) and is informed of the peer’s IP address.
When TCP/IP is informed that the interface is up, it adds routing entries for the interface. Normally this means that the remote peer becomes the default gateway.
If a local address has not been set by
RSocket::Bind()
, then the protocol sets the socket’s local
address to that obtained in step 3 (which is recorded in the route entry
created in step 4), and allocates an ephemeral port number. This process is
called automatic binding.