| < Day Day Up > |
|
Although Sockets programming is conceptually simple, improperly using the API or not taking into account protocol behaviors can induce errors within network applications. In this chapter, we investigate some common and not-so-common pitfalls that can be found in common network applications, and then explain how to correct them.
A number of programming pitfalls are discussed in this chapter. Some pitfalls concentrate on improper usage of the BSD API, whereas others explore protocol behavior effects on the API. The common pitfalls that are discussed in this chapter include:
Failing to use function returns
Ignoring peer socket closure
Ignoring endianness of parameters in API functions
Making protocol framing assumptions
Causing “Address in use” error for bind
Listening on multiple interfaces
Initial UDP datagrams disappearing
Defensive programming
Using safe functions to avoid buffer overflow
Rigorously checking error returns
Rigorously checking input and output parameters
Declaring string arrays
Minimizing protocol feedback
Initializing all variables
Enabling all compiler warnings
| < Day Day Up > |
|