Apress' The Definitive Guide to Linux Network Programming is a clear, concise treatment of creating clients and servers under the Linux operating system. The book assumes that the reader knows C and has experience developing code on Linux, but provides everything else a programmer needs for real-world network programming, including design, implementation, debugging, and security. Readers will learn about the many kinds of socket types, sessioned vs. sessionless protocols, how to build a custom protocol, encryption, how to use SSL, and how to tunnel data. Prelims......Page 1 Contents at a Glance......Page 7 Contents......Page 9 Introduction......Page 19 Circuits vs. Packets......Page 27 Internetworking......Page 28 Ethernets......Page 30 Ethernet Frames......Page 31 Ethernet Addresses......Page 32 Gateways......Page 34 Internet Addresses......Page 36 Internet Protocol......Page 41 Protocol Layering......Page 44 Protocol Layer Models......Page 46 User Datagram Protocol......Page 49 Transmission Control Protocol......Page 51 The Client-Server Model......Page 55 The Domain Name System......Page 57 Summary......Page 63 What Is a Socket?......Page 65 Using Sockets......Page 67 Socket Constants......Page 68 Address Structure......Page 71 Using Socket Functions......Page 73 Summary......Page 87 User Datagram Protocol......Page 89 UDP Server......Page 90 UDP Client......Page 94 File Transfer......Page 97 The Server......Page 98 The Client......Page 103 Example File Transfer Session......Page 106 Error Handling......Page 107 Summary......Page 108 State vs. Stateless......Page 109 Methods for Maintaining State......Page 111 Storing State on the Server......Page 112 Storing State on the Client......Page 114 Stateless Server Walk-through......Page 117 Stateful Server Walk-through......Page 118 Summary......Page 120 Client Test Program......Page 123 The select() Function......Page 126 A Multiplexing Server......Page 128 Forking......Page 132 One Process Per Client......Page 133 Preforking: Process Pools......Page 138 Multithreading......Page 142 A Multithreaded Server......Page 143 Combining Preforking and Prethreading......Page 152 Nonblocking Sockets......Page 154 Putting It All Together......Page 156 Summary......Page 159 What Is a Protocol?......Page 161 What Will the Message Format Be?......Page 162 Will the Server Be Passive or Active?......Page 163 Will the Protocol Be Sessioned or Sessionless?......Page 164 What About Privacy?......Page 165 Client Commands......Page 166 Server Messages......Page 170 Our Chat Protocol in Action......Page 173 The /etc/services File......Page 174 Service Entry Functions......Page 175 Summary......Page 177 Reliability......Page 179 Overhead......Page 180 Established vs. Custom......Page 181 Two-Tier Architecture......Page 182 Three-Tier Architecture......Page 183 Monolithic Client......Page 185 Server-Side Considerations......Page 186 Daemonizing......Page 187 Logging......Page 189 Privilege Dropping......Page 192 chroot() Jails......Page 195 Summary......Page 196 netstat......Page 197 Ethereal......Page 198 gdb......Page 200 Chicken or the Egg......Page 201 Debug Statements......Page 202 Respect Buffer Limits......Page 203 Expect the Unexpected......Page 205 Fail Gracefully, But Not Silently......Page 206 Summary......Page 207 The Server......Page 209 The Client......Page 225 chatcli.h......Page 227 chatcli.cpp......Page 228 logindlg.h......Page 233 logindlg.cpp......Page 234 chatwin.h......Page 235 chatwin.cpp......Page 236 Makefile......Page 249 Recommendations for Improvements......Page 250 Summary......Page 251 Securing Network Communication......Page 255 Tunneling......Page 256 Tunneling with OpenSSH......Page 257 Tunneling with Stunnel......Page 258 Symmetric Key Cryptography......Page 259 Asymmetric Key Cryptography......Page 260 Certificates......Page 261 OpenSSL Functions and Structures......Page 266 File Descriptor Association......Page 272 BIO Connection Handling......Page 277 Thread-safe Programming with OpenSSL......Page 279 Compiling and Running the Example......Page 283 Summary......Page 284 The Old Scenario......Page 285 The Present-Day Scenario......Page 286 The Conversation Function......Page 287 Creating a PAM-Aware Application......Page 290 Public Key Authentication......Page 292 Using Signed Data for Authentication......Page 293 Single Sign-on......Page 302 Summary......Page 303 Common Attacks......Page 305 Functions to Avoid and Their Alternatives......Page 306 Error Handling......Page 310 Memory Management......Page 312 Worst-Case Scenarios......Page 316 Shared Memory and Variable Scope......Page 317 Random Number Generation......Page 320 Compiler Add-ons......Page 321 Code Analysis Tools......Page 322 Summary......Page 323 Process Method......Page 325 Security Model......Page 326 The Protocol......Page 327 Common Code Library......Page 328 The Client......Page 342 The Server......Page 351 Running the Client and Server......Page 358 Flawfinder Audit......Page 359 Future Improvements and Enhancements......Page 360 Summary......Page 363 IPv6......Page 365 IPv6 Addressing......Page 366 IPv6 and Linux......Page 368 Porting to IPv6......Page 369 IPv6 Server......Page 371 IPv6 Client......Page 374 Address Conversion Functions......Page 376 Future Enhancements......Page 378 Summary......Page 382 Index......Page 385 Chapter 1 Networks And Protocols 3 -- Circuits Vs. Packets 3 -- Internetworking 4 -- Ethernets 6 -- Ethernet Frames 7 -- Addressing 8 -- Internet Protocol 17 -- User Datagram Protocol 25 -- Transmission Control Protocol 27 -- The Client-server Model 31 -- The Domain Name System 33 -- Chapter 2 Functions 41 -- Using Sockets 43 -- Chapter 3 Socket Programming 65 -- User Datagram Protocol 65 -- File Transfer 73 -- Error Handling 83 -- Chapter 4 Protocols, Sessions, And State 85 -- State Vs. Stateless 85 -- Methods For Maintaining State 87 -- Part 2 Design And Architecture 97 -- Chapter 5 Client-server Architecture 99 -- Client Test Program 99 -- Multiplexing 102 -- Forking 108 -- Multithreading 118 -- Combining Preforking And Prethreading 128 -- Which Method Should You Choose? 130 -- Dealing With Large Amounts Of Data 130 -- Chapter 6 Implementing Custom Protocols 137 -- Designing A Custom Protocol 138 -- Our Chat Protocol 142 -- Protocol Registration 150 -- Chapter 7 Design Decisions 155 -- Tcp Vs. Udp 155 -- Application Protocol Choices 157 -- Client-server Architecture 158 -- Client-side Considerations 161 -- Server-side Considerations 162 -- Chapter 8 Debugging And Development Cycle 173 -- Tools 173 -- Chicken Or The Egg 177 -- Debugging 178 -- Defensive Programming 179 -- Chapter 9 Case Study: A Networked Application 185 -- The Server 185 -- The Client 201 -- Recommendations For Improvements 226 -- Part 3 Security 229 -- Chapter 10 Securing Network Communication 231 -- Tunneling 232 -- Public Key Infrastructure 235 -- Secure Network Programming Using Openssl 242 -- Chapter 11 Authentication And Data Signing 261 -- The Old Scenario 261 -- The Present-day Scenario 262 -- The Pam Library 263 -- Public Key Authentication 268 -- Single Sign-on 278 -- Chapter 12 Common Security Problems 281 -- Common Attacks 281 -- Buffer Overflow 282 -- Secure Coding Practices 282 -- Tools Of The Trade 297 -- Chapter 13 Case Study: A Secure Networked Application 301 -- The Necessary Decisions 301 -- Code Design And Layout 303 -- The Code 304 -- Analysis 335 -- Appendix Ipv6 341 -- Ipv6 Addressing 342 -- Ipv6 And Linux 344 -- Porting To Ipv6 345 -- Future Enhancements 354. Keir Davis, John W. Turner, And Nathan Yocom. Includes Index. "The Definitive Guide to Linux Network Programming" offers a clear, concise treatment of creating clients and servers under the Linux operating system. This book assumes that you know C and have experience developing code on Linux, but it provides everything else you'll need as a programmer for real-world network programming. Whether you're a Windows developer looking to expand to Linux, or you're a proficient Linux developer looking to incorporate client-server programming into your applications, this book has a wealth of invaluable information to suit your needs. This book covers design, implementation, debugging, and security. You'll also learn about the many kinds of socket types, sessioned versus sessionless protocols, and encryption, as well as how to build a custom protocol, how to use SSL, and how to tunnel data. Table of Contents Networks and Protocols Functions Socket Programming Protocols, Sessions, and State Client-Server Architecture Implementing Custom Protocols Design Decisions Debugging and Development Cycle Case Study: A Networked Application Securing Network Communication Authentication and Data Signing Common Security Problems Case Study: A Secure Networked Application " A clear, concise treatment of creating clients and servers under the Linux operating system explains how TCP, UDP, and IP work, and shows how to debug networking applications via packet sniffing and deconstruction, using real-world code and plenty of examples. Original. (Advanced)