9 ms·
Let's code a TCP/IP stack (2016)
- eatonphil 5y agoThis is an awesome reference but I wish the code was shown as part of the tutorials. The Github code today is somewhat more complicated to follow. If you know of any tutorials that walk through a TCP/IP stack with all relevant code I'd love to hear of it.
- count 5y agoHave you seen Richard W. Stevens book TCP/IP Illustrated? Specifically volume 2 'the Implementation', which is, I think what you're looking for (albeit slightly dated).
- eatonphil 5y agoYes I own the series but their focus is a little more on completeness. I know I'm getting picky :) but TCP is pretty complex so I keep looking out for the most minimal code and walk through to understand all the state management and other flow.
- belter 5y agoNot a tutorial but did you look at PicoTCP ? https://github.com/tass-belgium/picotcp https://github.com/tass-belgium/picotcp
- tcptomato 5y agoThat version is abandoned and has quite a few severe bugs. There is a GPL fork which is maintained https://github.com/virtualsquare/picotcp https://github.com/virtualsquare/picotcp
- kqr2 5y agoThere is also a book : TCP/IP Lean http://www.iosoft.co.uk/tcplean.php http://www.iosoft.co.uk/tcplean.php
- johndoe0815 5y agoIn addition to the Stevens books already mentioned, there's also volume 2 of Comer's Xinu OS book: Operating System Design, Vol. 2: Internetworking with Xinu, ISBN-13: 978-0136374145 (https://www.amazon.com/Operating-System-Design-Vol-Internetworking/dp/013637414X https://www.amazon.com/Operating-System-Design-Vol-Internetw...). Unfortunately, this book was written in 1987, so it's a bit dated (e.g. no IPv6). I think it's still useful to learn the basics of a TCP/IP implementation.
- eatonphil 5y agoInteresting, thanks for the reference.
- deleted 5y ago[deleted]
- weavie 5y agoJon Gjengset has a series of videos implementing TCP in Rust. https://youtu.be/bzja9fQWzdA https://youtu.be/bzja9fQWzdA
- deleted 5y ago[deleted]
- deleted 5y ago[deleted]
- GeorgeTirebiter 5y agoHave a look at a TCP/IP stack written for ham radio, originally for CP/M: http://www.ka9q.net/code/ka9qnos/ http://www.ka9q.net/code/ka9qnos/
- ofrzeta 5y agoNostalgia anecdote: we used KA9Q as the routing software on a 286 PC with an ISDN uplink.
- taf2 5y agoISDN was super fast - I remember playing Warcraft 2 on an ISDN connect with a friend down the street :)
- 867-5309 5y agogrowing up in the UK stuck with 56Kbps modems, when prompted to select network speeds I remember seeing things like ISDN (128Kbps) and T1/T3 Cable (1Mbps) and thinking wow, those Americans have lightning Internet
- g0ran 5y agoOh how the tides have turned.
- teh_klev 5y agoYou could get ISDN2 installed on domestic premises in the UK. It wasn't cheap though, because as soon as you wanted a bonded 128k channel the cost could become somewhat eye watering for a domestic user (or even a small business). The good thing though was that you got a guaranteed 64k rather than the vagueries of a 56k modem that in practice never actually worked at 56k, more like 30-45k depending on phone line quality. On top of that you could (if your wallet was fat enough) get ISDN30 (E1) which was akin to a T1 but ~500k faster. I did a fair amount of commissioning of these things back in the 90's.
- cbm-vic-20 5y ago
- baby 5y agoIs there something similar but in python or rust or go? Not really keen on reading C.
- fdr_cs 5y agoJon Gjengset here implements TCP in rust. It's long, but it is very good https://youtu.be/bzja9fQWzdA https://youtu.be/bzja9fQWzdA
- antonalekseev 5y agohttps://github.com/jvns/teeceepee https://github.com/jvns/teeceepee
- wikitawasha 5y agoLow level library https://github.com/soypat/ether-swtch https://github.com/soypat/ether-swtch
- dpweb 5y agoNotice these classic technologies. They’re SIMPLE. That got lost in later development up the stack.
- naikrovek 5y agoI don't think I would describe TCP/IP as "simple". there are parts of the spec that contradict each other! it's impossible to implement fully.
- netr0ute 5y agoThe layer system used by TCP/IP (layer 2 -> 3 -> 4) makes it "simpler" because everything can be compartmentalized without worrying because it was designed to be that way. The real problem comes when you use TCP/UDP for higher level protocols and that's where the real difficulty is.
- tptacek 5y agoThere's really no such system. In TCP/IP, we refer to "layer 3" and "layer 4" protocols, in reference to OSI, but TCP/IP isn't an OSI protocol, the lines between L2 and L3 are blurred by things like ARP and DHCP (or completely eliminated in overlay networks and multicast), and none of the rest of the layers are even informally specified for TCP/IP. If all you're saying is that TCP/IP has, among its many goals, a separation of concerns, sure. But most major systems designs have separations of concerns.
- omegalulw 5y agoThe fundamental problem is that once your break/compartmentalize into layers it's harder apply global optimizations at local layers. You are trading off ease of implementation and compositionality for performance. You have to bubble up optimizations up the stack. This is partly why QUIC is based on UDP instead TCP. You don't have all the information needed at the TCP layer to do the kind of optimizations that QUIC does.
- odddog309 5y agosomething similar in rust https://www.youtube.com/watch?v=bzja9fQWzdA https://www.youtube.com/watch?v=bzja9fQWzdA
- splittingTimes 5y agoComing from C/C++ and Having worked for 5 years within the java world now, i must admit that the naming "conventions" and variable abbreviation in c code or more specifically Linux kernel code form a high entry barrier for me. Why is it so hard to write things out? We all look up to the various Linux philosophies (keep it simple, do one thing, etc), but to me it feels that this kind of code style is not written with a human reader in mind, but comes from the programmer perspective of "what is the shortest way and type as few characters as possible." This kind of overhead seems so unnecessary and alienating.
- theamk 5y agoI think the name shortening is very common in practically every science - and when we are not restricted to ASCII it is even worse, you would see mostly single letter names, combined with subscripts, superscripts, fonts, extra alphabets like Greek and so on. At least things like ifr_flags are easy to read, easy to type, and unique enough you ca search for them.
- linguae 5y agoC and Unix are from the early 1970s. They date from an era that predates the prevalence of large, bitmapped displays. There is a famous photo of Dennis Ritchie and Ken Thompson at a teletype in 1972 (http://www.columbia.edu/cu/computinghistory/teletype/ken-and-den.html http://www.columbia.edu/cu/computinghistory/teletype/ken-and...). When the luxuries of modern IDEs, bitmapped displays, and high amounts of untapped computational power are unavailable, the programming environment and operating system need to adapt to the technologies that are available. The convenience of terse names is more pronounced in an environment of teletypes. On the flipslide, Smalltalk, also developed in the 1970s, has much longer names. But Smalltalk was developed for the Xerox Alto (https://en.wikipedia.org/wiki/Xerox_Alto https://en.wikipedia.org/wiki/Xerox_Alto), an expensive machine with a bitmapped display, luxurious even by 1980s standards. Lisp also gradually embraced longer names as technology improved; compare the early Lisps of the early 1960s to Common Lisp, which first appeared in the mid 1980s. C and Unix are products of their relatively spartan environments from the early 1970s, whereas Java, a product of the 1990s, was influenced by Smalltalk, which was born under less austere conditions.
- dang 5y agoPast related threads: Let's code a TCP/IP stack, 1: Ethernet & ARP (2016) - https://news.ycombinator.com/item?id=17316487 https://news.ycombinator.com/item?id=17316487 - June 2018 (47 comments) Let's Code a TCP/IP Stack: TCP Retransmission - https://news.ycombinator.com/item?id=14701199 https://news.ycombinator.com/item?id=14701199 - July 2017 (30 comments) Let's code a TCP/IP stack, 1: Ethernet and ARP - https://news.ycombinator.com/item?id=11234229 https://news.ycombinator.com/item?id=11234229 - March 2016 (49 comments)
- deleted 5y ago[deleted]
- vajrabum 5y agoARP's fun but it's arguably the least fun bit of the TCP/IP stack. Here are the other articles from the series. https://www.saminiir.com/lets-code-tcp-ip-stack-2-ipv4-icmpv4/ https://www.saminiir.com/lets-code-tcp-ip-stack-2-ipv4-icmpv... https://www.saminiir.com/lets-code-tcp-ip-stack-3-tcp-handshake/ https://www.saminiir.com/lets-code-tcp-ip-stack-3-tcp-handsh... https://www.saminiir.com/lets-code-tcp-ip-stack-4-tcp-data-flow-socket-api/ https://www.saminiir.com/lets-code-tcp-ip-stack-4-tcp-data-f... https://www.saminiir.com/lets-code-tcp-ip-stack-5-tcp-retransmission/ https://www.saminiir.com/lets-code-tcp-ip-stack-5-tcp-retran...
- numlock86 5y agoEthernet, ARP, IP, ICMP and UDP are all the fun, until you get to do TCP.
- marlouwe 5y agoThe Internet Computer is going to fix that (https://dfinity.org/ https://dfinity.org/)
- effnorwood 5y agoLet's not. #FreeBSD