The following is a list of the 44 example programs included with this book, by chapter.
This chapter includes the following example programs:
win_init.c
: Example code to initialize Winsock (Windows only)win_list.c
: Lists all local IP addresses (Windows only)unix_list.c
: Lists all local IP addresses (Linux and macOS only)
This chapter includes the following example programs:
sock_init.c
: Example program to include all necessary headers and initializetime_console.c
: Prints the current date and time to the consoletime_server.c
: Serves a web page giving the current date and timetime_server_ipv6.c
: The same as the preceding code but listens for IPv6 connectionstime_server_dual.c
: The same as the preceding code but listens for IPv6/IPv4 dual-stack connections
This chapter includes the following example programs:
tcp_client.c
: Establishes a TCP connection and sends/receives data from the console.tcp_serve_toupper.c
: A TCP server servicing multiple connections usingselect()
. Echoes received data back to the client all in uppercase.
tcp_serve_toupper_fork.c
: The same as the preceding code but usesfork()
instead ofselect()
. (Linux and macOS only.)tcp_serve_chat.c
: A TCP server that relays received data to every other connected client.
This chapter includes the following example programs:
udp_client.c
: Sends/receives UDP data from the consoleudp_recvfrom.c
: Usesrecvfrom()
to receive one UDP datagramudp_sendto.c
: Usessendto()
to send one UDP datagramudp_serve_toupper.c
: Listens for UDP data and echoes it back to the sender all in uppercaseudp_serve_toupper_simple.c
: The same as the preceding code but doesn't useselect()
This chapter includes the following example programs:
lookup.c
: Usesgetaddrinfo()
to look up addresses for a given hostnamedns_query.c
: Encodes and sends a UDP DNS query, then listens for and decodes the response
This chapter includes the following example program:
web_get.c
: A minimal HTTP client to download a web resource from a given URL
This chapter includes the following example programs:
web_server.c
: A minimal web server capable of serving a static websiteweb_server2.c
: A minimal web server (no globals)
This chapter includes the following example program:
smtp_send.c
: A simple program to transmit an email
The examples in this chapter use OpenSSL. Be sure to link to the OpenSSL libraries when compiling (-lssl -lcrypto
):
openssl_version.c
: A program to report the installed OpenSSL versionhttps_simple.c
: A minimal program that requests a web page using HTTPShttps_get.c
: The HTTP client of Chapter 6, Building a Simple Web Client, modified to use HTTPStls_client.c
: The TCP client program of Chapter 3, An In-Depth Overview of TCP Connections, modified to use TLStls_get_cert.c
: Prints a certificate from a TLS server
The examples in this chapter use OpenSSL. Be sure to link to the OpenSSL libraries when compiling (-lssl -lcrypto
):
The examples in this chapter use libssh
. Be sure to link to the libssh
libraries when compiling (-lssh
):
ssh_version.c
: A program to report thelibssh
versionssh_connect.c
: A minimal client that establishes an SSH connectionssh_auth.c
: A client that attempts SSH client authentication using a passwordssh_command.c
: A client that executes a single remote command over SSHssh_download.c
: A client that downloads a file over SSH/SCP
This chapter includes the following example programs:
connect_timeout.c
: Shows how to time out aconnect()
call early.connect_blocking.c
: For comparison withconnect_timeout.c
.server_reuse.c
: Demonstrates the use ofSO_REUSEADDR
.server_noreuse.c
: For comparison withserver_reuse.c
.server_crash.c
: This server purposefully writes to a TCP socket after the client disconnects.error_text.c
: Shows how to obtain error code descriptions.big_send.c:
A TCP client that sends lots of data after connecting. Used to show the blocking behavior ofsend()
.server_ignore.c
: A TCP server that accepts connections, then simply ignores them. Used to show the blocking behavior ofsend()
.setsize.c
: Shows the maximum number of socketsselect()
can handle.