DATA LINK LAYER PROTOCOLS
1. Protocol for an Ideal Channel and Ideal Nodes
Implement a Program in GNU C in which the sender reads data from a given file,
encapsulates the data in a frame and transmits the frame to the receiver. This goes
on till all the data is read from the file. The receiver goes on receiving the frames,
de-capsulate the data from frame and store the data in a separate file. At the end,
the original data file at the sender’s end and the contents of the file at the receiver’s
end should tally. For sender/receiver communication, use IPC mechanism
FIFO/Named Pipes in Linux/Unix environment. Use Bit-Wise operators in C
wherever applicable. Consider a simplistic frame structure consisting of only frame
data (ASCII character string). All other fields of frame are to be neglected. Use
appropriate data-types for various variables/frame structure. Take appropriate
frame size and file sizes. Assume an ideal situation where the channel is noiseless
and receiver node has infinite system resources.
- first urn tem2.c
- then run term.c
term.c
#include<stdio.h>
#include<fcntl.h>
#include<unistd.h>
#include<sys/stat.h>
#include<string.h>
int main(){
int tid;
char string[BUFSIZ];
char str[60];
FILE *fp = fopen("a.txt" , "r+");
tid=open("MyPipe",O_WRONLY);
while(fgets(string,sizeof(string),fp)){
printf("%s",string);
write(tid,string,sizeof(string));
}
unlink("MyPipe");
close(tid);
/*
*/
return 0;
}
tem2.c
tem2.c
#include<stdio.h>
#include<fcntl.h>
#include<unistd.h>
#include<sys/stat.h>
#include<string.h>
int main(){
int tid;
char string[BUFSIZ];
FILE *fp = fopen("aa.txt" , "w+");
mkfifo("MyPipe",0666);
tid=open("MyPipe",O_RDONLY);
while(read(tid,string,sizeof(string))){
printf("%s",string);
fprintf(fp,"%s",string);
}
printf("%s",string);
unlink("MyPipe");
close(tid);
return 0;
}
Post a Comment