Networks Laboratory (06CSL77) : Dept. of CSE, NHCE Aug-Nov 2012
Networks Laboratory (06CSL77) : Dept. of CSE, NHCE Aug-Nov 2012
NETWORKS LABORATORY PART B PROGRAMS IN C(06CSL77) Program 1. Write a C program for error detecting code-using CRC-CCITT (16-bits). #include<stdio.h> #include<unistd.h> #include<string.h> int crc(char *input, char *output, char *gp, int mode) { int j, k; strcpy(output, input); if(mode) { for(j=1; j<strlen(gp); j++) strcat(output,"0"); } for(j=0; j<strlen(input); j++) if(*(output+j) == '1') for(k=0; k<strlen(gp); k++) { if (((*(output+j+k) =='0') && (gp[k] == '0')|| (*(output+j+k) == '1') && (gp[k] =='1'))) *(output+j+k)='0'; else *(output+j+k)='1'; } for(j=0; j<strlen(output); j++) if(output[j] == '1') return 1; return 0; } int main() { char input[50],output[50]; char recv[50], gp[50]; system("clear");
Dept. of CSE, NHCE Aug-Nov 2012 Page 1
$ Enter the input message in binary 1101011011 $ Enter the generator polynomial 10011 The transmitted message is 1101011011 1110 Enter the received message in binary 11010110111110 No error in data Enter the received message in binary 11011110111110 Error in data transmission has occurred
Aug-Nov 2012
Page 2
Program 3.Write a program for Distance Vector Algorithm to find suitable path for transmission. #include<stdio.h> #include<string.h> struct node { int dist[20]; int from[20]; }rt[10]; int main() { int dmat[20][20]; int n=0, i=0, j=0, k=0,count=0; system("clear"); printf("Enter The Number Of Nodes\n"); scanf("%d",&n);
Dept. of CSE, NHCE Aug-Nov 2012 Page 4
Aug-Nov 2012
Page 6
Program-Name: Client.c #include"inet.h" int main() { int sockfd; struct sockaddr_in serv_addr,cli_addr; char filename[100],buf[1000]; int n; serv_addr.sin_family=AF_INET; serv_addr.sin_addr.s_addr=inet_addr(SERV_HOST_ADDR); serv_addr.sin_port=htons(SERV_TCP_PORT); if((sockfd=socket(AF_INET,SOCK_STREAM,0))<0) { printf("Client:cant open stream socket\n"); exit(0); } else printf("Client:stream socket opened successfully\n"); if(connect(sockfd,(struct sockaddr *)&serv_addr, sizeof(serv_addr))<0) { printf("Client:cant connect to server\n"); exit(0); } else printf("Client:connected to server successfully\n"); printf("\n Enter the file name to be displayed :"); scanf("%s",filename);
Dept. of CSE, NHCE Aug-Nov 2012 Page 7
if((sockfd=socket(AF_INET,SOCK_STREAM,0))<0) { printf("Server:cant open stream socket\n"); exit(0); } else printf("Server:stream socket opened successfully\n");
Aug-Nov 2012
Page 9
Aug-Nov 2012
Page 10
Aug-Nov 2012
Page 11
Compile and run - open first terminal, compile and run server there - open second terminal, compile and run client there $ cc o ser fserver.c $ ./ser Server Online Sever: abc.txt is found! transferring the contents SERVER :Transfer completed Computer Science Engineering $ cc o cli fclient.c $ ./cli Client Online! CLIENT : enter the filename... abc.txt File received ..the contents are... Computer Science Engineering
Program6. Write a program for simple RSA algorithm to encrypt and decrypt the data. #include<stdio.h> int phi, M, n, e, d, C; void encrypt() { int i; C = 1; for(i=0;i< e;i++) C=C*M%n; C = C%n; printf("\n\tEncrypted keyword : %d",C); }
Aug-Nov 2012
Page 13
Program 7. Write a program for Congestion control using the leaky bucket algorithm
#include<stdio.h> #include<string.h> int min(int x,int y) { if(x<y) return x; else return y; } int main() { int drop=0,mini,nsec,cap,count=0,i,inp[25],process; system("clear"); printf("Enter The Bucket Size\n");
Dept. of CSE, NHCE Aug-Nov 2012 Page 15
Aug-Nov 2012
Page 17
Aug-Nov 2012
Page 20