areuz areuz - 12 days ago 5
C Question

Practical Implementation of OSI layers into code

Knowing the theory of how the seven layers interact and manipulate the data in theory is one thing, but how one implements this in the real-world with actual code is another.

I want to know how these layers are implemented in practice (PC as a example, because it uses all of the layers unlike a Router, etc.) - is every layer a separate process that has a standardized API (so there are many peices of software that work together) or is something like a network Driver for a specific HW/SW setup responsible for all of this using shared libraries and such? Or is it some other completely different approach?

The reason I'm asking this, is because I want to create my own network on the 886MHz band, and I want to use some existing code (for ex. a DataLink error correction and such code - because that is just way beyond my skill) but also write my own Network layer code to customize the way devices interact.

Answer

is something like a network Driver for a specific HW/SW setup responsible for all of this

Yes. In most all modern operating systems, the networking stack is implemented in the kernel, for performance and security reasons.

Performance: A lot of work goes into processing a packet, so it's more efficient to do that work in the kernel before dispatching the application-layer data to the application bound to the given socket.

Security: The kernel prevents unpriveleged users from doing "bad" things, like spoofing their IP address or flooding another host with ICMP messages.

A good resource to look at would be the Linux kernel source code.

  • net - Here you'll find all of the core device and protocol implementations (IP, TCP, UDP, etc.)
    • dev.c - Device management
    • ipv4 - IPv4 and UDP, TCP v4
    • ipv6 - IPv6 and UDP, TCP v6
  • drivers/net - Network device drivers