Unix Network Programming, Vol. 1: The Sockets Networking API, 3/e (Hardcover)

W. Richard Stevens, Bill Fenner, Andrew M. Rudoff

買這商品的人也買了...

相關主題

商品描述

"Everyone will want this book because it provides a great mix of practical experience, historical perspective, and a depth of understanding that only comes from being intimately involved in the field. I've already enjoyed and learned from reading this book, and surely you will too."

--Sam Leffler

The classic guide to UNIX networking APIs... now completely updated!

To build today's highly distributed, networked applications and services, you need deep mastery of sockets and other key networking APIs. One book delivers comprehensive, start-to-finish guidance for building robust, high-performance networked systems in any environment: UNIX Network Programming, Volume 1, Third Edition.

Building on the legendary work of W. Richard Stevens, this edition has been fully updated by two leading network programming experts to address today's most crucial standards, implementations, and techniques. New topics include:

  • POSIX Single UNIX Specification Version 3
  • IPv6 APIs (including updated guidance on IPv6/IPv4 interoperability)
  • The new SCTP transport protocol
  • IPsec-based Key Management Sockets
  • FreeBSD 4.8/5.1, Red Hat Linux 9.x, Solaris 9, AIX 5.x, HP-UX, and Mac OS X implementations
  • New network program debugging techniques
  • Source Specific Multicast API, the key enabler for widespread IP multicast deployment

The authors also update and extend Stevens' definitive coverage of these crucial UNIX networking standards and techniques:

  • TCP and UDP transport
  • Sockets: elementary, advanced, routed, and raw
  • I/O: multiplexing, advanced functions, nonblocking, and signal-driven
  • Daemons and inetd
  • UNIX domain protocols
  • ioctl operations
  • Broadcasting and multicasting
  • Threads
  • Streams
  • Design: TCP iterative, concurrent, preforked, and prethreaded servers

Since 1990, network programmers have turned to one source for the insights and techniques they need: W. Richard Stevens' UNIX Network Programming. Now, there's an edition specifically designed for today's challenges--and tomorrow's.

Table of Contents:

Foreword.
Preface.

I. INTRODUCTION AND TCP/IP.

1. Introduction.

 

Introduction.

 

 

A Simple Daytime Client.

 

 

Protocol Independence.

 

 

Error Handling: Wrapper Functions.

 

 

A Simple Daytime Server.

 

 

Roadmap to Client/Server Examples in the Text.

 

 

OSI Model.

 

 

BSD Networking History.

 

 

Test Networks and Hosts.

 

 

Unix Standards.

 

 

64-Bit Architectures.

 

 

Summary.

 

2. The Transport Layer: TCP, UDP, and SCTP.

 

Introduction.

 

 

The Big Picture.

 

 

User Datagram Protocol (UDP).

 

 

Transmission Control Protocol (TCP).

 

 

Stream Control Transmission Protocol (SCTP).

 

 

TCP Connection Establishment and Termination.

 

 

TIME_WAIT State.

 

 

SCTP Association Establishment and Termination.

 

 

Port Numbers.

 

 

TCP Port Numbers and Concurrent Servers.

 

 

Buffer Sizes and Limitations.

 

 

Standard Internet Services.

 

 

Protocol Usage by Common Internet Applications.

 

 

Summary.

 

II. ELEMENTARY SOCKETS.

3. Sockets Introduction.

 

Introduction.

 

 

Socket Address Structures.

 

 

Value-Result Arguments.

 

 

Byte Ordering Functions.

 

 

Byte Manipulation Functions.

 

 

inet_aton, inet_addr, and inet_ntoa Functions.

 

 

inet_pton and inet_ntop Functions.

 

 

sock_ntop and Related Functions.

 

 

readn, writen, and readline Functions.

 

 

Summary.

 

4. Elementary TCP Sockets.

 

Introduction.

 

 

socket Function.

 

 

connect Function.

 

 

bind Function.

 

 

listen Function.

 

 

accept Function.

 

 

fork and exec Functions.

 

 

Concurrent Servers.

 

 

close Function.

 

 

getsockname and getpeername Functions.

 

 

Summary.

 

5. TCP Client/Server Example.

 

Introduction.

 

 

TCP Echo Server: main Function.

 

 

TCP Echo Server: str_echo Function.

 

 

TCP Echo Client: main Function.

 

 

TCP Echo Client: str_cli Function.

 

 

Normal Startup.

 

 

Normal Termination.

 

 

POSIX Signal Handling.

 

 

Handling SIGCHLD Signals.

 

 

wait and waitpid Functions.

 

 

Connection Abort before accept Returns.

 

 

Termination of Server Process.

 

 

SIGPIPE Signal.

 

 

Crashing of Server Host.

 

 

Crashing and Rebooting of Server Host.

 

 

Shutdown of Server Host.

 

 

Summary of TCP Example.

 

 

Data Format.

 

 

Summary.

 

6. I/O Multiplexing: The select and poll Functions.

 

Introduction.

 

 

I/O Models.

 

 

select Function.

 

 

str_cli Function (Revisited).

 

 

Batch Input and Buffering.

 

 

shutdown Function.

 

 

str_cli Function (Revisited Again).

 

 

TCP Echo Server (Revisited).

 

 

pselect Function.

 

 

poll Function.

 

 

TCP Echo Server (Revisited Again).

 

 

Summary.

 

7. Socket Options.

 

Introduction.

 

 

getsockopt and setsockopt Functions.

 

 

Checking if an Option Is Supported and Obtaining the Default.

 

 

Socket States.

 

 

Generic Socket Options.

 

 

IPv4 Socket Options.

 

 

ICMPv6 Socket Option.

 

 

IPv6 Socket Options.

 

 

TCP Socket Options.

 

 

SCTP Socket Options.

 

 

fcntl Function.

 

 

Summary.

 

8. Elementary UDP Sockets.

 

Introduction.

 

 

recvfrom and sendto Functions.

 

 

UDP Echo Server: main Function.

 

 

UDP Echo Server: dg_echo Function.

 

 

UDP Echo Client: main Function.

 

 

UDP Echo Client: dg_cli Function.

 

 

Lost Datagrams.

 

 

Verifying Received Response.

 

 

Server Not Running.

 

 

Summary of UDP Example.

 

 

connect Function with UDP.

 

 

dg_cli Function (Revisited).

 

 

Lack of Flow Control with UDP.

 

 

Determining Outgoing Interface with UDP.

 

 

TCP and UDP Echo Server Using select.

 

 

Summary.

 

9. Elementary SCTP Sockets.

 

Introduction.

 

 

Interface Models.

 

 

sctp_bindx Function.

 

 

sctp_connectx Function.

 

 

sctp_getpaddrs Function.

 

 

sctp_freepaddrs Function.

 

 

sctp_getladdrs Function.

 

 

sctp_freeladdrs Function.

 

 

sctp_sendmsg Function.

 

 

sctp_recvmsg Function.

 

 

sctp_opt_info Function.

 

 

sctp_peeloff Function.

 

 

shutdown Function.

 

 

Notifications.

 

 

Summary.

 

10. SCTP Client/Server Example.

 

Introduction.

 

 

SCTP One-to-Many-Style Streaming Echo Server: main Function.

 

 

SCTP One-to-Many-Style Streaming Echo Client: main Function.

 

 

SCTP Streaming Echo Client: str_cli Function.

 

 

Exploring Head-of-Line Blocking.

 

 

Controlling the Number of Streams.

 

 

Controlling Termination.

 

 

Summary.

 

11. Name and Address Conversions.

 

Introduction.

 

 

Domain Name System (DNS).

 

 

gethostbyname Function.

 

 

gethostbyaddr Function.

 

 

getservbyname and getservbyport Functions.

 

 

getaddrinfo Function.

 

 

gai_strerror Function.

 

 

freeaddrinfo Function.

 

 

getaddrinfo Function: IPv6.

 

 

getaddrinfo Function: Examples.

 

 

host_serv Function.

 

 

tcp_connect Function.

 

 

tcp_listen Function.

 

 

udp_client Function.

 

 

udp_connect Function.

 

 

udp_server Function.

 

 

getnameinfo Function.

 

 

Re-entrant Functions.

 

 

gethostbyname_r and gethostbyaddr_r Functions.

 

 

Obsolete IPv6 Address Lookup Functions.

 

 

Other Networking Information.

 

 

Summary.

 

III. ADVANCED SOCKETS.

12. IPv4 and IPv6 Interoperability.

 

Introduction.

 

 

IPv4 Client, IPv6 Server.

 

 

IPv6 Client, IPv4 Server.

 

 

IPv6 Address-Testing Macros.

 

 

Source Code Portability.

 

 

Summary.

 

13. Daemon Processes and the inetd Superserver.

 

Introduction.

 

 

syslogd Daemon.

 

 

syslog Function.

 

 

daemon_init Function.

 

 

inetd Daemon.

 

 

daemon_inetd Function.

 

 

Summary.

 

14. Advanced I/O Functions.

 

Introduction.

 

 

Socket Timeouts.

 

 

recv and send Functions.

 

 

readv and writev Functions.

 

 

recvmsg and sendmsg Functions.

 

 

Ancillary Data.

 

 

How Much Data Is Queued?

 

 

Sockets and Standard I/O.

 

 

Advanced Polling.

 

 

Summary.

 

15. Unix Domain Protocols.

 

Introduction.

 

 

Unix Domain Socket Address Structure.

 

 

socketpair Function.

 

 

Socket Functions.

 

 

Unix Domain Stream Client/Server.

 

 

Unix Domain Datagram Client/Server.

 

 

Passing Descriptors.

 

 

Receiving Sender Credentials.

 

 

Summary.

 

16. Nonblocking I/O.

 

Introduction.

 

 

Nonblocking Reads and Writes: str_cli Function (Revisited).

 

 

Nonblocking connect.

 

 

Nonblocking connect: Daytime Client.

 

 

Nonblocking connect: Web Client.

 

 

Nonblocking accept.

 

 

Summary.

 

17. ioctl Operations.

 

Introduction.

 

 

ioctl Function.

 

 

Socket Operations.

 

 

File Operations.

 

 

Interface Configuration.

 

 

get_ifi_info Function.

 

 

Interface Operations.

 

 

ARP Cache Operations.

 

 

Routing Table Operations.

 

 

Summary.

 

18. Routing Sockets.

 

Introduction.

 

 

Datalink Socket Address Structure.

 

 

Reading and Writing.

 

 

sysctl Operations.

 

 

get_ifi_info Function (Revisited).

 

 

Interface Name and Index Functions.

 

 

Summary.

 

19. Key Management Sockets.

 

Introduction.

 

 

Reading and Writing.

 

 

Dumping the Security Association Database (SADB).

 

 

Creating a Static Security Association (SA).

 

 

Dynamically Maintaining SAs.

 

 

Summary.

 

20. Broadcasting.

 

Introduction.

 

 

Broadcast Addresses.

 

 

Unicast versus Broadcast.

 

 

dg_cli Function Using Broadcasting.

 

 

Race Conditions.

 

 

Summary.

 

21. Multicasting.

 

Introduction.

 

 

Multicast Addresses.

 

 

Multicasting versus Broadcasting on a LAN.

 

 

Multicasting on a WAN.

 

 

Source-Specific Multicast.

 

 

Multicast Socket Options.

 

 

mcast_join and Related Functions.

 

 

dg_cli Function Using Multicasting.

 

 

Receiving IP Multicast Infrastructure Session Announcements.

 

 

Sending and Receiving.

 

 

Simple Network Time Protocol (SNTP).

 

 

Summary.

 

22. Advanced UDP Sockets.

 

Introduction.

 

 

Receiving Flags, Destination IP Address, and Interface Index.

 

 

Datagram Truncation.

 

 

When to Use UDP Instead of TCP.

 

 

Adding Reliability to a UDP Application.

 

 

Binding Interface Addresses.

 

 

Concurrent UDP Servers.

 

 

IPv6 Packet Information.

 

 

IPv6 Path MTU Control.

 

 

Summary.

 

23. Advanced SCTP Sockets.

 

Introduction.

 

 

An Autoclosing One-to-Many-Style Server.

 

 

Partial Delivery.

 

 

Notifications.

 

 

Unordered Data.

 

 

Binding a Subset of Addresses.

 

 

Determining Peer and Local Address Information.

 

 

Finding an Association ID Given an IP Address.

 

 

Heartbeating and Address Failure.

 

 

Peeling Off an Association.

 

 

Controlling Timing.

 

 

When to Use SCTP Instead of TCP.

 

 

Summary.

 

24. Out-of-Band Data.

 

Introduction.

 

 

TCP Out-of-Band Data.

 

 

sockatmark Function.

 

 

TCP Out-of-Band Data Recap.

 

 

Summary.

 

25. Signal-Driven I/O.

 

Introduction.

 

 

Signal-Driven I/O for Sockets.

 

 

UDP Echo Server Using SIGIO.

 

 

Summary.

 

26. Threads.

 

Introduction.

 

 

Basic Thread Functions: Creation and Termination.

 

 

str_cli Function Using Threads.

 

 

TCP Echo Server Using Threads.

 

 

Thread-Specific Data.

 

 

Web Client and Simultaneous Connections (Continued).

 

 

Mutexes: Mutual Exclusion.

 

 

Condition Variables.

 

 

Web Client and Simultaneous Connections (Continued).

 

 

Summary.

 

27. IP Options.

 

Introduction.

 

 

IPv4 Options.

 

 

IPv4 Source Route Options.

 

 

IPv6 Extension Headers.

 

 

IPv6 Hop-by-Hop Options and Destination Options.

 

 

IPv6 Routing Header.

 

 

IPv6 Sticky Options.

 

 

Historical IPv6 Advanced API.

 

 

Summary.

 

28. Raw Sockets.

 

Introduction.

 

 

Raw Socket Creation.

 

 

Raw Socket Output.

 

 

Raw Socket Input.

 

 

ping Program.

 

 

traceroute Program.

 

 

An ICMP Message Daemon.

 

 

Summary.

 

29. Datalink Access.

 

Introduction.

 

 

BSD Packet Filter (BPF).

 

 

Datalink Provider Interface (DLPI).

 

 

Linux: SOCK_PACKET and PF_PACKET.

 

 

libpcap: Packet Capture Library.

 

 

libnet: Packet Creation and Injection Library.

 

 

Examining the UDP Checksum Field.

 

 

Summary.

 

30. Client/Server Design Alternatives.

 

Introduction.

 

 

TCP Client Alternatives.

 

 

TCP Test Client.

 

 

TCP Iterative Server.

 

 

TCP Concurrent Server, One Child per Client.

 

 

TCP Preforked Server, No Locking Around accept.

 

 

TCP Preforked Server, File Locking Around accept.

 

 

TCP Preforked Server, Thread Locking Around accept.

 

 

TCP Preforked Server, Descriptor Passing.

 

 

TCP Concurrent Server, One Thread per Client.

 

 

TCP Prethreaded Server, per-Thread accept.

 

 

TCP Prethreaded Server, Main Thread accept.

 

 

Summary.

 

31. STREAMS.

 

Introduction.

 

 

Overview.

 

 

getmsg and putmsg Functions.

 

 

getpmsg and putpmsg Functions.

 

 

ioctl Function.

 

 

Transport Provider Interface (TPI).

 

 

Summary.

 

Appendix A. IPv4, IPv6, ICMPv4, and ICMPv6.

 

Introduction.

 

 

IPv4 Header.

 

 

IPv6 Header.

 

 

IPv4 Addresses.

 

 

IPv6 Addresses.

 

 

Internet Control Message Protocols (ICMPv4 and ICMPv6).

 

Appendix B. Virtual Networks.

 

Introduction.

 

 

The MBone.

 

 

The 6bone.

 

 

IPv6 Transition: 6to4.

 

Appendix C. Debugging Techniques.

 

System Call Tracing.

 

 

Standard Internet Services.

 

 

sock Program.

 

 

Small Test Programs.

 

 

tcpdump Program.

 

 

netstat Program.

 

 

lsof Program.

 

Appendix D. Miscellaneous Source Code.

 

unp.h Header.

 

 

config.h Header.

 

 

Standard Error Functions.

 

Appendix E. Solutions to Selected Exercises.
Bibliography.
Index.

商品描述(中文翻譯)

「每個人都會想要這本書,因為它提供了實踐經驗、歷史觀點和深度理解的絕佳結合,這些只有從事該領域的人才能擁有。我已經從閱讀這本書中獲得了樂趣和學習,相信你也會一樣。」
- Sam Leffler

「UNIX網絡API的經典指南...現在完全更新!」
要構建今天高度分佈式、網絡化的應用程序和服務,您需要對套接字和其他關鍵網絡API有深入的掌握。有一本書提供了全面的、從頭到尾的指導,幫助您在任何環境中構建強大、高性能的網絡系統:《UNIX網絡編程,第1卷,第3版》。

在W. Richard Stevens的傳奇工作基礎上,本版已由兩位領先的網絡編程專家全面更新,以應對當今最重要的標準、實現和技術。新的主題包括:

- POSIX單一UNIX規範第3版
- IPv6 API(包括有關IPv6/IPv4互操作性的更新指導)
- 新的SCTP傳輸協議
- 基於IPsec的密鑰管理套接字
- FreeBSD 4.8/5.1、Red Hat Linux 9.x、Solaris 9、AIX 5.x、HP-UX和Mac OS X的實現
- 新的網絡程序調試技術
- 源特定多播API,廣泛部署IP多播的關鍵啟用器

作者還更新並擴展了Stevens對這些關鍵UNIX網絡標準和技術的權威覆蓋範圍:

- TCP和UDP傳輸
- 套接字:基礎、高級、路由和原始
- I/O:多路復用、高級功能、非阻塞和信號驅動
- 守護進程和inetd
- UNIX域協議
- ioctl操作
- 廣播和多播
- 線程
- 流
- 設計:TCP迭代、並發、預分叉和預線程服務器

自1990年以來,網絡程序員一直依賴一個來源來獲取他們所需的見解和技術:W. Richard Stevens的《UNIX網絡編程》。現在,有一個專門為當今和未來挑戰而設計的版本。

目錄:
- 前言
- 前言
- 第一部分:介紹和TCP/IP
- 第二部分:套接字編程基礎
- 第三部分:高級套接字編程
- 第四部分:高級I/O函數
- 第五部分:進程間通信
- 第六部分:高級進程間通信
- 第七部分:網絡IPC
- 第八部分:網絡IPC
- 第九部分:網絡IPC
- 第十部分:網絡IPC
- 第十一部分:網絡IPC
- 第十二部分:網絡IPC
- 第十三部分:網絡IPC
- 第十四部分:網絡IPC
- 第十五部分:網絡IPC
- 第十六部分:網絡IPC
- 第十七部分:網絡IPC
- 第十八部分:網絡IPC
- 第十九部分:網絡IPC
- 第二十部分:網絡IPC
- 第二十一部分:網絡IPC
- 第二十二部分:網絡IPC
- 第二十三部分:網絡IPC
- 第二十四部分:網絡IPC
- 第二十五部分:網絡IPC
- 第二十六部分:網絡IPC
- 第二十七部分:網絡IPC
- 第二十八部分:網絡IPC
- 第二十九部分:網絡IPC
- 第三十部分:網絡IPC
- 第三十一部分:網絡IPC
- 第三十二部分:網絡IPC
- 第三十三部分:網絡IPC
- 第三十四部分:網絡IPC
- 第三十五部分:網絡IPC
- 第三十六部分:網絡IPC
- 第三十七部分:網絡IPC
- 第三十八部分:網絡IPC
- 第三十九部分:網絡IPC
- 第四十部分:網絡IPC
- 第四十一部分:網絡IPC
- 第四十二部分:網絡IPC
- 第四十三部分:網絡IPC
- 第四十四部分:網絡IPC
- 第四十五部分:網絡IPC
- 第四十六部分:網絡IPC
- 第四十七部分:網絡IPC
- 第四十八部分:網絡IPC
- 第四十九部分:網絡IPC
- 第五十部分:網絡IPC
- 第五十一部分:網絡IPC
- 第五十二部分:網絡IPC
- 第五十三部分:網絡IPC
- 第五十四部分:網絡IPC
- 第五十五部分:網絡IPC
- 第五十六部分:網絡IPC
- 第五十七部分:網絡IPC
- 第五十八部分:網絡IPC
- 第五十九部分:網絡IPC
- 第六十部分:網絡IPC
- 第六十一部分:網絡IPC
- 第六十二部分:網絡IPC
- 第六十三部分:網絡IPC
- 第六十四部分:網絡IPC
- 第六十五部分:網絡IPC
- 第六十六部分:網絡IPC
- 第六十七部分:網絡IPC
- 第六十八部分:網絡IPC
- 第六十九部分:網絡IPC
- 第七十部分:網絡IPC
- 第七十一部分:網絡IPC
- 第七十二部分:網絡IPC
- 第七十三部分:網絡IPC
- 第七十四部分:網絡IPC
- 第七十五部分:網絡IPC
- 第七十六部分:網絡IPC
- 第七十七部分:網絡IPC
- 第七十八部分:網絡IPC
- 第七十九部分:網絡IPC
- 第八十部分:網絡IPC
- 第八十一部分:網絡IPC
- 第八十二部分:網絡IPC
- 第八十三部分:網絡IPC
- 第八十四部分:網絡IPC
- 第八十五部分:網絡IPC
- 第八十六部分:網絡IPC
- 第八十七部分:網絡IPC
- 第八十八部分:網絡IPC
- 第八十九部分:網絡IPC
- 第九十部分:網絡IPC
- 第九十一部分:網絡IPC
- 第九十二部分:網絡IPC
- 第九十三部分:網絡IPC
- 第九十四部分:網絡IPC
- 第九十五部分:網絡IPC
- 第九十六部分:網絡IPC
- 第九十七部分:網絡IPC
- 第九十八部分:網絡IPC
- 第九十九部分:網絡IPC
- 第一百部分:網絡IPC
- 第一百零一部分:網絡IPC
- 第一百零二部分:網絡IPC
- 第一百零三部分:網絡IPC
- 第一百零四部分:網絡IPC
- 第一百零五部分:網絡IPC
- 第一百零六部分:網絡IPC
- 第一百零七部分:網絡IPC
- 第一百零八部分:網絡IPC
- 第一百零九部分:網絡IPC
- 第一百一十部分:網絡IPC
- 第一百一十一部分:網絡IPC
- 第一百一十二部分:網絡IPC
- 第一百一十三部分:網絡IPC
- 第一百一十四部分:網絡IPC
- 第一百一十五部分:網絡IPC
- 第一百一十六部分:網絡IPC
- 第一百一十七部分:網絡IPC
- 第一