|
| 1 | +[](https://travis-ci.org/codeplea/Hands-On-Network-Programming-with-C) |
| 2 | +[](https://ci.appveyor.com/project/codeplea/hands-on-network-programming-with-c) |
| 3 | + |
1 | 4 | # Hands-On-Network-Programming-with-C
|
2 |
| -Hands-On Network Programming with C, published by Packt |
| 5 | + |
| 6 | +This repo contains the code which accompanies the book "Hands-On Network |
| 7 | +Programming with C", written by Lewis Van Winkle. The code is released under |
| 8 | +the MIT license. |
| 9 | + |
| 10 | +Unless otherwise noted, all programs will compile cleanly on Windows, Linux, |
| 11 | +and macOS, and as C or C++. Code is tested with MinGW and Visual Studio on |
| 12 | +Windows, gcc and clang on Linux and macOS. |
| 13 | + |
| 14 | + |
| 15 | +## Chapter 1 |
| 16 | + |
| 17 | +* **[chap01/win_init.c](chap01/win_init.c)** Example code to initialize Winsock. (Windows only) |
| 18 | +* **[chap01/win_list.c](chap01/win_list.c)** List all local IP addresses. (Windows only) |
| 19 | +* **[chap01/unix_list.c](chap01/unix_list.c)** List all local IP addresses. (Linux and macOS only) |
| 20 | + |
| 21 | +## Chapter 2 |
| 22 | + |
| 23 | +* **[chap02/sock_init.c](chap02/sock_init.c)** Example program to include all needed headers and initialize. |
| 24 | +* **[chap02/time_console.c](chap02/time_console.c)** Prints to console the current date and time. |
| 25 | +* **[chap02/time_server.c](chap02/time_server.c)** Serves a web page giving current date and time. |
| 26 | +* **[chap02/time_server_ipv6.c](chap02/time_server_ipv6.c)** As above, but listening for IPv6 connections. |
| 27 | +* **[chap02/time_server_dual.c](chap02/time_server_dual.c)** As above, but listening for IPv6/IPv4 dual stack connections. |
| 28 | + |
| 29 | +## Chapter 3 |
| 30 | + |
| 31 | +* **[chap03/tcp_client.c](chap03/tcp_client.c)** Establish TCP connection and send/receive data from the console. |
| 32 | +* **[chap03/tcp_serve_toupper.c](chap03/tcp_serve_toupper.c)** TCP server servicing multiple connections using `select()`. Echos received data back to client in all upper-case. |
| 33 | +* **[chap03/tcp_serve_toupper_fork.c](chap03/tcp_serve_toupper_fork.c)** As above, but uses `fork()` instead of `select()`. (Linux and macOS only) |
| 34 | +* **[chap03/tcp_serve_chat.c](chap03/tcp_serve_chat.c)** TCP server which relays received data to every other connected client. |
| 35 | + |
| 36 | +## Chapter 4 |
| 37 | + |
| 38 | +* **[chap04/udp_client.c](chap04/udp_client.c)** Send/receive UDP data from the console. |
| 39 | +* **[chap04/udp_recvfrom.c](chap04/udp_recvfrom.c)** Uses `recvfrom()` to receive one UDP packet. |
| 40 | +* **[chap04/udp_sendto.c](chap04/udp_sendto.c)** Uses `sendto()` to send one UDP packet. |
| 41 | +* **[chap04/udp_serve_toupper.c](chap04/udp_serve_toupper.c)** Receives UDP data, and echos it back to the sender in all upper-case. |
| 42 | +* **[chap04/udp_serve_toupper_simple.c](chap04/udp_serve_toupper_simple.c)** As above, but doesn't use `select()`. |
| 43 | + |
| 44 | +## Chapter 5 |
| 45 | + |
| 46 | +* **[chap05/lookup.c](chap05/lookup.c)** Uses `getaddrinfo()` to lookup addresses for a given hostname. |
| 47 | +* **[chap05/dns_query.c](chap05/dns_query.c)** Encodes and sends a DNS query, then decodes the response. |
| 48 | + |
| 49 | +## Chapter 6 |
| 50 | + |
| 51 | +* **[chap06/web_get.c](chap06/web_get.c)** A minimal HTTP client which will download a web resource from a given URL. |
| 52 | + |
| 53 | +## Chapter 7 |
| 54 | + |
| 55 | +* **[chap07/web_server.c](chap07/web_server.c)** A minimal web server. |
| 56 | +* **[chap07/web_server2.c](chap07/web_server2.c)** A minimal web server (no globals). |
| 57 | + |
| 58 | +## Chapter 8 |
| 59 | + |
| 60 | +* **[chap08/smtp_send.c](chap08/smtp_send.c)** A simple email sender. |
| 61 | + |
| 62 | +## Chapter 9 |
| 63 | + |
| 64 | +The examples in this chapter use OpenSSL. Be sure to link against the OpenSSL |
| 65 | +libraries when compiling (`-lssl -lcrypto`). |
| 66 | + |
| 67 | +* **[chap09/openssl_version.c](chap09/openssl_version.c)** A program to report the installed OpenSSL version. |
| 68 | +* **[chap09/https_simple.c](chap09/https_simple.c)** A minimal program that requests a web page using HTTPS. |
| 69 | +* **[chap09/https_get.c](chap09/https_get.c)** The HTTP client of chapter 6 modified to use HTTPS. |
| 70 | +* **[chap09/tls_client.c](chap09/tls_client.c)** The TCP client program of chapter 3 modified to use TLS/SSL. |
| 71 | +* **[chap09/tls_get_cert.c](chap09/tls_get_cert.c)** Prints a certificate from a TLS/SSL server. |
| 72 | + |
| 73 | +## Chapter 10 |
| 74 | + |
| 75 | +The examples in this chapter use OpenSSL. Be sure to link against the OpenSSL |
| 76 | +libraries when compiling (`-lssl -lcrypto`). |
| 77 | + |
| 78 | +* **[chap10/tls_time_server.c](chap10/tls_time_server.c)** The time server of chapter 2 modified to use HTTPS. |
| 79 | +* **[chap10/https_server.c](chap10/https_server.c)** The web server of chapter 7 modified to use HTTPS. |
| 80 | + |
| 81 | +## Chapter 11 |
| 82 | + |
| 83 | +The examples in this chapter use libssh. Be sure to link against the libssh libraries when compiling (`-lssh`). |
| 84 | + |
| 85 | +* **[chap11/ssh_version.c](chap11/ssh_version.c)** A program to report the libssh version. |
| 86 | +* **[chap11/ssh_connect.c](chap11/ssh_connect.c)** A minimal client that establishes a ssh connection. |
| 87 | +* **[chap11/ssh_auth.c](chap11/ssh_auth.c)** A client which attempts authentication. |
| 88 | +* **[chap11/ssh_command.c](chap11/ssh_command.c)** A client that runs a single command over ssh. |
| 89 | +* **[chap11/ssh_download.c](chap11/ssh_download.c)** A client that downloads a file over ssh. |
| 90 | + |
| 91 | + |
| 92 | +## Chapter 12 |
| 93 | + |
| 94 | +This chapter doesn't include any example programs. |
| 95 | + |
| 96 | +## Chapter 13 |
| 97 | + |
| 98 | +* **[chap13/connect_timeout.c](chap13/connect_timeout.c)** Shows how to timeout a `connect()` call early. |
| 99 | +* **[chap13/connect_blocking.c](chap13/connect_blocking.c)** For comparison with **connect_timeout.c**. |
| 100 | +* **[chap13/server_reuse.c](chap13/server_reuse.c)** Demonstrates the use of `SO_REUSEADDR`. |
| 101 | +* **[chap13/server_noreuse.c](chap13/server_noreuse.c)** For comparison with **server_reuse.c**. |
| 102 | +* **[chap13/server_crash.c](chap13/server_crash.c)** This server purposefully writes to a TCP socket after the client disconnects. |
| 103 | +* **[chap13/error_text.c](chap13/error_text.c)** Shows how to obtain error code descriptions. |
| 104 | +* **[chap13/big_send.c](chap13/big_send.c)** TCP client. Sends lots of data after connecting. Used to show blocking behaviour of `send()`. |
| 105 | +* **[chap13/server_ignore.c](chap13/server_ignore.c)** TCP server. Accepts connections, then simply ignores them. Used to show blocking behaviour of `send()`. |
| 106 | +* **[chap13/setsize.c](chap13/setsize.c)** Shows max number of sockets `select()` can handle. |
| 107 | + |
| 108 | +## Chapter 14 |
| 109 | + |
| 110 | +This chapter doesn't include any example programs. |
| 111 | + |
0 commit comments