The classic guide to UNIX networking APIs — completely updated!
° Previous editions sold over 160,000 units! Second Edition (1998) sold over 53,000 in retail alone!
° Updates coverage of programming standards, debugging techniques, and covers Operating Systems including Red Hat 9, Solaris 9, HP-UX, Free BSD 4.8/5.0, AIX 5.x, and Mac OS X.
° Bill Fenner (AT/T Labs) and Andrew Rudoff (SUN) carry on the tradition of this great work.
Author(s): W. Richard Stevens, Bill Fenner, Andrew M. Rudoff
Series: Addison-Wesley Professional Computing Series
Edition: 3rd
Publisher: Addison-Wesley Professional
Year: 2003
Language: English
Pages: 1021
Copyright......Page 2
Addison-Wesley Professional Computing Series......Page 3
Foreword......Page 18
Introduction......Page 20
Changes from the Second Edition......Page 21
Using This Book......Page 22
Acknowledgments......Page 23
Introduction and TCP/IP......Page 25
Introduction......Page 27
A Simple Daytime Client......Page 30
Protocol Independence......Page 34
Error Handling: Wrapper Functions......Page 35
A Simple Daytime Server......Page 37
Roadmap to Client/Server Examples in the Text......Page 40
OSI Model......Page 42
BSD Networking History......Page 44
Test Networks and Hosts......Page 46
Unix Standards......Page 49
64-Bit Architectures......Page 52
Summary......Page 53
Exercises......Page 54
Introduction......Page 55
The Big Picture......Page 56
User Datagram Protocol (UDP)......Page 58
Transmission Control Protocol (TCP)......Page 59
Stream Control Transmission Protocol (SCTP)......Page 60
TCP Connection Establishment and Termination......Page 61
TIME_WAIT State......Page 67
SCTP Association Establishment and Termination......Page 68
Port Numbers......Page 74
TCP Port Numbers and Concurrent Servers......Page 76
Buffer Sizes and Limitations......Page 79
Standard Internet Services......Page 85
Protocol Usage by Common Internet Applications......Page 86
Exercises......Page 87
Elementary Sockets......Page 89
Socket Address Structures......Page 91
Value-Result Arguments......Page 98
Byte Ordering Functions......Page 101
Byte Manipulation Functions......Page 104
inet_aton, inet_addr, and inet_ntoa Functions......Page 106
inet_pton and inet_ntop Functions......Page 107
sock_ntop and Related Functions......Page 110
readn, writen, and readline Functions......Page 112
Summary......Page 116
Exercises......Page 117
socket Function......Page 119
connect Function......Page 123
bind Function......Page 125
listen Function......Page 128
accept Function......Page 133
fork and exec Functions......Page 135
Concurrent Servers......Page 138
getsockname and getpeername Functions......Page 141
Exercises......Page 144
Introduction......Page 145
TCP Echo Server: main Function......Page 146
TCP Echo Server: str_echo Function......Page 147
TCP Echo Client: main Function......Page 148
TCP Echo Client: str_cli Function......Page 149
Normal Startup......Page 150
Normal Termination......Page 152
POSIX Signal Handling......Page 153
Handling SIGCHLD Signals......Page 156
wait and waitpid Functions......Page 159
Connection Abort before accept Returns......Page 163
Termination of Server Process......Page 165
SIGPIPE Signal......Page 166
Crashing and Rebooting of Server Host......Page 168
Shutdown of Server Host......Page 169
Summary of TCP Example......Page 170
Data Format......Page 171
Exercises......Page 175
Introduction......Page 177
I/O Models......Page 178
select Function......Page 184
str_cli Function (Revisited)......Page 191
Batch Input and Buffering......Page 193
shutdown Function......Page 196
str_cli Function (Revisited Again)......Page 197
TCP Echo Server (Revisited)......Page 199
pselect Function......Page 205
poll Function......Page 206
TCP Echo Server (Revisited Again)......Page 209
Summary......Page 212
Exercises......Page 213
Introduction......Page 215
getsockopt and setsockopt Functions......Page 216
Checking if an Option Is Supported and Obtaining the Default......Page 218
Generic Socket Options......Page 222
IPv4 Socket Options......Page 238
IPv6 Socket Options......Page 240
TCP Socket Options......Page 243
SCTP Socket Options......Page 246
fcntl Function......Page 257
Summary......Page 260
Exercises......Page 261
Introduction......Page 263
recvfrom and sendto Functions......Page 264
UDP Echo Server: main Function......Page 265
UDP Echo Server: dg_echo Function......Page 266
UDP Echo Client: main Function......Page 268
Lost Datagrams......Page 269
Verifying Received Response......Page 270
Server Not Running......Page 272
Summary of UDP Example......Page 274
connect Function with UDP......Page 276
dg_cli Function (Revisited)......Page 280
Lack of Flow Control with UDP......Page 281
Determining Outgoing Interface with UDP......Page 285
TCP and UDP Echo Server Using select......Page 286
Summary......Page 288
Exercises......Page 289
Introduction......Page 291
Interface Models......Page 292
sctp_bindx Function......Page 296
sctp_connectx Function......Page 298
sctp_getladdrs Function......Page 299
sctp_sendmsg Function......Page 300
sctp_recvmsg Function......Page 301
shutdown Function......Page 302
Notifications......Page 304
Exercises......Page 310
Introduction......Page 311
SCTP One-to-Many-Style Streaming Echo Server: main Function......Page 312
SCTP One-to-Many-Style Streaming Echo Client: main Function......Page 314
SCTP Streaming Echo Client: str_cli Function......Page 316
Exploring Head-of-Line Blocking......Page 317
Controlling the Number of Streams......Page 323
Controlling Termination......Page 324
Summary......Page 325
Exercises......Page 326
Domain Name System (DNS)......Page 327
gethostbyname Function......Page 331
gethostbyaddr Function......Page 334
getservbyname and getservbyport Functions......Page 335
getaddrinfo Function......Page 339
gai_strerror Function......Page 344
freeaddrinfo Function......Page 345
getaddrinfo Function: IPv6......Page 346
getaddrinfo Function: Examples......Page 348
host_serv Function......Page 349
tcp_connect Function......Page 350
tcp_listen Function......Page 354
udp_client Function......Page 358
udp_connect Function......Page 361
udp_server Function......Page 362
getnameinfo Function......Page 364
Re-entrant Functions......Page 365
gethostbyname_r and gethostbyaddr_r Functions......Page 368
Obsolete IPv6 Address Lookup Functions......Page 370
Other Networking Information......Page 372
Exercises......Page 373
Advanced Sockets......Page 375
Introduction......Page 377
IPv4 Client, IPv6 Server......Page 378
IPv6 Client, IPv4 Server......Page 381
IPv6 Address-Testing Macros......Page 384
Source Code Portability......Page 385
Exercises......Page 386
Introduction......Page 387
syslogd Daemon......Page 388
syslog Function......Page 389
daemon_init Function......Page 391
inetd Daemon......Page 395
daemon_inetd Function......Page 401
Summary......Page 403
Exercises......Page 404
Socket Timeouts......Page 405
recv and send Functions......Page 411
readv and writev Functions......Page 413
recvmsg and sendmsg Functions......Page 414
Ancillary Data......Page 419
How Much Data Is Queued?......Page 422
Sockets and Standard I/O......Page 423
Advanced Polling......Page 426
Summary......Page 432
Exercises......Page 433
Introduction......Page 435
Unix Domain Socket Address Structure......Page 436
socketpair Function......Page 438
Socket Functions......Page 439
Unix Domain Stream Client/Server......Page 440
Unix Domain Datagram Client/Server......Page 442
Passing Descriptors......Page 444
Receiving Sender Credentials......Page 453
Exercises......Page 456
Introduction......Page 459
Nonblocking Reads and Writes: str_cli Function (Revisited)......Page 461
Nonblocking connect......Page 472
Nonblocking connect: Daytime Client......Page 473
Nonblocking connect: Web Client......Page 476
Nonblocking accept......Page 485
Summary......Page 487
Exercises......Page 488
Introduction......Page 489
Socket Operations......Page 490
Interface Configuration......Page 492
get_ifi_info Function......Page 493
Interface Operations......Page 504
ARP Cache Operations......Page 505
Routing Table Operations......Page 507
Exercises......Page 508
Introduction......Page 509
Datalink Socket Address Structure......Page 510
Reading and Writing......Page 511
sysctl Operations......Page 519
get_ifi_info Function (Revisited)......Page 524
Interface Name and Index Functions......Page 528
Summary......Page 532
Exercises......Page 533
Introduction......Page 535
Reading and Writing......Page 536
Dumping the Security Association Database (SADB)......Page 538
Creating a Static Security Association (SA)......Page 541
Dynamically Maintaining SAs......Page 548
Exercises......Page 552
Introduction......Page 553
Broadcast Addresses......Page 555
Unicast versus Broadcast......Page 556
dg_cli Function Using Broadcasting......Page 559
Race Conditions......Page 562
Exercises......Page 571
Multicast Addresses......Page 573
Multicasting versus Broadcasting on a LAN......Page 577
Multicasting on a WAN......Page 580
Source-Specific Multicast......Page 582
Multicast Socket Options......Page 583
mcast_join and Related Functions......Page 589
dg_cli Function Using Multicasting......Page 594
Receiving IP Multicast Infrastructure Session Announcements......Page 595
Sending and Receiving......Page 599
Simple Network Time Protocol (SNTP)......Page 603
Summary......Page 608
Exercises......Page 609
Introduction......Page 611
Receiving Flags, Destination IP Address, and Interface Index......Page 612
When to Use UDP Instead of TCP......Page 618
Adding Reliability to a UDP Application......Page 621
Binding Interface Addresses......Page 632
Concurrent UDP Servers......Page 636
IPv6 Packet Information......Page 639
IPv6 Path MTU Control......Page 642
Exercises......Page 644
An Autoclosing One-to-Many-Style Server......Page 645
Partial Delivery......Page 646
Notifications......Page 649
Unordered Data......Page 653
Binding a Subset of Addresses......Page 654
Determining Peer and Local Address Information......Page 655
Finding an Association ID Given an IP Address......Page 659
Heartbeating and Address Failure......Page 660
Peeling Off an Association......Page 661
Controlling Timing......Page 663
When to Use SCTP Instead of TCP......Page 665
Exercises......Page 667
TCP Out-of-Band Data......Page 669
sockatmark Function......Page 678
TCP Out-of-Band Data Recap......Page 685
Exercises......Page 686
Introduction......Page 687
Signal-Driven I/O for Sockets......Page 688
UDP Echo Server Using SIGIO......Page 690
Summary......Page 696
Exercises......Page 697
Introduction......Page 699
Basic Thread Functions: Creation and Termination......Page 700
str_cli Function Using Threads......Page 703
TCP Echo Server Using Threads......Page 705
Thread-Specific Data......Page 710
Web Client and Simultaneous Connections (Continued)......Page 718
Mutexes: Mutual Exclusion......Page 721
Condition Variables......Page 725
Web Client and Simultaneous Connections (Continued)......Page 729
Exercises......Page 731
IPv4 Options......Page 733
IPv4 Source Route Options......Page 735
IPv6 Hop-by-Hop Options and Destination Options......Page 743
IPv6 Routing Header......Page 749
IPv6 Sticky Options......Page 755
Historical IPv6 Advanced API......Page 756
Exercises......Page 757
Introduction......Page 759
Raw Socket Creation......Page 760
Raw Socket Output......Page 761
Raw Socket Input......Page 763
ping Program......Page 765
traceroute Program......Page 779
An ICMP Message Daemon......Page 793
Exercises......Page 810
Introduction......Page 811
BSD Packet Filter (BPF)......Page 812
Datalink Provider Interface (DLPI)......Page 814
Linux: SOCK_PACKET and PF_PACKET......Page 815
libpcap: Packet Capture Library......Page 816
Examining the UDP Checksum Field......Page 817
Exercises......Page 839
Introduction......Page 841
TCP Client Alternatives......Page 843
TCP Test Client......Page 844
TCP Iterative Server......Page 845
TCP Concurrent Server, One Child per Client......Page 846
TCP Preforked Server, No Locking Around accept......Page 850
TCP Preforked Server, File Locking Around accept......Page 856
TCP Preforked Server, Thread Locking Around accept......Page 859
TCP Preforked Server, Descriptor Passing......Page 860
TCP Concurrent Server, One Thread per Client......Page 866
TCP Prethreaded Server, per-Thread accept......Page 868
TCP Prethreaded Server, Main Thread accept......Page 870
Summary......Page 873
Exercises......Page 874
Overview......Page 875
getmsg and putmsg Functions......Page 880
ioctl Function......Page 881
Transport Provider Interface (TPI)......Page 882
Exercises......Page 892
IPv4 Header......Page 893
IPv6 Header......Page 895
IPv4 Addresses......Page 898
IPv6 Addresses......Page 901
Internet Control Message Protocols (ICMPv4 and ICMPv6)......Page 906
The MBone......Page 909
The 6bone......Page 911
IPv6 Transition: 6to4......Page 913
System Call Tracing......Page 915
sock Program......Page 917
netstat Program......Page 920
lsof Program......Page 921
unp.h Header......Page 923
config.h Header......Page 928
Standard Error Functions......Page 934
Chapter 1......Page 937
Chapter 2......Page 938
Chapter 5......Page 939
Chapter 6......Page 943
Chapter 7......Page 944
Chapter 8......Page 948
Chapter 9......Page 950
Chapter 10......Page 951
Chapter 11......Page 952
Chapter 12......Page 957
Chapter 13......Page 958
Chapter 15......Page 959
Chapter 16......Page 962
Chapter 21......Page 963
Chapter 22......Page 965
Chapter 24......Page 967
Chapter 26......Page 968
Chapter 28......Page 969
Chapter 31......Page 970
Bibliography......Page 971