Pages

Sunday, December 25, 2016

Networking - Simulation of Framing Concept.

Networking: Simulation of Framing Concept using C language.

Assumptions:

1. Header contains following parameters:
    FrameNumber, SourceIP, DestinationIP,FiveCharacters of Data
2. SourceIP=192.168.1.1
3. DestinationIP=192.168.1.2
4. Input data is taken from input.txt file.
5. Generated Frames will be stored in output.txt file.

#include <stdio.h>
int main()  
{
  FILE *fp1, *fp2, *fopen(); 
  int i;
  char c,cnt=49; 
  fp1 = fopen("input.txt","r");  
  // open for reading
  fp2 = fopen("output.txt","w") ; 
  //open for writing

  if ( fp1 == NULL )
 
printf("Cannot open input.txt." ); 
exit(1);    
 
  else if ( fp2 == NULL ) 
 
printf("Cannot open output.txt."); 
exit(1);    
 
  else 
  {
  c = getc(fp1) ;  
  while ( c != EOF) 
 
putc(cnt++,fp2);
fputs(",192.168.1.1,192.168.1.2,",fp2);
//Logic to track 5 characters
for(i=0;i<5;i++) 
{
putc( c,  fp2); //Write to Output.txt 
c =  getc( fp1 ) ;
//putc(10,fp2);
}
putc(10,fp2);
  }
  printf("Frames generated in Output.txt file.");
  fclose(fp1); //close files
  fclose(fp2); 
  }
  return 0; 
}

Output of the program:

Frames generated in Output.txt file.

Sample content in input.txt file is as under:

Hello students, how are you?

After execution of program content of output.txt file:

1,192.168.1.1,192.168.1.2,Hello
2,192.168.1.1,192.168.1.2, stud
3,192.168.1.1,192.168.1.2,ents,
4,192.168.1.1,192.168.1.2, how 
5,192.168.1.1,192.168.1.2,are y
6,192.168.1.1,192.168.1.2,ou?ÿÿ

* * * * *




No comments:

Post a Comment