- Appendix A: Tracing System Calls
An introduction to tracing system call execution using strace(1). - Appendix B: Parsing Command-line Options
This appendix describes the use of the getopt() library function to parse command-line arguments. Many of the example programs in the book use getopt(). - Appendix C: Casting the NULL Pointer
Why is it necessary to use a (char *) cast for the NULL pointer given as an argument to variadic functions such as execl()? - Appendix D: Kernel Configuration
A short guide to configuring the Linux kernel. - Appendix E: Further Sources of Information
A survey of various places to look for information on topics related to the book. - Appendix F: Solutions to Selected Exercises
- Bibliography
- Index
It looks like the index will come in at over 50 pages!
2009-11-29
End matter
After the 64 chapters, we have a few pieces chasing up at the end:
2009-11-27
Chapter 64: Pseudoterminals
A pseudoterminal is a virtual device that provides an IPC channel. On one end of the channel is a program that expects to be connected to a terminal device. On the other end is a program that drives the terminal-oriented program by using the channel to send it input and read its output.
This chapter describes the use of pseudoterminals, showing how they are employed in applications such as terminal emulators, the script(1) program, and programs such as ssh, which provide network login services.
64 Pseudoterminals
64.1 Overview
64.2 UNIX 98 Pseudoterminals
64.2.1 Opening an Unused Master: posix_openpt()
64.2.2 Changing Slave Ownership and Permissions: grantpt()
64.2.3 Unlocking the Slave: unlockpt()
64.2.4 Obtaining the Name of the Slave: ptsname()
64.3 Opening a Pseudoterminal Master: ptyMasterOpen()
64.4 Connecting Two Processes with a Pseudoterminal: ptyFork()
64.5 Pseudoterminal I/O
64.6 Implementing script(1)
64.7 Terminal Attributes and Window Size
64.8 BSD Pseudoterminals
64.9 Summary
64.10 Exercises
This chapter describes the use of pseudoterminals, showing how they are employed in applications such as terminal emulators, the script(1) program, and programs such as ssh, which provide network login services.
64 Pseudoterminals
64.1 Overview
64.2 UNIX 98 Pseudoterminals
64.2.1 Opening an Unused Master: posix_openpt()
64.2.2 Changing Slave Ownership and Permissions: grantpt()
64.2.3 Unlocking the Slave: unlockpt()
64.2.4 Obtaining the Name of the Slave: ptsname()
64.3 Opening a Pseudoterminal Master: ptyMasterOpen()
64.4 Connecting Two Processes with a Pseudoterminal: ptyFork()
64.5 Pseudoterminal I/O
64.6 Implementing script(1)
64.7 Terminal Attributes and Window Size
64.8 BSD Pseudoterminals
64.9 Summary
64.10 Exercises
2009-11-25
Chapter 63: Alternative I/O Models
This chapter discusses three alternatives to the conventional file I/O model that we have employed in most programs shown in this book:
63.1 Overview
63.1.1 Level-triggered and Edge-triggered Notification
63.1.2 Employing Nonblocking I/O with Alternative I/O Models
63.2 I/O Multiplexing
63.2.1 The select() System Call
63.2.2 The poll() System Call
63.2.3 When Is a File Descriptor Ready?
63.2.4 Comparison of select() and poll()
63.2.5 Problems with select() and poll()
63.3 Signal-driven I/O
63.3.1 When Is "I/O Possible" Signaled?
63.3.2 Refining the Use of Signal-driven I/O
63.4 The epoll API
63.4.1 Creating an epoll Instance: epoll_create()
63.4.2 Modifying the epoll Interest List: epoll_ctl()
63.4.3 Waiting for Events: epoll_wait()
63.4.4 A Closer Look at epoll Semantics
63.4.5 Performance of epoll Versus I/O Multiplexing
63.4.6 Edge-triggered Notification
63.5 Waiting on Signals and File Descriptors
63.5.1 The pselect() System Call
63.5.2 The Self-pipe Trick
63.6 Summary
63.7 Exercises
- I/O multiplexing (the select() and poll() system calls);
- signal-driven I/O; and
- the Linux-specific epoll API.
63.1 Overview
63.1.1 Level-triggered and Edge-triggered Notification
63.1.2 Employing Nonblocking I/O with Alternative I/O Models
63.2 I/O Multiplexing
63.2.1 The select() System Call
63.2.2 The poll() System Call
63.2.3 When Is a File Descriptor Ready?
63.2.4 Comparison of select() and poll()
63.2.5 Problems with select() and poll()
63.3 Signal-driven I/O
63.3.1 When Is "I/O Possible" Signaled?
63.3.2 Refining the Use of Signal-driven I/O
63.4 The epoll API
63.4.1 Creating an epoll Instance: epoll_create()
63.4.2 Modifying the epoll Interest List: epoll_ctl()
63.4.3 Waiting for Events: epoll_wait()
63.4.4 A Closer Look at epoll Semantics
63.4.5 Performance of epoll Versus I/O Multiplexing
63.4.6 Edge-triggered Notification
63.5 Waiting on Signals and File Descriptors
63.5.1 The pselect() System Call
63.5.2 The Self-pipe Trick
63.6 Summary
63.7 Exercises
2009-11-24
Chapter 62: Terminals
This chapter focuses on the aspects of terminal programming that are particularly relevant to software terminal emulators (i.e., xterm and similar). It gives only brief coverage to serial lines; references for further information about serial programming at the end of this chapter.
62 Terminals
62.1 Overview
62.2 Retrieving and Modifying Terminal Attributes
62.3 The stty Command
62.4 Terminal Special Characters
62.5 Terminal Flags
62.6 Terminal I/O Modes
62.6.1 Canonical Mode
62.6.2 Noncanonical Mode
62.6.3 Cooked, Cbreak, and Raw Modes
62.7 Terminal Line Speed (Bit Rate)
62.8 Terminal Line Control
62.9 Terminal Window Size
62.10 Terminal Identification
62.11 Summary
62.12 Exercises
62 Terminals
62.1 Overview
62.2 Retrieving and Modifying Terminal Attributes
62.3 The stty Command
62.4 Terminal Special Characters
62.5 Terminal Flags
62.6 Terminal I/O Modes
62.6.1 Canonical Mode
62.6.2 Noncanonical Mode
62.6.3 Cooked, Cbreak, and Raw Modes
62.7 Terminal Line Speed (Bit Rate)
62.8 Terminal Line Control
62.9 Terminal Window Size
62.10 Terminal Identification
62.11 Summary
62.12 Exercises
2009-11-23
Copyediting done
Nearly everything is now copyedited. The only piece that is yet to go to the copyeditor is the preface, which I'm still working on.
2009-11-22
Chapter 61: Sockets: Advanced Topics
This chapter considers a range of more advanced topics relating to sockets programming, including the following:
61 Sockets: Advanced Topics
61.1 Partial Reads and Writes on Stream Sockets
61.2 The shutdown() system call
61.3 Socket-specific I/O System Calls: recv() and send()
61.4 The sendfile() System Call
61.5 Retrieving Socket Addresses: getsockname() and getpeername()
61.6 A Closer Look at TCP
61.6.1 Format of a TCP Segment
61.6.2 TCP Sequence Numbers and Acknowledgements
61.6.3 TCP State Machine and State Transition Diagram
61.6.4 TCP Connection Establishment
61.6.5 TCP Connection Termination
61.6.6 Calling shutdown() on a TCP Socket
61.6.7 The TIME_WAIT State
61.7 Monitoring Sockets: netstat
61.8 Using tcpdump to Monitor TCP Traffic
61.9 Socket Options: setsockopt() and getsockopt()
61.10 The SO_REUSEADDR Socket Option
61.11 Inheritance of File Flags and Socket Options across accept()
61.12 TCP Versus UDP
61.13 Advanced Features
61.13.1 Out-of-band Data
61.13.2 The sendmsg() and recvmsg() System Calls
61.13.3 Passing File Descriptors
61.13.4 Receiving Sender Credentials
61.13.5 Sequenced-packet Sockets
61.13.6 SCTP and DCCP Transport-layer Protocols
61.14 Summary
61.15 Exercises
- the circumstances in which partial reads and writes can occur on stream sockets;
- the use of shutdown() to close one half of the bidirectional channel between two connected sockets;
- the recv() and send() I/O system calls, which provide socket-specific functionality not available with read() and write();
- the sendfile() system call, which is used in certain circumstances to efficiently output data on a socket;
- details of the operation of the TCP protocol, with the aim of eliminating some common misunderstandings that lead to mistakes when writing programs that use TCP sockets;
- the use of the netstat and tcpdump commands for monitoring and debugging applications that use sockets; and
- the use of the getsockopt() and setsockopt() system calls to retrieve and modify options affecting the operation of a socket.
61 Sockets: Advanced Topics
61.1 Partial Reads and Writes on Stream Sockets
61.2 The shutdown() system call
61.3 Socket-specific I/O System Calls: recv() and send()
61.4 The sendfile() System Call
61.5 Retrieving Socket Addresses: getsockname() and getpeername()
61.6 A Closer Look at TCP
61.6.1 Format of a TCP Segment
61.6.2 TCP Sequence Numbers and Acknowledgements
61.6.3 TCP State Machine and State Transition Diagram
61.6.4 TCP Connection Establishment
61.6.5 TCP Connection Termination
61.6.6 Calling shutdown() on a TCP Socket
61.6.7 The TIME_WAIT State
61.7 Monitoring Sockets: netstat
61.8 Using tcpdump to Monitor TCP Traffic
61.9 Socket Options: setsockopt() and getsockopt()
61.10 The SO_REUSEADDR Socket Option
61.11 Inheritance of File Flags and Socket Options across accept()
61.12 TCP Versus UDP
61.13 Advanced Features
61.13.1 Out-of-band Data
61.13.2 The sendmsg() and recvmsg() System Calls
61.13.3 Passing File Descriptors
61.13.4 Receiving Sender Credentials
61.13.5 Sequenced-packet Sockets
61.13.6 SCTP and DCCP Transport-layer Protocols
61.14 Summary
61.15 Exercises
2009-11-21
Chapter 60: Sockets: Server Design
This chapter discusses the fundamentals of designing iterative and concurrent servers and describes inetd, a special daemon designed to facilitate the creation of Internet servers.
60 Sockets: Server Design
60.1 Iterative and Concurrent Servers
60.2 An Iterative UDP echo Server
60.3 A Concurrent TCP echo Server
60.4 Other Concurrent Server Designs
60.5 The inetd (Internet Superserver) Daemon
60.6 Summary
60.7 Exercises
60 Sockets: Server Design
60.1 Iterative and Concurrent Servers
60.2 An Iterative UDP echo Server
60.3 A Concurrent TCP echo Server
60.4 Other Concurrent Server Designs
60.5 The inetd (Internet Superserver) Daemon
60.6 Summary
60.7 Exercises
2009-11-17
Chapter 59: Sockets: Internet Domains
Having looked at generic sockets concepts and the TCP/IP protocol suite in previous chapters, we are now ready in this chapter to look at programming with sockets in the IPv4 (AF_INET) and IPv6 (AF_INET6) domains.
As noted in Chapter 58, Internet domain socket addresses consist of an IP address and a port number. Although computers use binary representations of IP addresses and port numbers, humans are much better at dealing with names than with numbers. Therefore, we describe the techniques used to identify host computers and ports using names. We also examine the use of library functions to obtain the IP address(es) for a particular hostname and the port number that corresponds to a particular service name. Our discussion of hostnames includes a description of the Domain Name System (DNS), which implements a distributed database that maps hostnames to IP addresses and vice versa.
59 Sockets: Internet Domains
59.1 Internet Domain Sockets
59.2 Network Byte Order
59.3 Data Representation
59.4 Internet Socket Addresses
59.5 Overview of Host and Service Conversion Functions
59.6 IPv6 and IPv4 Address Conversion: inet_pton() and inet_ntop()
59.7 Client-server Example (Datagram Sockets)
59.8 Domain Name System (DNS)
59.9 The /etc/services File
59.10 Protocol-independent Host and Service Conversion
59.10.1 The getaddrinfo() Function
59.10.2 Freeing addrinfo Lists: freeaddrinfo()
59.10.3 Diagnosing Errors: gai_strerror()
59.10.4 The getnameinfo() Function
59.11 Client-server Example (Stream Sockets)
59.12 An Internet Domain Sockets Library
59.13 Obsolete APIs for Host, Service, and Address Conversion
59.13.1 The inet_aton() and inet_ntoa() Functions
59.13.2 The gethostbyname() and gethostbyaddr() Functions
59.13.3 The getservbyname() and getservbyport() Functions
59.14 UNIX Versus Internet Domain Sockets
59.15 Further Information
59.16 Summary
59.17 Exercises
As noted in Chapter 58, Internet domain socket addresses consist of an IP address and a port number. Although computers use binary representations of IP addresses and port numbers, humans are much better at dealing with names than with numbers. Therefore, we describe the techniques used to identify host computers and ports using names. We also examine the use of library functions to obtain the IP address(es) for a particular hostname and the port number that corresponds to a particular service name. Our discussion of hostnames includes a description of the Domain Name System (DNS), which implements a distributed database that maps hostnames to IP addresses and vice versa.
59 Sockets: Internet Domains
59.1 Internet Domain Sockets
59.2 Network Byte Order
59.3 Data Representation
59.4 Internet Socket Addresses
59.5 Overview of Host and Service Conversion Functions
59.6 IPv6 and IPv4 Address Conversion: inet_pton() and inet_ntop()
59.7 Client-server Example (Datagram Sockets)
59.8 Domain Name System (DNS)
59.9 The /etc/services File
59.10 Protocol-independent Host and Service Conversion
59.10.1 The getaddrinfo() Function
59.10.2 Freeing addrinfo Lists: freeaddrinfo()
59.10.3 Diagnosing Errors: gai_strerror()
59.10.4 The getnameinfo() Function
59.11 Client-server Example (Stream Sockets)
59.12 An Internet Domain Sockets Library
59.13 Obsolete APIs for Host, Service, and Address Conversion
59.13.1 The inet_aton() and inet_ntoa() Functions
59.13.2 The gethostbyname() and gethostbyaddr() Functions
59.13.3 The getservbyname() and getservbyport() Functions
59.14 UNIX Versus Internet Domain Sockets
59.15 Further Information
59.16 Summary
59.17 Exercises
2009-11-16
Chapter 58: Sockets: Fundamentals of TCP/IP Networks
This chapter provides an introduction to computer networking concepts and the TCP/IP networking protocols. An understanding of these topics is necessary to make effective use of Internet domain sockets, which are described in the next chapter.
58 Sockets: Fundamentals of TCP/IP Networks
58.1 Internets
58.2 Networking Protocols and Layers
58.3 The Data-link Layer
58.4 The Network Layer: IP
58.5 IP Addresses
58.6 The Transport Layer
58.6.1 Port Numbers
58.6.2 User Datagram Protocol (UDP)
58.6.3 Transmission Control Protocol (TCP)
58.7 Requests for Comments (RFCs)
58.8 Summary
58 Sockets: Fundamentals of TCP/IP Networks
58.1 Internets
58.2 Networking Protocols and Layers
58.3 The Data-link Layer
58.4 The Network Layer: IP
58.5 IP Addresses
58.6 The Transport Layer
58.6.1 Port Numbers
58.6.2 User Datagram Protocol (UDP)
58.6.3 Transmission Control Protocol (TCP)
58.7 Requests for Comments (RFCs)
58.8 Summary
2009-11-14
Chapter 57: Sockets: UNIX Domain
This chapter looks at the use of UNIX domain sockets for communicating between processes on the same host system. We discuss the use of both stream and datagram sockets in the UNIX domain. We also describe the use of file permissions to control access to UNIX domain sockets, the use of socketpair() to create a pair of connected UNIX domain sockets, and the Linux abstract socket namespace.
57 Sockets: UNIX Domain
57.1 UNIX Domain Socket Addresses: struct sockaddr_un
57.2 Stream Sockets in the UNIX Domain
57.3 Datagram Sockets in the UNIX Domain
57.4 UNIX Domain Socket Permissions
57.5 Creating a Connected Socket Pair: socketpair()
57.6 The Linux Abstract Socket Namespace
57.7 Summary
57.8 Exercises
57 Sockets: UNIX Domain
57.1 UNIX Domain Socket Addresses: struct sockaddr_un
57.2 Stream Sockets in the UNIX Domain
57.3 Datagram Sockets in the UNIX Domain
57.4 UNIX Domain Socket Permissions
57.5 Creating a Connected Socket Pair: socketpair()
57.6 The Linux Abstract Socket Namespace
57.7 Summary
57.8 Exercises
2009-11-13
Chapter 56: Sockets: Introduction
Sockets are a method of IPC that allow data to be exchanged between applications, either on the same host (computer) or on different hosts connected by a network. The first widespread implementation of the sockets API appeared with 4.2BSD in 1983, and this API has been ported to virtually every Unix implementation, as well as most other operating systems.
This chapter and the following chapters describe the use of sockets, as follows:
56 Sockets: Introduction
56.1 Overview
56.2 Creating a Socket: socket()
56.3 Binding a Socket to an Address: bind()
56.4 Generic Socket Address Structures: struct sockaddr
56.5 Stream Sockets
56.5.1 Listening for Incoming Connections: listen()
56.5.2 Accepting a Connection: accept()
56.5.3 Connecting to a Peer Socket: connect()
56.5.4 I/O on Stream Sockets
56.5.5 Connection Termination: close()
56.6 Datagram Sockets
56.6.1 Exchanging Datagrams: recvfrom() and sendto()
56.6.2 Using connect() with Datagram Sockets
56.7 Summary
This chapter and the following chapters describe the use of sockets, as follows:
- This chapter provides a general introduction to the sockets API. The following chapters assume an understanding of the general concepts presented here. We don’t present any example code in this chapter. Code examples in the Unix and Internet domains are presented in the following chapters.
- Chapter 57 describes Unix domain sockets, which allow communication between applications on the same host system.
- Chapter 58 introduces various computer networking concepts and describes key features of the TCP/IP networking protocols. It provides background needed for the next chapters.
- Chapter 59 describes Internet domain sockets, which allow applications on different hosts to communicate via a TCP/IP network.
- Chapter 60 discusses the design of servers that use sockets.
- Chapter 61 covers a range of advanced topics, including additional features for socket I/O, a more detailed look at TCP (the protocol used for Internet domain stream sockets), and the use of socket options to retrieve and modify various attributes of sockets.
56 Sockets: Introduction
56.1 Overview
56.2 Creating a Socket: socket()
56.3 Binding a Socket to an Address: bind()
56.4 Generic Socket Address Structures: struct sockaddr
56.5 Stream Sockets
56.5.1 Listening for Incoming Connections: listen()
56.5.2 Accepting a Connection: accept()
56.5.3 Connecting to a Peer Socket: connect()
56.5.4 I/O on Stream Sockets
56.5.5 Connection Termination: close()
56.6 Datagram Sockets
56.6.1 Exchanging Datagrams: recvfrom() and sendto()
56.6.2 Using connect() with Datagram Sockets
56.7 Summary
2009-11-11
Copyedit nearly done!
Chapters 56 to 61 are back from copyedit. And chapters 62 to 64, the appendixes, and the bibliography already also went to the copyeditor and came back for my review (as yet unfinished).
Subscribe to:
Posts (Atom)
