Thread: Data-Link Layer Network Programming

  1. #1
    Old Fashioned
    Join Date
    Nov 2016

    Data-Link Layer Network Programming

    I'm having a slightly difficult time learning strictly the datalink layer programming. Every time I search for "network programming" it's 99% of the time TCP/IP and mostly HTTP.

    However, I want to do something which requires knowledge of Data Link Layer programming - need to write a custom program which uses the NIC to do some wi-fi stuff at the MAC address level.

    Do you know of any good resources, books, tutorials, etc in which a program is implemented in layer 2 of the OSI model entirely? If not, can you suggest a simple program I could try writing to get a basic knowledge of this layer?

    I assume I'm still going to be using the socket() API but just with raw sockets like this: socket(AF_PACKET,RAW_SOCKET) etc... but since I've never worked at this layer or know anyone who does, I don't even understand what a "connection" would look like at level if that makes sense.

    In any event, I looked at the ToC for Unix Network Programming book and it does seem to be mostly focused on TCP/IP and also my The Linux Programming Interface book is the same way, which makes sense because most apps do work at those layers... But someone must have had to code up the lower-level stuff and I'm rather surprised there isn't a title focusing on layer 2. I did take a look at the tun code in the Linux kernel but that's also like trying to build a house by diving straight into a jungle.
    Last edited by Asymptotic; 12-26-2018 at 05:36 PM.
    If I was homeless and jobless, I would take my laptop to a wifi source and write C for fun all day. It's the same thing I enjoy now!

  2. #2
    Old Fashioned
    Join Date
    Nov 2016
    Ok so I made some headway here and realized that essentially, an Ethernet/DL frame is just a very simple data structure wrapping up bytes by having a source and dest MAC address and then a data payload.

    I realized that parsing that is pretty trivial, and it's the IP then TCP header/layer stuff that becomes more complex..

    But I have one final question which I think some folks here may know the answer to. When I open a socket and create a TCP connection in C, I noticed that my C program doesn't really seem to know/care about which TCP packet we're on; just that we are using TCP, there is a connection which exists, and we are sending data from one place to another. Are these lower-level details worked out in the sockets library itself?
    If I was homeless and jobless, I would take my laptop to a wifi source and write C for fun all day. It's the same thing I enjoy now!

  3. #3
    Registered User
    Join Date
    May 2009
    "which TCP packet we're on" means nothing to me; did you mean TCP port or IP Address?

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 0
    Last Post: 02-21-2014, 11:25 AM
  2. Sending data over the network
    By codewriter in forum Tech Board
    Replies: 10
    Last Post: 05-09-2012, 06:44 AM
  3. Data link / Application layers
    By ltcabral in forum Networking/Device Communication
    Replies: 1
    Last Post: 04-09-2008, 05:45 AM
  4. Link to outside data in list view
    By eth0 in forum Windows Programming
    Replies: 5
    Last Post: 01-13-2006, 05:08 AM
  5. Trying to send data over a network
    By CyberVulpine in forum C++ Programming
    Replies: 1
    Last Post: 06-06-2002, 11:45 AM

Tags for this Thread