Am looking for an open source code for the TCP/IP stack. An explanation along the lines of the stack would also help me in understanding the different modules and their interactions. I tried searching but there is very less information relating to just the TCP/IP stack.
Source code for TCP/IP stack
internetnetworking
Related Solutions
The main difference between the algorithms actually used for Internet routing, and the A* algorithm, is that
- The A* algorithm requires all the information about a network -- knowledge of every node and exactly how the nodes are connected -- on a single machine, and that machine finds the actual best complete path.
- packet routing algorithms running on a router are "distributed algorithms" that use various heuristics to get "good" (but rarely the "best") results with very limited amounts of information at each router and very limited amounts of time at each router. Each router does a little bit of the work -- it chooses the next step in the path. None of the routers ever calculate a "complete path", and the actual path traveled by a packet is rarely the best.
Since A* finds the best path, why do we use other algorithms that give us suboptimal paths? The A* algorithm is impossible on the Internet for several reasons. There are now so many nodes on the Internet that it is impractical for a router to have enough RAM to store the IP address of every node and which nodes are connected to it. Even if every router did have plenty of RAM, when a new router is turned on or a new link is installed, we expect that new path to start handling packets more-or-less immediately, rather than waiting for that router to download the connection diagram of the entire internet and waiting for every other router on the planet to update its connection diagram. Many routers have packets coming in so quickly that there's simply not enough time to run a full A* algorithm on each packet. In some cases, changes in the network that affect the path of a packet can happen while the packet is in-flight, after the packet has been sent.
I hear that the simplest possible routing protocol -- "hot potato routing" -- works surprisingly well in small internetworks: Each router keeps track of the IP address of each end-node directly connected to it. If the router receives a packet with one of those as the destination address, then the router sends it to that end-node, and that packet's journey is complete. Otherwise, a router using "hot potato routing" randomly sends the incoming packet to any router directly connected to it.
I hear that the Border Gateway Protocol is currently the most popular routing protocol on the internet. The RFC4271 (and its errata) give detailed information that, in principle, is enough to build a interoperable router.
Such protocols typically use some combination of two techniques to allow each router to build its own routing table:
- Passive: When a packet from some IP address A comes in on port X, and later some packet with a destination of the same IP address A comes in on some other port, the router knows it should send that second packet out port X. The number of unique addresses associated with a port will eventually become too many to store all of them, so the router uses route summarization. Route summarization relies on the fact that geographically nearby machines do, in fact, typically have similar IP addresses, and IP addresses are handed out in ways that typically form a hierarchial tree of geographical subnets.
- Active: The router sends out its own IP address, and (a summary of) the IP addresses of the machines directly connected to it, to neighboring routers, typically using the routing information protocol.
TCP is a stream protocol, usually on top of IP (IPv4 or 6).It doesn't cover file transmission. Instead, this is typically delegated to other protocols such as FTP, HTTP, HTTPS, NFS, CIFS or rsync.
You are apparently removing the IP and TCP headers from the data, but not the metadata added by the other protocol(s) you're using. Since you haven't told us what those are, we can't specifically address them, but in general you'll have to implement a protocol handler for that.
Note that with advanced protocols such as HTTPS, you obviously and by design cannot recover a file from only the server side packets.
Best Answer
You can browse the entire Linux kernel at LXR. For example, here's the implementation of TCP over IPv4. Be aware that a full, real-world TCP/IP stack is going to be huge and it's going to be difficult getting a feel from it just by studying source code.
There are many books available which give you more of an overview, such as this one and this one. Follow the "related titles" link in Amazon for many more...