Data link / Application layers [Archive] - C Board

PDA

View Full Version : Data link / Application layers


ltcabral
04-08-2008, 09:56 AM
Could anyone make a simple example of an implementation in C of 2 separate layers, application and data link? In the program i need to make, they communicate with pre-defined functions, and the data link layer uses stop-n-wait or sliding window, which ill implement. The data link will use UDP sockets, but they will be included in pre-defined functions, so all i need to know is how to make the structure of the 2 layers program for this situation. Thanks in advance.

matsp
04-09-2008, 05:45 AM
Generally, the application layer is a packet within a bigger packet that is the data link. The purpose of the data link is to ensure the packet arrives correctly to the right application and complete with the correct content.

I don't have any direct example, but the data structure may be something like this:

struct header
{
int magic; // A magic number that indicates the start of a packet.
int pktsize; // Size of the payload (application) data.
int hdrsize; // Size of this header
int pktcsum; // checksum of the payload data.
int recipient; // Who it's for.
int sender; // Who sent it
int hdrcsum; // checksum of the header (it's last, so we can calculate it from the other components)
};


--
Mats