network-programmingnicdata-link-layer

How to access/read/write/program/listen in the first four layers of the OSI Model?


I am wondering how do all the networking dance components work: How can I program/read/write/access raw and parsed data in:

  1. the physical layer (through the NIC)?
  2. the data-link layer? (e.g. so as to make my own switching OS)
  3. the network layer? (e.g. so as to make my own routing OS)
  4. the transport layer?

Solution

  • RAW sockets allow you to modify all the above. Amazing examples can be found here. As you can see you can modify all the layer, but you must do all the parsing and processing yourself. Using UDP as an example:

    Layer 4 - you must either parse or create the UDP Header

    Layer 3 - You must either parse or create the IP Header

    Layer 2 - You must either parse or create the Ethernet Header

    Layer 1 - Write to or Read from the interface you opened the socket on