Log In
Or create an account ->
Imperial Library
Home
About
News
Upload
Forum
Help
Login/SignUp
Index
Title Page
Copyright and Credits
Hands-On Network Programming with C
Dedication
About Packt
Why subscribe?
Packt.com
Contributors
About the author
About the reviewer
Packt is searching for authors like you
Preface
Who this book is for
What this book covers
To get the most out of this book
Download the example code files
Download the color images
Conventions used
Get in touch
Reviews
Section 1 - Getting Started with Network Programming
Introducing Networks and Protocols
Technical requirements
The internet and C
OSI layer model
TCP/IP layer model
Data encapsulation
Internet Protocol
What is an address?
Domain names
Internet routing
Local networks and address translation
Subnetting and CIDR
Multicast, broadcast, and anycast
Port numbers
Clients and servers
Putting it together
What's your address?
Listing network adapters from C
Listing network adapters on Windows
Listing network adapters on Linux and macOS
Summary
Questions
Getting to Grips with Socket APIs
Technical requirements
What are sockets?
Socket setup
Two types of sockets
Socket functions
Anatomy of a socket program
TCP program flow
UDP program flow
Berkeley sockets versus Winsock sockets
Header files
Socket data type
Invalid sockets
Closing sockets
Error handling
Our first program
A motivating example
Making it networked
Working with IPv6
Supporting both IPv4 and IPv6
Networking with inetd
Summary
Questions
An In-Depth Overview of TCP Connections
Technical requirements
Multiplexing TCP connections
Polling non-blocking sockets
Forking and multithreading
The select() function
Synchronous multiplexing with select()
select() timeout
Iterating through an fd_set
select() on non-sockets
A TCP client
TCP client code
A TCP server
TCP server code
Building a chat room
Blocking on send()
TCP is a stream protocol
Summary
Questions
Establishing UDP Connections
Technical requirements
How UDP sockets differ
UDP client methods
UDP server methods
A first UDP client/server
A simple UDP server
A simple UDP client
A UDP server
Summary
Questions
Hostname Resolution and DNS
Technical requirements
How hostname resolution works
DNS record types
DNS security
Name/address translation functions
Using getaddrinfo()
Using getnameinfo()
Alternative functions
IP lookup example program
The DNS protocol
DNS message format
DNS message header format
Question format
Answer format
Endianness
A simple DNS query
A DNS query program
Printing a DNS message name
Printing a DNS message
Sending the query
Summary
Questions
Further reading
Section 2 - An Overview of Application Layer Protocols
Building a Simple Web Client
Technical requirements
The HTTP protocol
HTTP request types
HTTP request format
HTTP response format
HTTP response codes
Response body length
What's in a URL
Parsing a URL
Implementing a web client
HTTP POST requests
Encoding form data
File uploads
Summary
Questions
Further reading
Building a Simple Web Server
Technical requirements
The HTTP server
The server architecture
Content types
Returning Content-Type from a filename
Creating the server socket
Multiple connections buffering
get_client()
drop_client()
get_client_address()
wait_on_clients()
send_400()
send_404()
serve_resource()
The main loop
Security and robustness
Open source servers
Summary
Questions
Further reading
Making Your Program Send Email
Technical requirements
Email servers
SMTP security
Finding an email server
SMTP dialog
The format of an email
A simple SMTP client program
Enhanced emails
Email file attachments
Spam-blocking pitfalls
Summary
Questions
Further reading
Section 3 - Understanding Encrypted Protocols and OpenSSL
Loading Secure Web Pages with HTTPS and OpenSSL
Technical requirements
HTTPS overview
Encryption basics
Symmetric ciphers
Asymmetric ciphers
How TLS uses ciphers
The TLS protocol
Certificates
Server name identification
OpenSSL
Encrypted sockets with OpenSSL
Certificates
A simple HTTPS client
Other examples
Summary
Questions
Further reading
Implementing a Secure Web Server
Technical requirements
HTTPS and OpenSSL summary
Certificates
Self-signed certificates with OpenSSL
HTTPS server with OpenSSL
Time server example
A full HTTPS server
HTTPS server challenges
OpenSSL alternatives
Alternatives to TLS
Summary
Questions
Further reading
Establishing SSH Connections with libssh
Technical requirements
The SSH protocol
libssh
Testing out libssh
Establishing a connection
SSH authentication
Server authentication
Client authentication
Executing a remote command
Downloading a file
Summary
Questions
Further reading
Section 4 - Odds and Ends
Network Monitoring and Security
Technical requirements
The purpose of network monitoring
Testing reachability
Checking a route
How traceroute works
Raw sockets
Checking local connections
Snooping on connections
Deep packet inspection
Capturing all network traffic
Network security
Application security and safety
Network-testing etiquette
Summary
Questions
Further reading
Socket Programming Tips and Pitfalls
Technical requirements
Error handling
Obtaining error descriptions
TCP socket tips
Timeout on connect()
TCP flow control and avoiding deadlock
Congestion control
The Nagle algorithm
Delayed acknowledgment
Connection tear-down
The shutdown() function
Preventing address-in-use errors
Sending to a disconnected peer
Socket's local address
Multiplexing with a large number of sockets
Summary
Questions
Web Programming for the Internet of Things
Technical requirements
What is the IoT?
Connectivity options
Wi-Fi
Ethernet
Cellular
Bluetooth
IEEE 802.15.4 WPANs
Hardware choices
Single-board computers
Microcontrollers
FPGAs
External transceivers and modems
IoT protocols
Firmware updates
Ethics of IoT
Privacy and data collection
End-of-life planning
Security
Summary
Questions
Answers to Questions
Chapter 1, Introducing Networks and Protocols
Chapter 2, Getting to Grips with Socket APIs
Chapter 3, An In-Depth Overview of TCP Connections
Chapter 4, Establishing UDP Connections
Chapter 5, Hostname Resolution and DNS
Chapter 6, Building a Simple Web Client
Chapter 7, Building a Simple Web Server
Chapter 8, Making Your Program Send Email
Chapter 9, Loading Secure Web Pages with HTTPS and OpenSSL
Chapter 10, Implementing a Secure Web Server
Chapter 11, Establishing SSH Connections with libssh
Chapter 12, Network Monitoring and Security
Chapter 13, Socket Programming Tips and Pitfalls
Chapter 14, Web Programming for the Internet of Things
Setting Up Your C Compiler on Windows
Installing MinGW GCC
Installing Git
Installing OpenSSL
Installing libssh
Alternatives
Setting Up Your C Compiler on Linux
Installing GCC
Installing Git
Installing OpenSSL
Installing libssh
Setting Up Your C Compiler on macOS
Installing Homebrew and the C compiler
Installing OpenSSL
Installing libssh
Example Programs
Code license
Code included with this book
Chapter 1 – Introducing Networks and Protocols
Chapter 2 – Getting to Grips with Socket APIs
Chapter 3 – An In-Depth Overview of TCP Connections
Chapter 4 – Establishing UDP Connections
Chapter 5 – Hostname Resolution and DNS
Chapter 6 – Building a Simple Web Client
Chapter 7 – Building a Simple Web Server
Chapter 8 – Making Your Program Send Email
Chapter 9 – Loading Secure Web Pages with HTTPS and OpenSSL
Chapter 10 – Implementing a Secure Web Server
Chapter 11 – Establishing SSH Connections with libssh
Chapter 12 – Network Monitoring and Security
Chapter 13 – Socket Programming Tips and Pitfalls
Chapter 14 – Web Programming for the Internet of Things
Other Book You May Enjoy
Leave a review - let other readers know what you think
← Prev
Back
Next →
← Prev
Back
Next →