SitemapMain PageTable of contentCopyrightAddison-Wesley Professional Computing SeriesForewordPrefaceIntroductionChanges from the Second EditionUsing This BookSource Code and Errata AvailabilityAcknowledgmentsPart 1: Introduction and TCP/IPChapter 1. Introduction1.1 Introduction1.2 A Simple Daytime Client1.3 Protocol Independence1.4 Error Handling: Wrapper Functions1.5 A Simple Daytime Server1.6 Roadmap to Client/Server Examples in the Text1.7 OSI Model1.8 BSD Networking History1.9 Test Networks and Hosts1.10 Unix Standards1.11 64-Bit Architectures1.12 SummaryExercisesChapter 2. The Transport Layer: TCP, UDP, and SCTP2.1 Introduction2.2 The Big Picture2.3 User Datagram Protocol (UDP)2.4 Transmission Control Protocol (TCP)2.5 Stream Control Transmission Protocol (SCTP)2.6 TCP Connection Establishment and Termination2.7 TIME_WAIT State2.8 SCTP Association Establishment and Termination2.9 Port Numbers2.10 TCP Port Numbers and Concurrent Servers2.11 Buffer Sizes and Limitations2.12 Standard Internet Services2.13 Protocol Usage by Common Internet Applications2.14 SummaryExercisesPart 2: Elementary SocketsChapter 3. Sockets Introduction3.1 Introduction3.2 Socket Address Structures3.3 Value-Result Arguments3.4 Byte Ordering Functions3.5 Byte Manipulation Functions3.6 'inet_aton', 'inet_addr', and 'inet_ntoa' Functions3.7 'inet_pton' and 'inet_ntop' Functions3.8 'sock_ntop' and Related Functions3.9 'readn', 'writen', and 'readline' Functions3.10 SummaryExercisesChapter 4. Elementary TCP Sockets4.1 Introduction4.2 'socket' Function4.3 'connect' Function4.4 'bind' Function4.5 'listen' Function4.6 'accept' Function4.7 'fork' and 'exec' Functions4.8 Concurrent Servers4.9 'close' Function4.10 'getsockname' and 'getpeername' Functions4.11 SummaryExercisesChapter 5. TCP Client/Server Example5.1 Introduction5.2 TCP Echo Server: 'main' Function5.3 TCP Echo Server: 'str_echo' Function5.4 TCP Echo Client: 'main' Function5.5 TCP Echo Client: 'str_cli' Function5.6 Normal Startup5.7 Normal Termination5.8 POSIX Signal Handling5.9 Handling 'SIGCHLD' Signals5.10 'wait' and 'waitpid' Functions5.11 Connection Abort before 'accept' Returns5.12 Termination of Server Process5.13 'SIGPIPE' Signal5.14 Crashing of Server Host5.15 Crashing and Rebooting of Server Host5.16 Shutdown of Server Host5.17 Summary of TCP Example5.18 Data Format5.19 SummaryExercisesChapter 6. I/O Multiplexing: The 'select' and 'poll' Functions6.1 Introduction6.2 I/O Models6.3 'select' Function6.4 'str_cli' Function (Revisited)6.5 Batch Input and Buffering6.6 'shutdown' Function6.7 'str_cli' Function (Revisited Again)6.8 TCP Echo Server (Revisited)6.9 'pselect' Function6.10 'poll' Function6.11 TCP Echo Server (Revisited Again)6.12 SummaryExercisesChapter 7. Socket Options7.1 Introduction7.2 'getsockopt' and 'setsockopt' Functions7.3 Checking if an Option Is Supported and Obtaining the Default7.4 Socket States7.5 Generic Socket Options7.6 IPv4 Socket Options7.7 ICMPv6 Socket Option7.8 IPv6 Socket Options7.9 TCP Socket Options7.10 SCTP Socket Options7.11 'fcntl' Function7.12 SummaryExercisesChapter 8. Elementary UDP Sockets8.1 Introduction8.2 'recvfrom' and 'sendto' Functions8.3 UDP Echo Server: 'main' Function8.4 UDP Echo Server: 'dg_echo' Function8.5 UDP Echo Client: 'main' Function8.6 UDP Echo Client: 'dg_cli' Function8.7 Lost Datagrams8.8 Verifying Received Response8.9 Server Not Running8.10 Summary of UDP Example8.11 'connect' Function with UDP8.12 'dg_cli' Function (Revisited)8.13 Lack of Flow Control with UDP8.14 Determining Outgoing Interface with UDP8.15 TCP and UDP Echo Server Using 'select'8.16 SummaryExercisesChapter 9. Elementary SCTP Sockets9.1 Introduction9.2 Interface Models9.3 'sctp_bindx' Function9.4 'sctp_connectx' Function9.5 'sctp_getpaddrs' Function9.6 'sctp_freepaddrs' Function9.7 'sctp_getladdrs' Function9.8 'sctp_freeladdrs' Function9.9 'sctp_sendmsg' Function9.10 'sctp_recvmsg' Function9.11 'sctp_opt_info' Function9.12 'sctp_peeloff' Function9.13 'shutdown' Function9.14 Notifications9.15 SummaryExercisesChapter 10. SCTP Client/Server Example10.1 Introduction10.2 SCTP One-to-Many-Style Streaming Echo Server: 'main' Function10.3 SCTP One-to-Many-Style Streaming Echo Client: 'main' Function10.4 SCTP Streaming Echo Client: 'str_cli' Function10.5 Exploring Head-of-Line Blocking10.6 Controlling the Number of Streams10.7 Controlling Termination10.8 SummaryExercisesChapter 11. Name and Address Conversions11.1 Introduction11.2 Domain Name System (DNS)11.3 'gethostbyname' Function11.4 'gethostbyaddr' Function11.5 'getservbyname' and 'getservbyport' Functions11.6 'getaddrinfo' Function11.7 'gai_strerror' Function11.8 'freeaddrinfo' Function11.9 'getaddrinfo' Function: IPv611.10 'getaddrinfo' Function: Examples11.11 'host_serv' Function11.12 'tcp_connect' Function11.13 'tcp_listen' Function11.14 'udp_client' Function11.15 'udp_connect' Function11.16 'udp_server' Function11.17 'getnameinfo' Function11.18 Re-entrant Functions11.19 'gethostbyname_r' and 'gethostbyaddr_r' Functions11.20 Obsolete IPv6 Address Lookup Functions11.21 Other Networking Information11.22 SummaryExercisesPart 3: Advanced SocketsChapter 12. IPv4 and IPv6 Interoperability12.1 Introduction12.2 IPv4 Client, IPv6 Server12.3 IPv6 Client, IPv4 Server12.4 IPv6 Address-Testing Macros12.5 Source Code Portability12.6 SummaryExercisesChapter 13. Daemon Processes and the 'inetd' Superserver13.1 Introduction13.2 'syslogd' Daemon13.3 'syslog' Function13.4 'daemon_init' Function13.5 'inetd' Daemon13.6 'daemon_inetd' Function13.7 SummaryExercisesChapter 14. Advanced I/O Functions14.1 Introduction14.2 Socket Timeouts14.3 'recv' and 'send' Functions14.4 'readv' and 'writev' Functions14.5 'recvmsg' and 'sendmsg' Functions14.6 Ancillary Data14.7 How Much Data Is Queued?14.8 Sockets and Standard I/O14.9 Advanced Polling14.10 SummaryExercisesChapter 15. Unix Domain Protocols15.1 Introduction15.2 Unix Domain Socket Address Structure15.3 'socketpair' Function15.4 Socket Functions15.5 Unix Domain Stream Client/Server15.6 Unix Domain Datagram Client/Server15.7 Passing Descriptors15.8 Receiving Sender Credentials15.9 SummaryExercisesChapter 16. Nonblocking I/O16.1 Introduction16.2 Nonblocking Reads and Writes: 'str_cli' Function (Revisited)16.3 Nonblocking 'connect'16.4 Nonblocking 'connect:' Daytime Client16.5 Nonblocking 'connect:' Web Client16.6 Nonblocking 'accept'16.7 SummaryExercisesChapter 17. 'ioctl' Operations17.1 Introduction17.2 'ioctl' Function17.3 Socket Operations17.4 File Operations17.5 Interface Configuration17.6 'get_ifi_info' Function17.7 Interface Operations17.8 ARP Cache Operations17.9 Routing Table Operations17.10 SummaryExercisesChapter 18. Routing Sockets18.1 Introduction18.2 Datalink Socket Address Structure18.3 Reading and Writing18.4 'sysctl' Operations18.5 'get_ifi_info' Function (Revisited)18.6 Interface Name and Index Functions18.7 SummaryExercisesChapter 19. Key Management Sockets19.1 Introduction19.2 Reading and Writing19.3 Dumping the Security Association Database (SADB)19.4 Creating a Static Security Association (SA)19.5 Dynamically Maintaining SAs19.6 SummaryExercisesChapter 20. Broadcasting20.1 Introduction20.2 Broadcast Addresses20.3 Unicast versus Broadcast20.4 'dg_cli' Function Using Broadcasting20.5 Race Conditions20.6 SummaryExercisesChapter 21. Multicasting21.1 Introduction21.2 Multicast Addresses21.3 Multicasting versus Broadcasting on a LAN21.4 Multicasting on a WAN21.5 Source-Specific Multicast21.6 Multicast Socket Options21.7 'mcast_join' and Related Functions21.8 'dg_cli' Function Using Multicasting21.9 Receiving IP Multicast Infrastructure Session Announcements21.10 Sending and Receiving21.11 Simple Network Time Protocol (SNTP)21.12 SummaryExercisesChapter 22. Advanced UDP Sockets22.1 Introduction22.2 Receiving Flags, Destination IP Address, and Interface Index22.3 Datagram Truncation22.4 When to Use UDP Instead of TCP22.5 Adding Reliability to a UDP Application22.6 Binding Interface Addresses22.7 Concurrent UDP Servers22.8 IPv6 Packet Information22.9 IPv6 Path MTU Control22.10 SummaryExercisesChapter 23. Advanced SCTP Sockets23.1 Introduction23.2 An Autoclosing One-to-Many-Style Server23.3 Partial Delivery23.4 Notifications23.5 Unordered Data23.6 Binding a Subset of Addresses23.7 Determining Peer and Local Address Information23.8 Finding an Association ID Given an IP Address23.9 Heartbeating and Address Failure23.10 Peeling Off an Association23.11 Controlling Timing23.12 When to Use SCTP Instead of TCP23.13 SummaryExercisesChapter 24. Out-of-Band Data24.1 Introduction24.2 TCP Out-of-Band Data24.3 'sockatmark' Function24.4 TCP Out-of-Band Data Recap24.5 SummaryExercisesChapter 25. Signal-Driven I/O25.1 Introduction25.2 Signal-Driven I/O for Sockets25.3 UDP Echo Server Using 'SIGIO'25.4 SummaryExercisesChapter 26. Threads26.1 Introduction26.2 Basic Thread Functions: Creation and Termination26.3 'str_cli' Function Using Threads26.4 TCP Echo Server Using Threads26.5 Thread-Specific Data26.6 Web Client and Simultaneous Connections (Continued)26.7 Mutexes: Mutual Exclusion26.8 Condition Variables26.9 Web Client and Simultaneous Connections (Continued)26.10 SummaryExercisesChapter 27. IP Options27.1 Introduction27.2 IPv4 Options27.3 IPv4 Source Route Options27.4 IPv6 Extension Headers27.5 IPv6 Hop-by-Hop Options and Destination Options27.6 IPv6 Routing Header27.7 IPv6 Sticky Options27.8 Historical IPv6 Advanced API27.9 SummaryExercisesChapter 28. Raw Sockets28.1 Introduction28.2 Raw Socket Creation28.3 Raw Socket Output28.4 Raw Socket Input28.5 'ping' Program28.6 'traceroute' Program28.7 An ICMP Message Daemon28.8 SummaryExercisesChapter 29. Datalink Access29.1 Introduction29.2 BSD Packet Filter (BPF)29.3 Datalink Provider Interface (DLPI)29.4 Linux: 'SOCK_PACKET' and 'PF_PACKET'29.5 'libpcap': Packet Capture Library29.6 'libnet': Packet Creation and Injection Library29.7 Examining the UDP Checksum Field29.8 SummaryExercisesChapter 30. Client/Server Design Alternatives30.1 Introduction30.2 TCP Client Alternatives30.3 TCP Test Client30.4 TCP Iterative Server30.5 TCP Concurrent Server, One Child per Client30.6 TCP Preforked Server, No Locking Around 'accept'30.7 TCP Preforked Server, File Locking Around 'accept'30.8 TCP Preforked Server, Thread Locking Around 'accept'30.9 TCP Preforked Server, Descriptor Passing30.10 TCP Concurrent Server, One Thread per Client30.11 TCP Prethreaded Server, per-Thread 'accept'30.12 TCP Prethreaded Server, Main Thread 'accept'30.13 SummaryExercisesChapter 31. Streams31.1 Introduction31.2 Overview31.3 'getmsg' and 'putmsg' Functions31.4 'getpmsg' and 'putpmsg' Functions31.5 'ioctl' Function31.6 Transport Provider Interface (TPI)31.7 SummaryExercisesAppendix A. IPv4, IPv6, ICMPv4, and ICMPv6A.1 IntroductionA.2 IPv4 HeaderA.3 IPv6 HeaderA.4 IPv4 AddressesA.5 IPv6 AddressesA.6 Internet Control Message Protocols (ICMPv4 and ICMPv6)Appendix B. Virtual NetworksB.1 IntroductionB.2 The MBoneB.3 The 6boneB.4 IPv6 Transition: 6to4Appendix C. Debugging TechniquesC.1 System Call TracingC.2 Standard Internet ServicesC.3 'sock' ProgramC.4 Small Test ProgramsC.5 'tcpdump' ProgramC.6 'netstat' ProgramC.7 'lsof' ProgramAppendix D. Miscellaneous Source CodeD.1 'unp.h' HeaderD.2 'config.h' HeaderD.3 Standard Error FunctionsAppendix E. Solutions to Selected ExercisesChapter 1Chapter 2Chapter 3Chapter 4Chapter 5Chapter 6Chapter 7Chapter 8Chapter 9Chapter 10Chapter 11Chapter 12Chapter 13Chapter 14Chapter 15Chapter 16Chapter 17Chapter 18Chapter 20Chapter 21Chapter 22Chapter 24Chapter 25Chapter 26Chapter 27Chapter 28Chapter 29Chapter 30Chapter 31Bibliography |