The Linux Programming Interface

(nextflipdebug5) #1

1184 Chapter 58


58.4 The Network Layer: IP


Above the data-link layer is the network layer, which is concerned with delivering
packets (data) from the source host to the destination host. This layer performs a
variety of tasks, including:
z breaking data into fragments small enough for transmission via the data-link
layer (if necessary);
z routing data across the internet; and
z providing services to the transport layer.
In the TCP/IP protocol suite, the principal protocol in the network layer is IP. The
version of IP that appeared in the 4.2BSD implementation was IP version 4 (IPv4).
In the early 1990s, a revised version of IP was devised: IP version 6 (IPv6). The most
notable difference between the two versions is that IPv4 identifies subnets and
hosts using 32-bit addresses, while IPv6 uses 128-bit addresses, thus providing a
much larger range of addresses to be assigned to hosts. Although IPv4 is still the
predominant version of IP in use on the Internet, in coming years, it should be sup-
planted by IPv6. Both IPv4 and IPv6 support the higher UDP and TCP transport-
layer protocols (as well as many other protocols).

Although a 32-bit address space theoretically permits billions of IPv4 network
addresses to be assigned, the manner in which addresses were structured and
allocated meant that the practical number of available addresses was far lower.
The possible exhaustion of the IPv4 address space was one of the primary
motivations for the creation of IPv6.
A short history of IPv6 can be found at http://www.laynetworks.com/
IPv6.htm.
The existence of IPv4 and IPv6 begs the question, “What about IPv5?”
There never was an IPv5 as such. Each IP datagram header includes a 4-bit ver-
sion number field (thus, IPv4 datagrams always have the number 4 in this
field), and the version number 5 was assigned to an experimental protocol,
Internet Stream Protocol. (Version 2 of this protocol, abbreviated as ST-II, is
described in RFC 1819.) Initially conceived in the 1970s, this connection-oriented
protocol was designed to support voice and video transmission, and distributed
simulation. Since the IP datagram version number 5 was already assigned, the
successor to IPv4 was assigned the version number 6.

Figure 58-2 shows a raw socket type (SOCK_RAW), which allows an application to com-
municate directly with the IP layer. We don’t describe the use of raw sockets, since
most applications employ sockets over one of the transport-layer protocols (TCP or
UDP). Raw sockets are described in Chapter 28 of [Stevens et al., 2004]. One
instructive example of the use of raw sockets is the sendip program (http://
http://www.earth.li/projectpurple/progs/sendip.html), which is a command-line-driven tool
that allows the construction and transmission of IP datagrams with arbitrary contents
(including options to construct UDP datagrams and TCP segments).

IP transmits datagrams
IP transmits data in the form of datagrams (packets). Each datagram sent between
two hosts travels independently across the network, possibly taking a different
Free download pdf