{"id":19787455,"url":"https://github.com/codeplea/hands-on-network-programming-with-c","last_synced_at":"2025-04-13T07:49:43.417Z","repository":{"id":39662653,"uuid":"183856462","full_name":"codeplea/Hands-On-Network-Programming-with-C","owner":"codeplea","description":"Book Example Code for Hands-On Network Programming with C","archived":false,"fork":false,"pushed_at":"2024-01-16T16:09:17.000Z","size":62,"stargazers_count":608,"open_issues_count":10,"forks_count":166,"subscribers_count":21,"default_branch":"master","last_synced_at":"2025-04-04T05:42:10.487Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://handsonnetworkprogramming.com/","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/codeplea.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-04-28T04:42:36.000Z","updated_at":"2025-04-02T02:28:55.000Z","dependencies_parsed_at":"2024-11-12T06:35:14.706Z","dependency_job_id":null,"html_url":"https://github.com/codeplea/Hands-On-Network-Programming-with-C","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeplea%2FHands-On-Network-Programming-with-C","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeplea%2FHands-On-Network-Programming-with-C/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeplea%2FHands-On-Network-Programming-with-C/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeplea%2FHands-On-Network-Programming-with-C/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codeplea","download_url":"https://codeload.github.com/codeplea/Hands-On-Network-Programming-with-C/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248681494,"owners_count":21144700,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-12T06:23:11.131Z","updated_at":"2025-04-13T07:49:43.382Z","avatar_url":"https://github.com/codeplea.png","language":"C","readme":"# Hands-On Network Programming with C\n\n\u003ca href=\"https://www.amazon.com/exec/obidos/ASIN/1789349869/aoeu-20\"\u003e\u003cimg src=\"https://handsonnetworkprogramming.com/processed_images/d68715e4b29b3b9f00.png\" alt=\"Hands-On Network Programming with C\" height=\"256px\" align=\"right\"\u003e\u003c/a\u003e\n\nThis is the code repository for [Hands-On Network Programming with C](https://www.amazon.com/exec/obidos/ASIN/1789349869/aoeu-20), written by Lewis Van Winkle and published by Packt.\n\n**Learn socket programming in C and write secure and optimized network code**\n\n## What is this book about?\nNetwork programming, a challenging topic in C, is made easy to understand with a careful exposition of socket programming APIs. This book gets you started with modern network programming in C and proper usage of the relevant operating system APIs.\n\nThis book covers the following exciting features:\n-\tUncover cross-platform socket programming APIs\n-\tImplement techniques   for supporting IPv4 and IPv6\n-\tUnderstand how TCP and UDP connections work over IP\n-\tDiscover how hostname resolution and   DNS work\n-\tInterface with web APIs using HTTP and HTTPS\n-\tAcquire hands-on experience with the email protocol (SMTP)\n-\tGain real-world expertise with practical network applications  \n-\tExplore new approaches for   the Internet of Things (IoT)\n\n\nIf you feel this book is for you, get your [copy](https://www.amazon.com/exec/obidos/ASIN/1789349869/aoeu-20) today!\n\n## Instructions and Navigations\n\n[![Build Status](https://travis-ci.org/codeplea/Hands-On-Network-Programming-with-C.svg?branch=master)](https://travis-ci.org/codeplea/Hands-On-Network-Programming-with-C)\n[![Build status](https://ci.appveyor.com/api/projects/status/yarb3kmmn5db21vn?svg=true)](https://ci.appveyor.com/project/codeplea/hands-on-network-programming-with-c)\n\nThis repo contains the code which accompanies the book \"Hands-On Network\nProgramming with C\", written by Lewis Van Winkle. The code is released under\nthe MIT license.\n\nUnless otherwise noted, all programs will compile cleanly on Windows, Linux,\nand macOS, and as C or C++. Code is tested with MinGW and Visual Studio on\nWindows, gcc and clang on Linux and macOS.\n\n\n## Chapter 1\n\n* **[chap01/win_init.c](chap01/win_init.c)** Example code to initialize Winsock. (Windows only)\n* **[chap01/win_list.c](chap01/win_list.c)** List all local IP addresses. (Windows only)\n* **[chap01/unix_list.c](chap01/unix_list.c)** List all local IP addresses. (Linux and macOS only)\n\n## Chapter 2\n\n* **[chap02/sock_init.c](chap02/sock_init.c)** Example program to include all needed headers and initialize.\n* **[chap02/time_console.c](chap02/time_console.c)** Prints to console the current date and time.\n* **[chap02/time_server.c](chap02/time_server.c)** Serves a web page giving current date and time.\n* **[chap02/time_server_ipv6.c](chap02/time_server_ipv6.c)** As above, but listening for IPv6 connections.\n* **[chap02/time_server_dual.c](chap02/time_server_dual.c)** As above, but listening for IPv6/IPv4 dual stack connections.\n\n## Chapter 3\n\n* **[chap03/tcp_client.c](chap03/tcp_client.c)** Establish TCP connection and send/receive data from the console.\n* **[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.\n* **[chap03/tcp_serve_toupper_fork.c](chap03/tcp_serve_toupper_fork.c)** As above, but uses `fork()` instead of `select()`. (Linux and macOS only)\n* **[chap03/tcp_serve_chat.c](chap03/tcp_serve_chat.c)** TCP server which relays received data to every other connected client.\n\n## Chapter 4\n\n* **[chap04/udp_client.c](chap04/udp_client.c)** Send/receive UDP data from the console.\n* **[chap04/udp_recvfrom.c](chap04/udp_recvfrom.c)** Uses `recvfrom()` to receive one UDP packet.\n* **[chap04/udp_sendto.c](chap04/udp_sendto.c)** Uses `sendto()` to send one UDP packet.\n* **[chap04/udp_serve_toupper.c](chap04/udp_serve_toupper.c)** Receives UDP data, and echos it back to the sender in all upper-case.\n* **[chap04/udp_serve_toupper_simple.c](chap04/udp_serve_toupper_simple.c)** As above, but doesn't use `select()`.\n\n## Chapter 5\n\n* **[chap05/lookup.c](chap05/lookup.c)** Uses `getaddrinfo()` to lookup addresses for a given hostname.\n* **[chap05/dns_query.c](chap05/dns_query.c)** Encodes and sends a DNS query, then decodes the response.\n\n## Chapter 6\n\n* **[chap06/web_get.c](chap06/web_get.c)** A minimal HTTP client which will download a web resource from a given URL.\n\n## Chapter 7\n\n* **[chap07/web_server.c](chap07/web_server.c)** A minimal web server.\n* **[chap07/web_server2.c](chap07/web_server2.c)** A minimal web server (no globals).\n\n## Chapter 8\n\n* **[chap08/smtp_send.c](chap08/smtp_send.c)** A simple email sender.\n\n## Chapter 9\n\nThe examples in this chapter use OpenSSL. Be sure to link against the OpenSSL\nlibraries when compiling (`-lssl -lcrypto`).\n\n* **[chap09/openssl_version.c](chap09/openssl_version.c)** A program to report the installed OpenSSL version.\n* **[chap09/https_simple.c](chap09/https_simple.c)** A minimal program that requests a web page using HTTPS.\n* **[chap09/https_get.c](chap09/https_get.c)** The HTTP client of chapter 6 modified to use HTTPS.\n* **[chap09/tls_client.c](chap09/tls_client.c)** The TCP client program of chapter 3 modified to use TLS/SSL.\n* **[chap09/tls_get_cert.c](chap09/tls_get_cert.c)** Prints a certificate from a TLS/SSL server.\n\n## Chapter 10\n\nThe examples in this chapter use OpenSSL. Be sure to link against the OpenSSL\nlibraries when compiling (`-lssl -lcrypto`).\n\n* **[chap10/tls_time_server.c](chap10/tls_time_server.c)** The time server of chapter 2 modified to use HTTPS.\n* **[chap10/https_server.c](chap10/https_server.c)** The web server of chapter 7 modified to use HTTPS.\n\n## Chapter 11\n\nThe examples in this chapter use libssh. Be sure to link against the libssh libraries when compiling (`-lssh`).\n\n* **[chap11/ssh_version.c](chap11/ssh_version.c)** A program to report the libssh version.\n* **[chap11/ssh_connect.c](chap11/ssh_connect.c)** A minimal client that establishes a ssh connection.\n* **[chap11/ssh_auth.c](chap11/ssh_auth.c)** A client which attempts authentication.\n* **[chap11/ssh_command.c](chap11/ssh_command.c)** A client that runs a single command over ssh.\n* **[chap11/ssh_download.c](chap11/ssh_download.c)** A client that downloads a file over ssh.\n\n\n## Chapter 12\n\nThis chapter doesn't include any example programs.\n\n## Chapter 13\n\n* **[chap13/connect_timeout.c](chap13/connect_timeout.c)** Shows how to timeout a `connect()` call early.\n* **[chap13/connect_blocking.c](chap13/connect_blocking.c)** For comparison with **connect_timeout.c**.\n* **[chap13/server_reuse.c](chap13/server_reuse.c)** Demonstrates the use of `SO_REUSEADDR`.\n* **[chap13/server_noreuse.c](chap13/server_noreuse.c)** For comparison with **server_reuse.c**.\n* **[chap13/server_crash.c](chap13/server_crash.c)** This server purposefully writes to a TCP socket after the client disconnects.\n* **[chap13/error_text.c](chap13/error_text.c)** Shows how to obtain error code descriptions.\n* **[chap13/big_send.c](chap13/big_send.c)** TCP client. Sends lots of data after connecting. Used to show blocking behaviour of `send()`.\n* **[chap13/server_ignore.c](chap13/server_ignore.c)** TCP server. Accepts connections, then simply ignores them. Used to show blocking behaviour of `send()`.\n* **[chap13/setsize.c](chap13/setsize.c)** Shows max number of sockets `select()` can handle.\n\n## Chapter 14\n\nThis chapter doesn't include any example programs.\n\n\n## Required Software\n\nFollowing along with the code in this book requires that you to have access to a C compiler on a standard operating system. The example programs in this book were carefully tested on Windows, Linux, and macOS. They were tested using the gcc, clang, and Microsoft Visual Studio compilers. All of the code in this book will compile as either C or C++.\n\nIn addition, the code examples in Chapter 9, Loading Secure Web Pages with HTTPS and OpenSSL, and Chapter 10, Implementing a Secure Web Server, require that you have the OpenSSL library installed.\n\nChapter 11, Establishing SSH Connections with libssh, requires that the libssh library is installed.\n\nInstructions for installing all of the require software are provided in the appendices. See Appendix B, Setting Up Your C Compiler On Windows, Appendix C, Setting Up Your C Compiler On Linux, and Appendix D, Setting Up Your C Compiler On macOS, for compiler setup. A complete list of the example programs provided is given in Appendix E, Example Programs.\n\nNo non-free software is required to follow along with any of the examples in this book.\n\n\n## Get to Know the Author\n**Lewis Van Winkle** is a software programming consultant, entrepreneur, and founder of a successful IoT company. He has over 20 years of programming experience after publishing his first successful software product at age twelve. He has over 15 years of programming experience with the C programming language on a variety of operating systems and platforms. He is active in the open-source community and has published several popular open-source programs and libraries, many of them in C. Today, Lewis spends much of his time consulting, where he loves taking on difficult projects that other programmers have given up on. He specializes in network systems, financial systems, machine learning, and interoperation between different programming languages.\n\n\n### Suggestions and Feedback\nPlease [contact me](https://handsonnetworkprogramming.com/contact/) if you have any feedback or suggestions.\n\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodeplea%2Fhands-on-network-programming-with-c","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodeplea%2Fhands-on-network-programming-with-c","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodeplea%2Fhands-on-network-programming-with-c/lists"}