Pages

Saturday, December 17, 2016

Computer Networking Practical - Fragmentation Implementation

Computer Networking Practical of Fragmentation

/* Implementation of fragmentation concept using C program.
Assume MTU size is 5 characters. 
All fragments will be displayed on screen.
Content of in.txt file is: "Hello student. How are you?"
*/

#include<stdio.h>
#include<string.h>
int main()
{
  char ch;
  int i=0,cnt=0;
  FILE *fp;

  fp=fopen("in.txt","r");
  ch=fgetc(fp);

/*Assuming SourceIP=192.168.1.1 and DestinationIP=10.1.1.1*/

  printf("%d,192.168.1.1, 10.1.1.1,",cnt++);
  while(ch != EOF)
  {
  printf("%c", ch);
  i++;
  if(i%5==0)
  {
printf("\n");
printf("%d,192.168.1.1, 10.1.1.1,",cnt++);
  }
  ch = fgetc(fp);
  }
  printf("\nTotal fragments created=%d",cnt);
  return 0;
}

/*Instead of printing fragments on screen, we can also write fragments into a file.*/

Output of the program

0,192.168.1.1, 10.1.1.1,Hello
1,192.168.1.1, 10.1.1.1, stud
2,192.168.1.1, 10.1.1.1,ent.
3,192.168.1.1, 10.1.1.1,How a
4,192.168.1.1, 10.1.1.1,re yo
5,192.168.1.1, 10.1.1.1,u?
Total fragments created=6
* * * * *

No comments:

Post a Comment