The Linux Programming Interface

(nextflipdebug5) #1

1236 Chapter 59


z [Sarolahti & Kuznetsov, 2002] describes congestion control and other details
of the Linux TCP implementation.
z Linux-specific information can be found in the following manual pages:
socket(7), ip(7), raw(7), tcp(7), udp(7), and packet(7).
z See also the RFC list in Section 58.7.

59.16 Summary


Internet domain sockets allow applications on different hosts to communicate via a
TCP/IP network. An Internet domain socket address consists of an IP address and
a port number. In IPv4, an IP address is a 32-bit number; in IPv6, it is a 128-bit number.
Internet domain datagram sockets operate over UDP, providing connectionless,
unreliable, message-oriented communication. Internet domain stream sockets operate
over TCP, and provide a reliable, bidirectional, byte-stream communication channel
between two connected applications.
Different computer architectures use different conventions for representing
data types. For example, integers may be stored in little-endian or big-endian form,
and different computers may use different numbers of bytes to represent numeric
types such as int or long. These differences mean that we need to employ some
architecture-independent representation when transferring data between hetero-
geneous machines connected via a network. We noted that various marshalling
standards exist to deal this problem, and also described a simple solution used by
many applications: encoding all transmitted data in text form, with fields delimited
by a designated character (usually a newline).
We looked at a range of functions that can be used to convert between
(numeric) string representations of IP addresses (dotted-decimal for IPv4 and hex-
string for IPv6) and their binary equivalents. However, it is generally preferable to
use host and service names rather than numbers, since names are easier to remem-
ber and continue to be usable, even if the corresponding number is changed. We
looked at various functions that convert host and service names to their numeric
equivalents and vice versa. The modern function for translating host and service
names into socket addresses is getaddrinfo(), but it is common to see the historical
functions gethostbyname() and getservbyname() in existing code.
Consideration of hostname conversions led us into a discussion of DNS, which
implements a distributed database for a hierarchical directory service. The advan-
tage of DNS is that the management of the database is not centralized. Instead,
local zone administrators update changes for the hierarchical component of the
database for which they are responsible, and DNS servers communicate with one
another in order to resolve a hostname.

59.17 Exercises


59-1. When reading large quantities of data, the readLine() function shown in Listing 59-1
is inefficient, since a system call is required to read each character. A more efficient
interface would read a block of characters into a buffer and extract a line at a time from
this buffer. Such an interface might consist of two functions. The first of these
functions, which might be called readLineBufInit(fd, &rlbuf), initializes the bookkeeping
Free download pdf