r/C_Programming • u/Soft-Bedroom8708 • 2d ago
Building a user space network stack from scratch
I dont know much about networking as i am just now studying it seriously but i am thinking of building what i mentioned in the title from scratch, if anyone could help me with the direction im supposed to go in to start i would really really appreciate it. whenever i try looking up a place to start all i get is github repos with many many files of stuff im not yet familiar with and it all assumes prior knowledge of some stuff, i know you cant really just go into this thing blind but what im saying is i dont really know where to begin learning about all of this stuff to build my target. also i am on a 2-week time limit
7
u/Due-Mortgage-6854 2d ago
thats a huge project for a beginnerðŸ˜
Ik you said you don't really love the github repos but did you try this one : https://github.com/TanayK07/networking-from-scratch ?
1
u/deaddodo 2d ago
What do you mean by a "user space network stack"? Are you referring to a client/server architecture over the OS' network interface? Or are you trying to implement your own TCP/IP / UDP/IP / other networking interface that runs via a user space daemon?
For the former, it's tedious but overall fairly simple. You can just follow Beej's guide for a run down of sockets. For the latter, you're getting into black magic territory, OSes like to lock down the raw network interface for various reasons. You would either need to break your "user space" requirement and write some sort of kernel or driver shim, or go straight to embedded development.
That being said, I've never had to actually write a user space network protocol/interface, so others here might have better advice for you.
3
u/sciencekm 2d ago edited 2d ago
Look up the book "Computer Networks: A Systems Approach" by Larry Peterson, 1st Edition.
As part of teaching the fundamentals, it implements a complete single allocation, zero copy TCP/IP stack in C.
https://people.inf.elte.hu/toke/halozatok-jegyzet/Peterson-Davie/X-kernel/
1
u/yel50 9h ago
not sure how much of the stack you want to do, but a good user space project would be to implement an FEC (Forward Error Correction) protocol. then write a proxy that corrupts the packets and verify that the receiver can still recover the original data.