您好,欢迎光临本网站![请登录][注册会员]  
文件名称: Linux Socket Programming by Example
  所属分类: 其它
  开发工具:
  文件大小: 3mb
  下载次数: 0
  上传时间: 2011-04-03
  提 供 者: li0524******
 详细说明: TABLE OF CONTENTS Introduction 1 Part 1 Basic Socket Concepts 5 1 Introducing Sockets 7 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 Families 35 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 Page v 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 Protocols 93 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 Type 97 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 Page vi 5 Binding Addresses to a Socket 115 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 Protocols 133 The Methods of Communication 134 Understanding the Advantages 134 Understanding the Disadvantages of Connectionless Communications 135 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 TEAMFLY Team-Fly® 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 Clients 159 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 Page vii 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 Servers 183 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 Lookups 203 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 Page viii Part 2 Advanced Socket Programming 227 10 Using Standard I/O on Sockets 229 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 Servers 269 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 Options 305 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 UDP 329 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 Data 349 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 Page x 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 Daemon 379 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 Programming 393 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 Page xi Testing the Wrapper Program 420 Testing the Server Timeout 421 Uninstalling the Demonstration Programs 422 Datagram Vulnerability 423 17 Passing Credentials and File Descriptors 427 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 TEAMFLY Team-Fly® 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 Project 473 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 Page xii 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 ...展开收缩
(系统自动生成,下载前可以参看下载内容)

下载文件列表

相关说明

  • 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
  • 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度
  • 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
  • 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
  • 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
  • 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.
 相关搜索: Linux Socket Programming by Example
 输入关键字,在本站1000多万海量源码库中尽情搜索: