没有合适的资源?快使用搜索试试~ 我知道了~
Linux Socket Programming by Example - II.pdf
4星 · 超过85%的资源 需积分: 10 97 下载量 196 浏览量
2009-02-25
11:14:28
上传
评论
收藏 1.35MB PDF 举报
温馨提示
试读
365页
Linux Socket Programming by Example 英文第二版,内有大量的实例代码,很好的教程……
资源推荐
资源详情
资源评论
Linux Socket Programming by Example
By WarrenW.Gay
Part I: Basic Socket Concepts
Chapter 1. Introducing Sockets
A Brief Historical Introduction
Understanding Sockets
Comparing Sockets to Pipes
Creating Sockets
Performing I/O on Sockets
Closing Sockets
Writing a Client/Server Example
Chapter 2. Domains and Address Families
Nameless Sockets
Understanding Domains
Forming Socket Addresses
Forming Local Addresses
Forming Internet (IPv4) Socket Addresses
Specifying an X.25 Address
Specifying Other Address Families
The AF_UNSPEC Address Family
Chapter 3. Address Conversion Functions
Internet IP Numbers
Allocating IP Addresses
Manipulating IP Numbers
Chapter 4. Socket Types and Protocols
Specifying the Domain of a Socket
Using the socket(2) Function
Choosing a Socket Type
Choosing a Protocol
Socket Domain and Type Summary
Other Linux-Supported Protocols
Chapter 5. Binding Addresses to a Socket
The Purpose of the bind(2) Function
Using the bind(2) Function
Obtaining the Socket Address
Interfaces and Addressing
Chapter 6. Connectionless-Oriented Protocols
The Methods of Communication
Performing Input/Output of Datagrams
Writing a UDP Datagram Server
Writing a UDP Datagram Client
Testing the Datagram Client and Server
Chapter 7. Connection-Oriented Protocols for Clients
Reviewing the Methods of Communication
Internet Services
Consulting the /etc/protocols File
Writing a TCP/IP Client Program
Using connect(2) on SOCK_DGRAM Sockets
What's Next
Chapter 8. Connection-Oriented Protocols for Servers
Understanding the Role of the Server
The listen(2) Function
The accept(2) Function Call
Writing a TCP/IP Server
Modifying the Client Program
Chapter 9. Hostname and Network Name Lookups
Understanding the Need for Names
Using the uname(2) Function
Obtaining Hostnames and Domain Names
Resolving Remote Addresses
Chapter 10. Using Standard I/O on Sockets
Understanding the Need for Standard I/O
Associating a Socket with a Stream
Closing a Socket Stream
Using Separate Read and Write Streams
Winding Up Communications
Handling Interrupts
Defining Buffer Operation
Applying FILE Streams to Sockets
What's Next
Chapter 11. Concurrent Client Servers
Understanding the Multiple-Client Problem
Overview of Server Functions
Using fork(2) to Service Multiple Clients
Designing Servers That Use select(2)
Applying select(2) to a Server
What's Next
Chapter 12. Socket Options
Getting Socket Options
Setting Socket Options
Retrieving the Socket Type (SO_TYPE)
Setting the SO_REUSEADDR Option
Setting the SO_LINGER Option
Setting the SO_KEEPALIVE Option
Setting the SO_BROADCAST Option
Setting the SO_OOBINLINE Option
Options SO_PASSCRED and SO_PEERCRED
What's Next
Chapter 13. Broadcasting with UDP
Understanding Broadcast Addresses
2
Broadcasting from a Server
Receiving Broadcasts
Demonstrating the Broadcasts
Broadcasting to a Network
What's Next
Chapter 14. Out-of-Band Data
Defining Out-of-Band
Understanding the Need for Out-of-Band Data
Sockets and Out-of-Band Data
Variations in Implementation
Using Out-of-Band Data
Understanding the Urgent Pointer
Receiving Out-of-Band Data Inline
Limitations of the Urgent Mode Pointer
What's Next
Chapter 15. Using the inetd Daemon
Steps Common to Most Servers
Introducing inetd
Implementing a Simple stream tcp Server
Datagram Servers with inetd
What's Next
Chapter 16. Network Security Programming
Defining Security
The Challenges of Security
Identifying Friend or Foe
Securing inetd Servers
Installing Wrapper and Server Programs
Introducing the Client Program
Installing and Testing the Wrapper
What's Next
Chapter 17. Passing Credentials and File Descriptors
Problem Statement
Introducing Ancillary Data
Introducing I/O Vectors
The sendmsg(2) and recvmsg(2) Functions
Ancillary Data Structures and Macros
Presenting an Ancillary Data Example
Testing the Socket Server
What's Next
Chapter 18. A Practical Network Project
Problem Statement
Solving the Quote Service Problem
Examining the Quote Server Program
Fetching Quotations via get_tickinfo()
Broadcasting Quotes via broadcast()
Examining the Client Program
Compiling and Running the Demonstration
What's Next
Appendixes
Appendix A. Socket Function Quick Reference
3
Socket-Specific Functions
Socket Addressing
Reading of Sockets
Writing to Sockets
Other Socket I/O
Controlling Sockets
Network Support Functions
Standard I/O Support
Hostname Support
Appendix B. Socket-Related Structures Reference
Socket Address Structures
Miscellaneous Structures
I/O-Related Structures
Appendix C. Useful Network Tables
Glossary
Chapter 1. Introducing Sockets
Friday, October 4, 1957, marked the beginning of a startling new era. The Soviet Union had launched
the world's first artificial satellite into the Earth's orbit, known as Sputnik. Approximately the size of a
basketball, this satellite took 98 minutes to orbit the Earth. Anyone with a shortwave radio was able
to hear it during overhead passes, at a frequency of approximately 40.002Mhz. Who would have
imagined at that time, that this would later spawn the beginnings of TCP/IP and the Internet?
In this chapter you will be introduced to
•
A brief history of how sockets were developed
•
The essence of sockets
•
How sockets are referenced by the Linux kernel and application programs
•
An introductory example of a socket C program
A Brief Historical Introduction
Eisenhower's response to the Sputnik threat was to approach Congress on January 7, 1958, for the
startup funds necessary for the Advanced Research Projects Agency (ARPA). At that time,
government agencies were required to buy computers from different manufacturers each time they
made a purchase, to maintain fairness. The new ARPA organization soon found that they had a
collection of machines that spoke completely different languages. Sometime after 1962, J. C. R.
Licklider conceived of the idea that computers should be able to communicate with one another, even
if they were "highly individualistic."
During the 1960s, the ARPAnet was being conceived and developed by a number of talented people.
The humble beginning of the ARPAnet was to become the Internet that we know of today. Eventually
ARPA was folded into the Defense Advanced Research Projects Agency (DARPA).
4
Overlapping with the development of ARPAnet, UNIX development was beginning in 1969. The
University of California, Berkeley (UCB) later developed their own flavor of UNIX, which was known as
BSD. DARPA wanted to divest itself of the business of networking, and so DARPA provided funding to
UCB in 1979, to further develop the ARPAnet. In 1982, 4.1BSD and 4.2BSD versions of UNIX were
released by UCB that included a TCP/IP network implementation. The network socket concepts and
interfaces that you will learn about in this book are based upon the work done by UCB.
Linux draws upon this rich heritage, and so you'll learn about the Linux specific implementation of the
BSD socket interface in this book. Figure 1.1 is provided as a time line overview of the history behind
the socket interface.
Figure 1.1. According to the time line, BSD sockets were developed
24 years after the formation of ARPA.
Understanding Sockets
It is important that you have an understanding of some of the concepts behind the socket interface
before you try to apply them. This section outlines some of the high level concepts surrounding the
sockets themselves.
Defining a Socket
To communicate with someone using a telephone, you must pick up the handset, dial the other
party's telephone number, and wait for them to answer. While you speak to that other party, there
are two endpoints of communication established:
•
Your telephone, at your location
•
The remote party's telephone, at his location
As long as both of you communicate, there are two endpoints involved, with a line of communication
in between them. Figure 1.2 shows an illustration of two telephones as endpoints, each connected to
the other, through the telephone network.
Figure 1.2. Without the telephone network, each endpoint of a
telephone line is nothing more than a plastic box.
5
剩余364页未读,继续阅读
资源评论
- Gauchyler2015-01-09学习Linux Socket编程的好资料,谢谢!
wudale
- 粉丝: 0
- 资源: 17
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功