Pages

Friday, March 16, 2018

Networking Protocol Header


Various protocols like TCP, UDP, IP, IPSec, HTTPs etc have their own header. Following program can be extended to create full protocol header.

Write a C program to generate protocol header with following set of parameters into it:
  •  First parameter is Source IP Address
  •  Second parameter is Destination IP Address
  •  Third parameter is total number of characters present in input.txt file.
#include<stdio.h>
#include<conio.h>

int main()
{

FILE *input,*out;
int c,counter=0;
//Source Add
char source[]="192.168.1.1";
//Destination Add
char dest[]="192.168.1.20";

input= fopen("input.txt","r");
out=fopen("output.txt","w");

if(input==NULL){
printf("Input File Not found");
}
else if(out==NULL){
printf("Output file not Created");
}
else{
//Counting No of charecter in files
do{
c=getc(input);
counter++;
}while(c!=EOF);

counter= counter-1;
//Generatting Headers

fprintf(out,"%s,%s,%d",source,dest,counter);
printf("Header generated Successfully.\nCheck output.txt file.");

fclose(input);
fclose(out);

return 0;
}
}


Output of program:

Header generated Successfully.
Check output.txt file.


No comments:

Post a Comment