C/layer fragmentation
Expert: Narendra - 9/18/2005
QuestionHi!
I'm implementing a layered network in c, and was wondering if
you could please help or point me in the right direction with the
fragmentation...
There are 4 layers... layer 4 can send messages of up to 1000
bytes to layer 3... layer 3 has to fragment them down to 150
byte packets to send to layer 2... each packet has a 20 byte
header, so there will be 100 bytes for the data...
then on the way back, the fragments need to be put back in the
correct order... and sent up to layer 4 again...
so can you please point me in the right direction?
thanks!
#define L3_MTU 65536
typedef struct {
unsigned int length;
unsigned char data[L3_MTU];
} L3_IDU;
void L3_sendDU(L3_IDU l3idu)
{
..
}
#define L2_MTU 150
typedef struct {
unsigned int length;
unsigned char data[L2_MTU];
} L2_IDU;
void L3_receiveL2_IDU(L2_IDU l2idu)
{
..
}
AnswerFragmentation & de-fragmentation is a well defined network protocol.
So if you study the RFC's of layer-1, 2, 3 & 4, you will definitely get to study the protocol.
You will need to have sequence number for each packet and fragment number within these sequence numbers.
So, using this you will be able to determine which fragment belongs to which packet and can be joined together.
If any of the fragment is missing, you will have to resend the packet or take a decision based on the protocol/application you are building.
Also, you will have to decide about how to decide which is the last fragment.
So, what I suggest for you is to study the RFC and it would help you in this.
-Narendra