You are here:

C/layer fragmentation

Advertisement


Question
Hi!

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)
{
..
}

Answer
Fragmentation & 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

C

All Answers


Answers by Expert:


Ask Experts

Volunteer


Narendra

Expertise

I can answer questions in C related to programming, data structures, pointers and file manipulation. I use Solaris for doing C code and if you have questions related to C programming on Solaris, I will be able to help better.

Experience

6.5

Organizations belong to
Sun Microsystems

Awards and Honors
Brain Bench Certified Expert C programmer.
Advanced System Software Certified

©2012 About.com, a part of The New York Times Company. All rights reserved.