0% found this document useful (0 votes)
2 views

Network Lab Manual

Uploaded by

smartscales7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Network Lab Manual

Uploaded by

smartscales7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 20

INDEX

PAGE
EXPNO DATE EXPERIMENT NAME SIGNATURE
NO

1 SOCKET CREATION

SIMULATION OF
2
ARP/RARP

3 BIT STUFFING

CYCLIC REDUNDANCY
4
CHECK
SIMULATION OF SLIDING
5
WINDOW PROTOCOL
OPEN SHORTEST PATH
6
FIRST ALGORITHM
SOCKET CREATION

AIM:

To write a c program to create a socket.

ALGORITHM:

Step 1: Start the program.

Step 2: Include the necessary header files.

Step 3: Declare the variable sockfd1,sockfd2.

Step 4: Define .sockfd1 as socket which transmits data as a stream of bytes.

Step 5: Define .sockfd2 as socket which transmits data as a datagram.

Step 6: Display the file discription value.

Step 7: If the sock fd2= -1 then it is not created .

Step 8: Stop the program excution.


SOCKET CREATION
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<sys/socket.h>
#include<netinet/in.h>
#include<arpa/inet.h>
int main()
{
int sockfd1,sockfd2;
sockfd1=socket(AF_INET,SOCK_STREAM,0);
sockfd2=socket(AF_INET,SOCK_DGRAM,0);
if(sockfd==1)
{
printf("socket 1is not created");
}
else
{
printf("socket 1 created and\t socket1 file descriptor value is %d\n",sockfd1);
if(sockfd2==-1)
{
printf("socket2 creation error");
}
else
{
printf("socket2 created and \t socket2 descriptor value is%d\n",sockfd2);
}
}
}

Output:

Socket 1 created and socket1 file descriptor value is 3

Socket2 created and socket2 descriptor value is4

Result:

Thus the c program for implementing socket creation has been executed and verified.
SIMULATION OF ARP/RARP

AIM:

To write a c program to create a socket.

ALGORITHM:

Step 1: Start the program.

Step 2: Include the necessary header files.

Step 3: Declare the function properties for .ARP/RARP.

Step 4: Create a file and with that file declare the physical and logical address.

Step 5: Get the choice of operation. If it is ARP show the logical address and if its RARP
display the physical address.
.

Step 6: Otherwise exit from it.

Step 7: Stop the program excution.


ARP/RARP

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct file
{
char phyadd[30];
char logadd[30];
}f[15];
File *fp
int n;
void arp(char *ladd)
{
int i;
for(i=0;i<n;i++)
{
if(strcmp,(ladd,f[i].logadd))
{
printf("\n corresponding logical address is",f[i].phyadd);
break;
}
if(i==n)
printf("the address is not found");
}
}
void rarp(char *padd)
{
int i;
for(i=0;i<n;i++)
{
if(!strcmp,(padd,f[i].phyadd))
{
printf("\n corresponding physical address is",f[i].logadd);
break;
}
}
if(i==n)
printf("the address is not found");
}

int main()
{
int i=0,ch;
char padd[30],ladd[30];
fp=fopen("data.txt","r");
if(fp=null)
{
pritnf(" \n file not found");
exit(0);
}
while(!feof(fp))
{
fscanf(fp,"%s%s",f[i].phyadd,f[i].logadd);
i++;
}
fclose(fp);
n=i;
while(1);
{
printf("\n 1.ARP \n 2.RARP \n 3.EXIT");
printf(" enter your choice");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf("enter the physical address");
scanf("%s",ladd);
arp(ladd);
break;
case 2:
printf(" enter the logical address");
scanf("%s",padd);
rarp(padd);
break;
case 3:
exit(1);
break;
}
}
return(0);
}
Output:
1. ARP
2. RARP
3. EXIT
Enter your choice: 1

Enter the physical address: 50

Corresponding logical address is: dsp

Enter your choice: 2


Enter the logical address : arun

Corresponding physical address is: 20

Enter your choice: 3


BIT STUFFING

AIM:

To write a c program to implement bit stuffing for the given bits of information.

ALGORITHM:

Step 1: Start the program execution.

Step 2: Declare the variable and obtain the information size and need it.

Step 3: Create an input file and copy the information into it.

Step 4: Create another file with read mode and check for the condition.

Step 5: Check whether five consecutive is have appeared, if appeared so print 0 as


information in the copied file.

Step 6: Finally print the information bit in the created file.

Step 7: Close all the created files.

Step 8: Stop the program execution.


BIT STUFFING

#include<stdio.h>
main()
{
int n=0,i,size;
char ch,b[100];
FILE*ed;
FILE*es;
printf("enter the bit information size:");
scanf("%d",&size);
printf("enter the bit information:");
for(i=0;i<size;i++)
{
scanf("%c",&b[i]);
}
ed=fopen("sarinput.txt","wt");
i=0;
for(i=0;i<size;i++)
{
fputc(b[i],ed);
}
fclose(ed);
ed=fopen("sarinput.txt","rt");
if(ed==NULL)
printf("\n error ");
es=fopen("saroutput.txt","wt");
ch=getc(ed);
while(ch!=EOF)
{
fputc(ch,es);
if(ch='1')
n++;
else
n=0;
if(n==5)
{
fputc('0',es);
n=0;
}
ch=getc(ed);
}
printf("\n original data");
fclose(ed);
fclose(es);
ed=fopen("sarinput.txt","rbt");
ed=fopen("saroutput","rbt");
ch=getc(ed);
while(ch!=EOF)
{
printf("%c",ch);
ch=getc(ed);
}
printf("\n data after stuffing");
ch=getc(es);
while(ch!=EOF)
{
printf("%c",ch);
ch=getc(es);
}
fclose(ed);
fclose(es);
}

output:

Enter the bit information size:6

Enter the bit information:111111

original data:
111111
data after stuffing:
1111101
Result:

Thus the program for bit stuffing is verified and written successfully.
CYCLIC REDUNDANCY CHECK

AIM:

To write a c program for cyclic redundancy check.

ALGORITHM:

Step 1: Start the program.

Step 2: Enter the dividend and the divisor.

Step 3: Perform the binary division and the CRC remainder is found.

Step 4: Append the CRC remainder with the original data.

Step 5: Stop the program.


CYCLIC REDUNDANCY CHECK

#include<stdio.h>
#include<string.h>
int main()
{
int i,j=1,k=0,m=0,divlen,len;
char orgdiv[20],dividend[20],divisor[20],zeros[10],crc[10];
printf("enter the dividend:");
scanf("%s",dividend);
printf("enter the divisor:");
scanf("%s",divisor);
divlen=strlen(divisor);
for(i=0;i<divlen-1;i++)
zeros[i]='0';
zeros[i]='\0';
strcpy(orgdiv,dividend);
strcat(dividend,zeros);
len=strlen(dividend);
while(j<=(len-divlen+1))
{
if(dividend[m]=='1')
{
for(i=0;i<divlen;i++)
{
if(dividend[i]==divisor[i])
crc[i]='0';
else
crc[i]='1';
dividend[m]=crc[i];
m++;
}
}

else
{
for(i=0;i<divlen;i++)
{
if(dividend[i]=='0')
crc[i]='0';
else
crc[i]='1';
dividend[m]=crc[i];
m++;
}
}
for(k=0;dividend[k]!='\0';k++)
dividend[k]=dividend[k+1];
m=0;
j++;
}
for(j=0;j<divlen-1;j++)
crc[j]=dividend[j];
crc[j]='\0';
printf("\n the crc is: %s",crc);
strcat(orgdiv,crc);
printf("the append data is p: %s",orgdiv);
}

Output:

Enter the dividend: 100100

Enter the divisor : 1101

The CRC is : 001

The appendend data is P : 100100001


SIMULATION OF SLIDING WINDOW PROTOCOL

AIM:

To implement the sliding window server and client using c program.

ALGORITHM:

Step 1: Start the program.

Step 2: Declare the necessary header files and variables.

Step 3: Create a socket, if not created print socket error.

Step 4: Connect the server by using the client function.

Step 5: Enter the sequence number to be sent and the current sender window.

Step 6: Stop the program.


SLIDING WINDOW
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<error.h>
#include<netdb.h>
int main()
{
int data[5],rec[5];
int m,n,a,i,c=0;
char r1[5];
printf("enter the choice:\n");
printf("1.select reject \n");
printf("2.go backn \n");
scanf("%d",&a);
printf("enter the size of the data");
scanf("%d",&n);
printf("enter the data one by one:");
for(i=0;i<n;i++)
{
scanf("%d",&data[i]);
}
switch(a)
{
case 1:
{
printf("data is ready to send:\n");
for(i=0;i<n;i++)
{
rec[i]=data[i];
printf("%d is sent \n",data[i]);
scanf("%s",r1);
if(strcmp(r1,"n"))
printf("ack is rec %d n",i+1);
else
{
c++;
}
}
if(c!=0)
{
printf("enter the position of the data to be sent again:");
scanf("%d",&m);
while(m>n)
{

printf("\n wrong choice");


printf("\n enter the position of the data again");
scanf("%d",&m);
}
if(a==1)
{
printf("/n%d is sent again\n",data[m-1]);
}
}
return 0;
}
case 2:
{
for(i=0;i<n;i++)
{
rec[i]=data[i];
printf("%d is sent\n",data[i]);
scanf("%s",r1);
if(strcmp(r1,"n"))
printf("ack is rec%d\n",i);
else
{
c++;
}
if(c!=0){
printf("enter the starting position of data to be sent again");
scanf("%d",&m);
for(i=m-1;i<n;i++)
{
rec[i]=data[i];
printf("%d is sent\n",data[i]);
scanf("%s",r1);
}
}
}
}
}
return(0);
}
output:
enter the choice:
1.select reject
2.go backn
1
enter the size of the data: 3
enter the data one by one:
1
2
3
data is ready to send:
1 is sent
a
ack is rec 1
2 is sent
n
3 is sent
a
ack is rec 1
enter the position of the data to be sent again:2
2 is sent again
enter the choice:
1.select reject
2.go backn
2
enter the size of the data3
enter the data one by one:
3
4
5
3 is sent
a
ack is rec 0
4 is sent
n
enter the starting position of data to be sent again2
4 is sent
a
5 is sent
a
Result:

Thus the program for sliding window protocol is verified and written successfully.
OPEN SHORTEST PATH FIRST ALGORITHM

AIM:

To write a c++ program for open shortest path between server and destination
Node.

ALGORITHM:

Step 1: Start the program.

Step 2: Include the necessary header files.

Step 3: Declare the variable functions.

Step 4: Get the Number of nodes and the cost of the edge between various nodes.

Step 5: Enter the source and destination nodes.

Step 6: Find the shortest path between source and destination node.

Step 7: Stop the program excution.


OSPF
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
class path
{
int a[10][10],c[10[10],key[10][10],num,min,i,j,k;
public:
void findpath();
void read();
void output(int,int);
void out(int i, int j);
};
void path::read()
{
cout<<”Number of nodes:”;
cin>>num;
for(i=1;i<=num;i++)
for(j=1;j<=nump;j++)
{
if(i==j)
a[i][j]=0;
else
{
cout<<”The cost for[“<<i<<”,”<<j<<”];
cin>>a[i][j];
}
c[i][j]=a[i][j];
key[i][j]=0;
}
}
void path::findpath()
{
int t1,t2,t3;
for(k=1;k<=num;k++)
for(i=1;i<=num;i++)
for(j=1;j<=num;j++)
{
t1=c[i][k];
t2=c[k][j];
t3=c[i][j];
if(t1!=0 &&t2!=0 && (t3==0||t1+t2<t3))
{
c[i][j]=t1+t2;
key[i][j]=k;
}
}
}
void path::output(int i, int j)
{
min=0;
if(c[i][j]==0)
{
cout<<”no path exist”;
return;
}
else
{
cout<<”The path is :”<<i;
out(i,j);
cout<<end1<<”cost is :”<<min;
cout<<”\n”;
}
}
void path :: out(int i, int j)
{
if(i==j)
return;
if(key[i][j]==0)
{
cout<<”->”<<j;
min+=a[i][j];
}
else
{
out(i,key[i][j]);
out(key[i][j],j);
}
}
void main()
{
clrscr();
int ch=1,n1,n2;
path p;
p.read();
p.findpath();
cout<<end1<<”1.Shortest path”<<end1;
cout<<”2.Exit”<<end1;
while(ch!=2)
{
cout<<end1<<”choice…..”;
cin>>ch;
switch(ch)
{
case 1:
cout<<”enter the source node”;
cin>>n1;
cout<<”enter the destination node”;
cin>>n2;
p.output(n1,n2);
break;
case 2:
exit(0);
}
}
getch();
}

Output:

Number of nodes : 3

The cost for [1,2] : 1

The cost for [1,3] : 4

The cost for [2,1] : 2

The cost for [2,3] : 2

The cost for [3,1] : 2

The cost for [3,2] : 1

1.shortest path
2.exit

Choice……….. 1

Enter the source code : 1


Enter the destination code : 3
The path is 1 -> 2 ->3
Cost is 3

Choice……….. 2

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy