Upload
pradyot-sn
View
215
Download
0
Embed Size (px)
Citation preview
8/10/2019 Networks Laboratory
1/10
File: /home/pradyot/Desktop/CN FINAL/crc.c Page 1 of 2
//7. Write a program for error detecting code using CRC-CCITT (16- bits).#include#include#includeint main(){
char rem[50],a[50],s[50],c,msg[50],gen[]="111";int i,genlen,t,j,flag=0,k,n;printf("Generator polynomial is CRC-CCITT %s\n",gen);
genlen=strlen(gen);k=genlen-1;printf("\nEnter the message\n");n=0;while ((c=getchar())!='\n'){
msg[n]=c;n++;
}msg[n]='\0';for (i=0;i
8/10/2019 Networks Laboratory
2/10
File: /home/pradyot/Desktop/CN FINAL/crc.c Page 2 of 2
for (i=0;i
8/10/2019 Networks Laboratory
3/10
File: /home/pradyot/Desktop/CN FINAL/dist1.c Page 1 of 1
#include#include#include
int min( int a, int b){
return (a
8/10/2019 Networks Laboratory
4/10
File: /home/pradyot/Desktop/cn nal for pdf/9.c Page 1 of 2
/*9. Using TCP/IP sockets, write a client server program to make the clientsend the file name and to make the server send back the contents of therequested file if present.
CLIENT:*/#include#include#include
#include#include#include#define MAX 100#define MAXBUFF 1000int main( int argc, char * argv[]){
int n,c,sid;char buf[MAX],buf1[MAXBUFF];struct sockaddr_un client;sid=socket(AF_UNIX,SOCK_STREAM,0);if (sid
8/10/2019 Networks Laboratory
5/10
File: /home/pradyot/Desktop/cn nal for pdf/9.c Page 2 of 2
SERVER:
#include#include#include#include#include#include#include
#define MAX 100#define MAXBUFF 1000int main(){
int sid,fd,a,l,n,b,length;char buf[MAX],buf1[MAXBUFF];struct sockaddr_un server,client;sid=socket(AF_UNIX,SOCK_STREAM,0);if (sid
8/10/2019 Networks Laboratory
6/10
File: /home/pradyot/Desktop/cn nal for pdf/10.c Page 1 of 2
10. Implement the above program using as message queues or FIFOs as IPCchannels.
CLIENT:#include#include#include#include#include
#define FIFO1 "fifo1"#define FIFO2 "fifo2"#define PERMS 0666char fname[256];int main(){
int readfd,writefd,fd;ssize_t n;char buff[512];printf("Trying To Connect To SERVER!!!\n");writefd=open(FIFO1,O_WRONLY,0);readfd=open(FIFO2,O_RDONLY,0);if (readfd0)
write(1,buff,n);close(readfd);close(writefd);return (0);
}/*pradyot@pradyot :~/cn/10$ cc -o client fifoclient.cpradyot@pradyot :~/cn/10$ ./clientTrying To Connect To SERVER!!!Connection EstablishedEnter the File Name to request from Server:hiWaiting for Server to Reply...hi ho w are youi am finepradyot@pradyot :~/cn/10$*/
SERVER:#include#include#include#include#include#include#define FIFO1 "fifo1"#define FIFO2 "fifo2"#define PERMS 0666char fname[256];int main(){
int readfd,writefd,fd;ssize_t n;char buff[512];if (mkfifo(FIFO1,PERMS)
8/10/2019 Networks Laboratory
7/10
File: /home/pradyot/Desktop/cn nal for pdf/10.c Page 2 of 2
if (mkfifo(FIFO2,PERMS)
8/10/2019 Networks Laboratory
8/10
File: /home/pradyot/Desktop/cn nal for pdf/11.c Page 1 of 2
11. Write a program for simple RSA algorithm to encrypt and decrypt thedata.#include#include#includelong int e,d,n;long int val[50];
char decode( long int ch)
{ int i;long int temp=ch;for (i=1;i
8/10/2019 Networks Laboratory
9/10
File: /home/pradyot/Desktop/cn nal for pdf/11.c Page 2 of 2
do{
d=rand()%phi;} while ((d*e%phi)!=1);printf("\n**** encoding message*** \n");sleep(2);for (i=0;text[i]!='\0';i++)
val[i]=encode(text[i]);
val[i]=-999;printf("\n**** encoded message *** \n");for (i=0;val[i]!=-999;i++)
printf("%ld",val[i]);printf("\n decoded message");sleep(2);for (i=0;val[i]!=-999;i++)
ctext[i]=decode(val[i]);ctext[i]='\0';printf("\n decoded message :%s\n\n\n",ctext);
}
/* pradyot@pradyot :~/cn$ ./a.outEnter the text to be encoded
hi how are uhi how are u
p=13 q=23 n=299 phi=264
**** encoding message***
**** encoded message ***13248981322714198111114759839decoded messagedecoded message :hi how are u
pradyot@pradyot :~/cn$*/
8/10/2019 Networks Laboratory
10/10
File: /home/pradyot/Desktop/cn nal for pdf/12.c Page 1 of 1
//12. Write a program for congestion control using leaky bucket algorithm.#includeint main(){
int max_buf_size=400, out_flow_rate=100, i, in_flow[10], out_flow=0, dis_arr[10], cur_buf_used=0;
printf("Enter the inflow:\n");for (i=0;i