Page 293 - DCAP403_Operating System
P. 293
Operating System
Notes There are several socket types and these represent the type of service that supports the connection.
Not all address families support all types of service. Linux BSD sockets support a number of
socket types:
Stream: These sockets provide reliable two way sequenced data streams with a guarantee that
data cannot be lost, corrupted or duplicated in transit. Stream sockets are supported by the TCP
protocol of the Internet (INET) address family.
Datagram: These sockets also provide two way data transfer but, unlike stream sockets, there is
no guarantee that the messages will arrive. Even if they do arrive there is no guarantee that they
will arrive in order or even not be duplicated or corrupted. This type of socket is supported by
the UDP protocol of the Internet address family.
Raw: This allows processes direct (hence ‘‘raw’’) access to the underlying protocols. It is, for
example, possible to open a raw socket to an ethernet device and see raw IP data traffi c.
Reliable Delivered Messages: These are very like datagram sockets but the data is guaranteed to
arrive.
Sequenced Packets: These are like stream sockets except that the data packet sizes are fi xed.
Packet: This is not a standard BSD socket type, it is a Linux specific extension that allows processes
to access packets directly at the device level.
Processes that communicate using sockets use a client server model. A server provides a service
and clients make use of that service. One example would be a Web Server, which provides web
pages and a web client, or browser, which reads those pages. A server using sockets, fi rst creates
a socket and then binds a name to it. The format of this name is dependent on the socket’s address
family and it is, in effect, the local address of the server. The socket’s name or address is specifi ed
using the sockaddr data structure. An INET socket would have an IP port address bound to it.
The registered port numbers can be seen in /etc/services; for example, the port number for a
web server is 80. Having bound an address to the socket, the server then listens for incoming
connection requests specifying the bound address. The originator of the request, the client, creates
a socket and makes a connection request on it, specifying the target address of the server. For
an INET socket the address of the server is its IP address and its port number. These incoming
requests must find their way up through the various protocol layers and then wait on the server’s
listening socket. Once the server has received the incoming request it either accepts or rejects it. If
the incoming request is to be accepted, the server must create a new socket to accept it on. Once a
socket has been used for listening for incoming connection requests it cannot be used to support
a connection. With the connection established both ends are free to send and receive data. Finally,
when the connection is no longer needed it can be shutdown. Care is taken to ensure that data
packets in transit are correctly dealt with.
The exact meaning of operations on a BSD socket depends on its underlying address family.
Setting up TCP/IP connections is very different from setting up an amateur radio X.25 connection.
Like the virtual filesystem, Linux abstracts the socket interface with the BSD socket layer being
concerned with the BSD socket interface to the application programs which is in turn supported
by independent address family specific software. At kernel initialization time, the address families
built into the kernel register themselves with the BSD socket interface. Later on, as applications
create and use BSD sockets, an association is made between the BSD socket and its supporting
address family. This association is made via cross-linking data structures and tables of address
family specific support routines. For example there is an address family specific socket creation
routine which the BSD socket interface uses when an application creates a new socket.
When the kernel is configured, a number of address families and protocols are built into the
protocols vector. Each is represented by its name, for example ``INET’’ and the address of
its initialization routine. When the socket interface is initialized at boot time each protocol’s
initialization routine is called. For the socket address families this results in them registering a set
286 LOVELY PROFESSIONAL UNIVERSITY