Chinaunix首页 | 论坛 | 博客
  • 博客访问: 173006
  • 博文数量: 40
  • 博客积分: 1573
  • 博客等级: 上尉
  • 技术积分: 385
  • 用 户 组: 普通用户
  • 注册时间: 2009-08-09 22:50
个人简介

忙得不会思考了!!!!!!

文章分类

全部博文(40)

文章存档

2015年(2)

2014年(1)

2011年(15)

2010年(3)

2009年(19)

我的朋友

分类: LINUX

2009-08-30 08:31:07

CONTENTS AT A GLANCE
Introduction 1
Part 1: Basic Socket Concepts 5
1
Introducing Sockets7
2
Domains and Address Families35
3
Address Conversion Functions65
4
Socket Types and Protocols93
5
Binding Addresses to a Socket115
6
Connectionless-Oriented Protocols133
7
Connection-Oriented Protocols for Clients159
8
Connection-Oriented Protocols for Servers183
9
Hostname and Network Name Lookups203
Part 2: Advanced Socket Programming 227
10
Using Standard I/O on Sockets229
11
Concurrent Client Servers269
12
Socket Options305
13
Broadcasting with UDP329
14
Out-of-Band Data349
15
Using the inetd Daemon379
16
Network Security Programming393
17
Passing Credentials and File Descriptors427
18
A Practical Network Project473
Appendixes 505
A
Socket Function Quick Reference507
B
Socket-Related Structures Reference519
C
Useful Network Tables525
Glossary 529
Index 537

 

TABLE OF CONTENTS
Introduction 1
Part 1
Basic Socket Concepts5
1
Introducing Sockets7
A Brief Historical Introduction 8
Understanding Sockets 9
Defining a Socket 9
Using Sockets 10
Referencing Sockets 11
Comparing Sockets to Pipes 12
Creating Sockets 13
Using socketpair(2) in an Example 14
Running the Demonstration Program 16
Performing I/O on Sockets 17
Closing Sockets 21
The shutdown(2) Function 22
Shutting Down Writing to a Socket 22
Dealing with Duplicated Sockets 23
Shutting Down Reading from a Socket 24
Knowing When Not to Use shutdown(2) 24
Writing a Client/Server Example 24
2
Domains and Address Families35
Nameless Sockets 36
Anonymous Calls 36
Generating Addresses 36
Understanding Domains 36
Forming Socket Addresses 37
Examining the Generic Socket Address 37
Forming Local Addresses 38
Forming Traditional Local Addresses 39
Forming Abstract Local Addresses 44
Forming Internet (IPv4) Socket Addresses 47
Understanding Network Byte Order 49
Performing Endian Conversions 50
Initializing a Wild Internet Address 51
Initializing a Specific Internet Address 52
Specifying an X.25 Address 55
Specifying Other Address Families 58
The AF_UNSPEC Address Family 61
3
Address Conversion Functions
65
Internet IP Numbers 66
Internet Address Classes 66
Understanding Netmask Values 67
Allocating IP Addresses 72
Private IP Numbers 72
Reserved IP Numbers 73
Manipulating IP Numbers 73
Using the inet_addr(3) Function 73
The inet_aton(3) Function 77
Using the inet_ntoa(3) Function 80
Using inet_network(3) 83
Using the inet_lnaof(3) Function 85
Using the inet_netof(3) Function 86
Using the inet_makeaddr(3) Function 87
4
Socket Types and Protocols93
Specifying the Domain of a Socket 94
Choosing PF_INET or AF_INET 94
Using the PF_LOCAL and AF_LOCAL Macros 95
Using the socket(2) Function 96
Choosing a Socket Type 96
Understanding the SOCK_STREAM Socket Type97
Understanding the SOCK_DGRAM Socket Type 99
Understanding the SOCK_SEQPACKET Socket Type 100
Choosing a Protocol 101
Using PF_LOCAL and SOCK_STREAM 102
Using PF_LOCAL and SOCK_DGRAM 103
Using PF_INET and SOCK_STREAM 103
Using PF_INET and SOCK_DGRAM 105
Socket Domain and Type Summary 106
Other Linux-Supported Protocols 107
Researching Other Protocols 109
5
Binding Addresses to a Socket115
The Purpose of the bind(2) Function 116
Using the bind(2) Function 116
Obtaining the Socket Address 120
Writing a sock_addr() Function 121
Obtaining a Peer Socket Address 125
Interfaces and Addressing 128
Specifying an Interface Address Example 128
Binding a Specific Interface Address 129
Binding for Any Interface 130
6
Connectionless-Oriented Protocols133
The Methods of Communication 134
Understanding the Advantages 134
Understanding the Disadvantages of Connectionless Communications135
Performing Input/Output of Datagrams 136
Introducing the sendto(2) Function 136
Introducing the recvfrom(2) Function 138
Writing a UDP Datagram Server 140
Writing a UDP Datagram Client 146
Testing the Datagram Client and Server 150
Testing with No Server 152

Testing with Other IP Numbers 153
Leaving out bind(2) in Client Programs 154
Replying to a Wild Address 154
7
Connection-Oriented Protocols for Clients159
Reviewing the Methods of Communication 160
TCP/IP Handles Lost Packets 160
TCP/IP Handles Duplicated Packets 161
TCP/IP Handles Sequencing 161
TCP/IP Handles Flow Control 161
Understanding the Advantages of TCP/IP 161
Internet Services 162
Examining the /etc/services File 162
Using Function getservent(3) 163
Using the setservent(3) Function 166
Using the endservent(3) Function 167
Looking up a Service by Name and Protocol 167
Looking up a Service by Port and Protocol 168
Consulting the /etc/protocols File 168
Using the setprotoent(3) Function 171
Using the endprotoent(3) Function 172
Looking up a Protocol by Name 172
Looking up a Protocol by Number 172
Writing a TCP/IP Client Program 173
Introducing the connect(2) Function 173
Preparing to Write the Client Program 174
The daytime Client Program 176
Using connect(2) on SOCK_DGRAM Sockets 180
8
Connection-Oriented Protocols for Servers183
Understanding the Role of the Server 184
The listen(2) Function 185
Understanding the Connect Queue 186
Specifying a Value for backlog 187
The accept(2) Function Call 188
Understanding the Role of accept(2) 189
Writing a TCP/IP Server 190
Running a Wild Server 196
Modifying the Client Program 197
9
Hostname and Network Name Lookups203
Understanding the Need for Names 204
Using the uname(2) Function 204
Obtaining Hostnames and Domain Names 207
Using Function gethostname 207
Using the getdomainname(2) Function 208
Testing gethostname(2) and getdomainname(2) 208
Resolving Remote Addresses 210
Error Reporting 210
Reporting an h_errno Error 211
Using the gethostbyname(3) Function 212
Applying the gethostbyname(3) Function 214
The gethostbyaddr(3) Function 217
Using the sethostent(3) Function 223
Using the endhostent(3) Function 224
Part 2
Advanced Socket Programming227
10
Using Standard I/O on Sockets229
Understanding the Need for Standard I/O 230
Associating a Socket with a Stream 230
Using fdopen(3) to Associate a Socket with a Stream 231
Closing a Socket Stream 232
Using Separate Read and Write Streams 233
Duplicating a Socket 234
Closing the Dual Streams 234
Winding up Communications 235
Shutting Down the Write Side Only 235
Shutting Down the Read Side Only 237
Shutting Down Both Read and Write Sides 237
Handling Interrupts 238
Handling EINTR for Other Functions 240
Denning Buffer Operation 240
Applying FILE Streams to Sockets 243
Presenting the mkaddr() Function 243
The RPN Calculator Engine Code 249
Trying out the RPN Server 264
11
Concurrent Client Servers269
Understanding the Multiple-Client Problem 270
Overview of Server Functions 271
Using fork(2) to Service Multiple Clients 275
Understanding the Overall Server Process 280
Understanding the Child Server Process Flow 281
Understanding Process Termination Processing 282
Designing Servers That Use select(2) 282
Introducing the select(2) Function 283
Manipulating File Descriptor Sets 285
Applying select(2) to a Server 287
Testing the select(2) -Based Server 299
Limitations of the Example 301
12
Socket Options305
Getting Socket Options 306
Applying getsockopt(2) 307
Page ix
Setting Socket Options 310
Applying the setsockopt(2) Function 311
Retrieving the Socket Type (SO_TYPE) 315
Setting the SO_REUSEADDR Option 317
Setting the SO_LINGER Option 320
Setting the SO_KEEPALIVE Option 323
Setting the SO_BROADCAST Option 324
Setting the SO_OOBINLINE Option 325
Options SO_PASSCRED and SO_PEERCRED 326
13
Broadcasting with UDP329
Understanding Broadcast Addresses 330
Broadcasting on 255.255.255.255 330
Enhancing the mkaddr.c Subroutine 331
Broadcasting from a Server 332
Receiving Broadcasts 338
Demonstrating the Broadcasts 342
Broadcasting to a Network 343
Starting Broadcasts 343
Receiving Broadcasts 345
Receiving Broadcasts from a Remote Host 345
Troubleshooting Hints 346
14
Out-of-Band Data349
Defining Out-of-Band 350
Understanding the Need for Out-of-Band Data 350
Sockets and Out-of-Band Data 351
Variations in Implementation 351
Using Out-of-Band Data 353
Writing Out-of-Band Data 353
Reading Out-of-Band Data 354
Understanding the Signal SIGURG 355
Supporting Subprograms 356
Receiving with the SIGURG Signal 359
Sending Out-of-Band Data 362
Testing the oobrecv and oobsend Programs 365
Understanding the Urgent Pointer 366
Understanding TCP Urgent Mode 366
Urgent Mode When tcp_stdurg=1 369
Receiving Out-of-Band Data Inline 370
Determining the Urgent Pointer 370
Using Out-of-Band Data Inline 371
Limitations of the Urgent Mode Pointer 375
Processing Out-of-Band Data with select(2) 377
15
Using the inetd Daemon379
Steps Common to Most Servers 380
Introducing inetd 380
The /etc/inetd.conf Configuration File 381
The Design Parameters of inetd Servers 383
Implementing a Simple stream tcp Server 384
Configuring /etc/inetd.conf to Invoke a New Server 385
Disabling the New Service 389
Datagram Servers with inetd 389
Understanding wait and nowait 390
16
Network Security Programming393
Defining Security 394
The Challenges of Security 394
Identifying Friend or Foe 396
Securing by Hostname or Domain Name 396
Identifying by IP Number 397
Securing inetd Servers 398
Centralized Network Policy 399
Understanding the TCP Wrapper Concept 399
Determining Access 401
Installing Wrapper and Server Programs 403
Examining Server and Wrapper Logging Code 403
Examining the Datagram Server Code 405
Examining the Simple TCP Wrapper Program 410
Introducing the Client Program 414
Installing and Testing the Wrapper 418
Monitoring the Log Files 419
Starting Your inetd Daemon 419
Testing the Wrapper Program 420
Testing the Server Timeout 421
Uninstalling the Demonstration Programs 422
Datagram Vulnerability 423
17
Passing Credentials and File Descriptors427
Problem Statement 428
Introducing Ancillary Data 428
Introducing I/O Vectors 429
The I/O Vector (struct iovec) 429
The readv(2) and writev(2) Functions 430
The sendmsg(2) and recvmsg(2) Functions 432
The sendmsg(2) Function 432
The recvmsg(2) Function 433
Understanding struct msghdr 433
Ancillary Data Structures and Macros 435
Introducing struct cmsghdr Structure 435
Introducing the cmsg(3) Macros 437
Iterating through Ancillary Data 439
Creating Ancillary Data 440
Presenting an Ancillary Data Example 441
The Common Header File common.h 442
The misc.c Module 443
The recvcred.c Module 443
The Simple Web Server web80 447
The reqport() Function 451
The recv_fd() Function 453
The sockserv Server Program 456
The send_fd() Function 465
Testing the Socket Server 468
Testing sockserv 469
18
A Practical Network Project473
Problem Statement 474
Solving the Quote Service Problem 474
Obtaining Stock Market Quotes 474
Examining the Quote Server Program 477
Fetching Quotations via get_tickinfo() 484
Broadcasting Quotes via broadcast() 493
Examining the Client Program 495
Compiling and Running the Demonstration 500
Starting the qserve Quotation Server 501
Starting the mktwatch Client 501
If the finance.yahoo.com Service Changes 503
Appendixes 505
A
Socket Function Quick Reference507
Socket-Specific Functions 507
Socket Addressing 508
Reading of Sockets 508
Writing to Sockets 510
Other Socket I/O 511
Controlling Sockets 512
Network Support Functions 513
Standard I/O Support 515
Hostname Support 515
B
Socket-Related Structures Reference519
Socket Address Structures 519
Miscellaneous Structures 521
I/O-Related Structures 522
C
Useful Network Tables525
Glossary 529
Index 537

文件: Linux Socket Programming By example.pdf
大小: 4015KB
下载: 下载
阅读(1656) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~