Chapter
5. Binding Addresses to a Socket
The preceding chapters prepared you with the means to create sockets and to form addresses for them. This chapter will expand upon this, enabling you to understand how bind(2) works and how to apply it correctly.
In this chapter, you will learn
How the bind(2) function call assigns an address to a socket
How to obtain the local socket address from a socket that already has an existing address
How to obtain the peer socket address
How bind(2) can choose the network interface that is used for communication
Chapter 2, "Domains and Address Families," covered addresses in detail. This background will make this chapter easy for you to follow.Having mastered the bind function, you will be able to put sockets to work in the next chapter.