https://github.com/cozis/microtcp Skip to content Toggle navigation Sign up * Product + Actions Automate any workflow + Packages Host and manage packages + Security Find and fix vulnerabilities + Codespaces Instant dev environments + Copilot Write better code with AI + Code review Manage code changes + Issues Plan and track work + Discussions Collaborate outside of code Explore + All features + Documentation + GitHub Skills + Blog * Solutions For + Enterprise + Teams + Startups + Education By Solution + CI/CD & Automation + DevOps + DevSecOps Resources + Learning Pathways + White papers, Ebooks, Webinars + Customer Stories + Partners * Open Source + GitHub Sponsors Fund open source developers + The ReadME Project GitHub community articles Repositories + Topics + Trending + Collections * Pricing Search or jump to... Search code, repositories, users, issues, pull requests... Search [ ] Clear Search syntax tips Provide feedback We read every piece of feedback, and take your input very seriously. [ ] [ ] Include my email address so I can be contacted Cancel Submit feedback Saved searches Use saved searches to filter your results more quickly Name [ ] Query [ ] To see all available qualifiers, see our documentation. Cancel Create saved search Sign in Sign up You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session. Dismiss alert {{ message }} cozis / microtcp Public * Notifications * Fork 0 * Star 82 A minimal TCP/IP stack 82 stars 0 forks Activity Star Notifications * Code * Issues 1 * Pull requests 0 * Actions * Projects 0 * Security * Insights More * Code * Issues * Pull requests * Actions * Projects * Security * Insights cozis/microtcp This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository. main Switch branches/tags [ ] Branches Tags Could not load branches Nothing to show {{ refName }} default View all branches Could not load tags Nothing to show {{ refName }} default View all tags Name already in use A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch? Cancel Create 1 branch 0 tags Code * Local * Codespaces * Clone HTTPS GitHub CLI [https://github.com/c] Use Git or checkout with SVN using the web URL. [gh repo clone cozis/] Work fast with our official CLI. Learn more about the CLI. * Open with GitHub Desktop * Download ZIP Sign In Required Please sign in to use Codespaces. Launching GitHub Desktop If nothing happens, download GitHub Desktop and try again. Launching GitHub Desktop If nothing happens, download GitHub Desktop and try again. Launching Xcode If nothing happens, download Xcode and try again. Launching Visual Studio Code Your codespace will open once ready. There was a problem preparing your codespace, please try again. Latest commit @cozis cozis fixed a couple typos in the readme ... e6dbeaf Oct 31, 2023 fixed a couple typos in the readme e6dbeaf Git stats * 28 commits Files Permalink Failed to load latest commit information. Type Name Latest commit message Commit time 3p new makefile October 31, 2023 16:09 examples new makefile October 31, 2023 16:09 src new makefile October 31, 2023 16:09 .gitignore gitignore update October 31, 2023 16:12 .gitmodules general cleanups October 29, 2023 22:38 README.md fixed a couple typos in the readme October 31, 2023 21:41 makefile new makefile October 31, 2023 16:09 View code MicroTCP Where does it run? Build and Install Usage Testing README.md MicroTCP MicroTCP is a TCP/IP network stack I started building as a learning exercise while attending the Computer Networking course at the Universita degli Studi di Napoli Federico II. It's just a hobby project and is intended to just be a minimal, yet complete, implementation. At this moment MicroTCP implements ARP (RFC 826, complete), IPv4 (no fragmentation), ICMP (minimum necessary to reply to pings) and TCP (complete but not stress-tested). Note that "complete" should not be intended as "fully compliant" but just as a measure of progress on all of the major features. For instance, it's complete enough to handle HTTP traffic on a local network (Look into examples/microhttp to know more). Where does it run? MicroTCP can run on Windows and Linux alongside the OS's network stack. To route the network traffic to MicroTCP, the process running it behaves as a virtual host with its own IP address. This is done using a TAP device, which comes built-in on Linux and needs to be installed on Windows. It should be very easy to adapt MicroTCP to run on microcontrollers but haven't tried yet. The dream is to serve my blog from an STM32 board! Build and Install If you are on Windows, you need to install the TAP driver provided by OpenVPN and instanciate a virtual NIC so that MicroTCP can connect to it when started. To build the project from source, make sure you cloned the repository with submodules git clone https://github.com/cozis/microtcp.git --recursive and then run make You'll need both make and cmake for it to work. If all goes well, you'll find the library files libtuntap.a, libmicrotcp.a and header files tuntap.h, tuntap-export.h, microtcp.h in out/. Usage MicroTCP's uses the usual socket interface any network programmer is familiar with, the main difference being you need to explicitly instanciate the network stack and pass its handle around. Here's a simple echo server that shows the basic usage: #include int main(void) { microtcp_t *mtcp = microtcp_create(); uint16_t port = 80; microtcp_socket_t *server = microtcp_open(mtcp, port, NULL); while (1) { microtcp_socket_t *client = microtcp_accept(server, false, NULL); char buffer[1024]; size_t num = microtcp_recv(client, buffer, sizeof(buffer), NULL); microtcp_send(client, "echo: ", 6, NULL); microtcp_send(client, buffer, num, NULL); microtcp_close(client); } microtcp_close(server); microtcp_destroy(mtcp); return 0; } // NOTE: Errors checks were omitted for readability's sake. // If you want to use this code, you probably want to // add some checks! This should be pretty straight forward to understand. One thing may be worth noting is that microtcp_open behaves as the BSD's socket+bind+listen all at once to setup a listening TCP server. There is more than one way to set up the stack, the main way being microtcp_create which creates a virtual network inferface on the host OS with IP 10.0.0.5/24 and a virtual host for the MicroTCP process at 10.0.0.4/24. You can open Wireshark on the virtual NIC to inspect the traffic between the host and the process. It's also possible to configure the stack using the microtcp_create_using_callbacks, which lets you explicitly provide the input L2 frames to it and receive the frames in a buffer. This is how one would configure the stack to run on a microcontroller. Each instance of MicroTCP (without considering the callbacks) is completely isolated from the others, therefore, if your specific callback implementation allows it, you can have as many instances as you like! Testing There is still no testing infractructure. The way I'm testing it is by setting up an HTTP or echo server and stressing it until something breaks while capturing what happened using Wireshark. About A minimal TCP/IP stack Topics c socket tcp minimal ip socket-programming Resources Readme Activity Stars 82 stars Watchers 3 watching Forks 0 forks Report repository Releases No releases published Packages 0 No packages published Languages * C 98.9% * Makefile 1.1% Footer (c) 2023 GitHub, Inc. Footer navigation * Terms * Privacy * Security * Status * Docs * Contact GitHub * Pricing * API * Training * Blog * About You can't perform that action at this time.