01fe20bec051 208
01fe20bec051 208
6th Semester
17EECP303
Computer Communication and Networking Laboratory Journal
Demo Experiment
1.2 Aim of the experiment: Introduction to hardware components and ethernet LAN
A local area network (LAN) is a computer network that interconnects devices within a limited geographical area,
such as a home, office, or campus. LANs are typically designed using switches as the central networking device.
Switches are network devices that enable multiple devices to connect and communicate within a LAN environment.
17EECP303
Computer Communication and Networking Laboratory Journal
Experiment No: 1
1.2 Aim of the experiment: Write a C program to implement bit stuffing and de-stuffing
17EECP303
Computer Communication and Networking Laboratory Journal
1.5 Step by step procedure to carry out the experiment:
• C program is written to implement bit stuffing and de stuffing.
• Flag bits are inserted at the start and end of the data frame.
• If five consecutive 1s are encountered in data then 0 bit is inserted in bit stuffing.
• In de stuffing the 0 bit after five consecutive 1s is ignored.
• Thus, for given input data stuffed and de stuffed frames are obtained.
1.6 C Program/Commands:
#include<stdio.h>
int main()
{
int start_flag[8]={0,1,1,1,1,1,1,0};
int end_flag[8]={0,1,1,1,1,1,1,0};
int tx[10]={0,1,1,1,1,1,1,0,1,1};
int bit_stuff[26];
int temp_stuff[100];
int count=0,i=0,key=0;
int s=0;
while(i<10)
{
if(tx[i]==0)
{
temp_stuff[s]=tx[i];
s++;
count=0;
int j;
for(j=i+1;j<i+6;j++)
{
if(tx[j]==1)
{
temp_stuff[s]=tx[j];
s++;
count++;
}
else
{
break;
}
}
if(count==5)
{
key=key+1;
temp_stuff[s]=0;
17EECP303
Computer Communication and Networking Laboratory Journal
s++;
temp_stuff[s]=1;
s++;
i=j+1;
}
else{
i=j;
}
}
else
{
temp_stuff[s]=tx[i];
s++;
}
}
printf("Processed data : ");
for(int i=0;i<10+key;i++)
{
printf("%d ",temp_stuff[i]);
}
}
17EECP303
Computer Communication and Networking Laboratory Journal
Experiment No: 2
2.2 Aim of the experiment: To write a C program to implement character stuffing and de stuffing.
Byte stuffing, also known as character stuffing, is a technique used in computer networks to ensure proper data
framing and to handle control characters within the data stream. It involves the insertion of special escape characters
to mark and distinguish control characters from the actual data. Byte stuffing is primarily used to address the issue
of control characters appearing within the data stream. Control characters, such as the start and end delimiters or
reserved characters, may interfere with the interpretation of the data. Byte stuffing ensures that control characters are
properly handled and do not disrupt the integrity of the transmitted data.
Byte stuffing utilizes an escape character, which is a special character that signals the occurrence of a control
character. When a control character needs to be transmitted, it is preceded by the escape character, indicating that
the following character is not to be interpreted as a control character. In byte stuffing, the escape character is used
not only to mark control characters but also to replace them with a specific byte sequence. This replacement ensures
that control characters are distinguishable from the actual data and can be correctly interpreted by the receiving end.
On the receiving end, byte unstuffing is performed to recover the original data from the stuffed stream. The receiver
examines each character, looking for the escape character. If the escape character is found, the next character is
interpreted as a control character. If the escape character is not present, the received character is treated as part of the
data stream.
17EECP303
Computer Communication and Networking Laboratory Journal
• Flag DLE STX is inserted at the start of frame and DLE ETX is inserted at end of the data frame.
• If any of the reserved characters appear in the data then DLE is inserted before it.
• In de stuffing the first encountered DLE is ignored and the successive reserved characters are taken as data.
• Thus, for given input data stuffed and de stuffed frames are obtained.
2.6 C Program/Commands:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int j=0;
int i=0;
void main()
17EECP303
Computer Communication and Networking Laboratory Journal
char flag[]={"DLE"};
char input[100];
char arraynew[100];
char temp[4];
scanf("%s",input);
int l= strlen(input);
for(i=0;i<=l-3;i++)
temp[0]=input[i];
temp[1]=input[i+1];
temp[2]=input[i+2];
temp[3]='\0';
if(strcmp(temp,"ACK")==0 || strcmp(temp,"SYN")==0)
arraynew[j]='D';
j++;
arraynew[j]='L';
j++;
arraynew[j]='E';
j++;
17EECP303
Computer Communication and Networking Laboratory Journal
}
arraynew[j]=input[i];
j++;
arraynew[j]=input[i];
i++;
j++;
arraynew[j]=input[i];
i++;
j++;
arraynew[j]='\0';
int l1=strlen(arraynew);
char out[100];
i=0;
j=0;
for(i=0;i<=l1-3;i++)
temp[0]=arraynew[i];
temp[1]=arraynew[i+1];
temp[2]=arraynew[i+2];
temp[3]='\0';
17EECP303
Computer Communication and Networking Laboratory Journal
if(strcmp(temp,flag)==0)
i=i+3;
out[j]=arraynew[i];
j++;
out[j]=arraynew[i];
j++;i++;
out[j]=arraynew[i];
j++;i++;
out[j]='\0';
17EECP303
Computer Communication and Networking Laboratory Journal
Experiment No: 3
3.1 Title of the experiment: Cyclic Redundancy Code (CRC)
17EECP303
Computer Communication and Networking Laboratory Journal
3.6 C Program/Commands:
#include<stdio.h>
int main()
{
int flag=0;
int x,y;
printf("Enter the number of bits in divisor and input\n");
scanf("%d %d",&x,&y);
y=y+x-1;
int div[x],data[y];
printf("Enter divisor elements\n");
for(int i=0;i<x;i++)
17EECP303
Computer Communication and Networking Laboratory Journal
{
scanf("%d",&div[i]);
}
printf("Enter input elements\n");
for(int i=0;i<y;i++)
{
scanf("%d",&data[i]);
}
int j=0,k=0;
int rem[x],final[x-1];
for(int i=0;i<x;i++)
{
rem[i]=data[j];
j++;
}
int i=0;
while(1)
{
k=0;
for(i=0;i<x;i++)
{
rem[i]=div[i]^rem[i];
}
if(j==y)
break;
/*if(j==y-2){
final[0]=rem[x-1];
for(int i=1;i<x-1;i++)
{
final[i]=0;
}
break;
}*/
for(i=0;i<x;i++)
{
if(rem[i]==1)
{
break;
}
}
while(i<x)
{
rem[k]=rem[i];
k++;
i++;
}
while(k<x)
{
rem[k]=data[j];
17EECP303
Computer Communication and Networking Laboratory Journal
j++;
k++;
if(j==y) //
break; //
}
if(j==y && k!=x){
flag=1;
break;}
}
if(flag==0){
for(i=0;i<x-1;i++)
{
final[i]=rem[i+1];
}}
if(flag==1){
for(i=0;i<x-1;i++)
{
final[i]=rem[i];
}
}
printf("\nFinally reminder:\n");
for(int i=0;i<x-1;i++)
{
printf("%d ",final[i]);
}
return 0;
}
3.7 Results: (Screen Shots)
17EECP303
Computer Communication and Networking Laboratory Journal
Experiment No: 4
4.2 Aim of the experiment: To write a socket program using C to implement Echo server
Client server is a computer network architecture. Server is always on host which has permanent IP address. Client
communicates with the server and have dynamic IP address. Clients cannot communicate directly instead they can
communicate with server as mediator. It is different from P2P architecture where arbitrary end systems directly
communicate. In this experiment a socket program is written in which the message entered by the client is sent to the
server and is echoed back. This is called echo server.
17EECP303
Computer Communication and Networking Laboratory Journal
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
17EECP303
Computer Communication and Networking Laboratory Journal
#include<arpa/inet.h>
#include<stdlib.h>
#include<unistd.h>
int n;
int yes=1;
char buf[BUFLEN];
port = atoi(argv[1]);
exit(1);
17EECP303
Computer Communication and Networking Laboratory Journal
/* Fill the structure fileds with values */
server.sin_family = AF_INET;
server.sin_port = port;
server.sin_addr.s_addr =inet_addr("127.0.0.1");
perror("setsockopt");
exit(1);
exit(1);
listen(sd,5);
while(1)
17EECP303
Computer Communication and Networking Laboratory Journal
client_len = sizeof(client);
exit(1);
write(new_sd, buf,n);
close(new_sd);
close(sd);
return(0);
#include <stdio.h>
#include <netdb.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include<arpa/inet.h>
17EECP303
Computer Communication and Networking Laboratory Journal
#include<stdlib.h>
#include<unistd.h>
int n;
char buf[BUFLEN];
port=atoi(argv[1]);
exit(1);
17EECP303
Computer Communication and Networking Laboratory Journal
server.sin_family = AF_INET;
server.sin_port = port;
server.sin_addr.s_addr = inet_addr("127.0.0.1");
exit(1);
printf("Echoed Messege:\n**************\n");
printf("%s\n",buf);
close(sd);
return(0);
17EECP303
Computer Communication and Networking Laboratory Journal
4.7 Results: (Screen Shots)
Experiment No: 5
5.2 Aim of the experiment: To write a socket program using C to implement chat application
17EECP303
Computer Communication and Networking Laboratory Journal
Client-server architecture is used to build the chat application. All that is needed is a server application which can
supply the location of a specific user to a client requesting that user and a client application that will connect to a
given location for a user. Thus messages can be sent and response is given for received messages.
• The chat server and client programs are run on two different terminals.
• The server program is executed first and later the client program.
• The message entered at client is sent to server and response to it is sent back to the client.
• This continues until the server and client terminate the chat.
17EECP303
Computer Communication and Networking Laboratory Journal
5.6 C Program/Commands:
CHAT SERVER
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include<arpa/inet.h>
#include<stdlib.h>
#include<unistd.h>
#include<string.h>
#define MAX 80
int flag=0;
char buff[MAX];
int n;
for(;;)
17EECP303
Computer Communication and Networking Laboratory Journal
if(flag==1)
break;
bzero(buff,MAX);
n=read(sockfd,buff,sizeof(buff));
bzero(buff,MAX);
n=0;
//while((buff[n++]=getchar())!='\n');
fgets(buff,sizeof(buff),stdin);
n=strlen(buff);
if(strncmp("exit",buff,4)==0)
flag=1;
break;
else
write(sockfd,buff,sizeof(buff));
bzero(buff,MAX);
} // for loop
17EECP303
Computer Communication and Networking Laboratory Journal
int n;
int yes=1;
char buff[BUFLEN];
port = atoi(argv[1]);
// port=5750;
exit(1);
server.sin_family = AF_INET;
server.sin_port = port;
17EECP303
Computer Communication and Networking Laboratory Journal
server.sin_addr.s_addr =htonl(INADDR_ANY);
perror("setsockopt");
exit(1);
exit(1);
listen(sd,5);
while(1)
client_len = sizeof(client);
exit(1);
17EECP303
Computer Communication and Networking Laboratory Journal
}
func(new_sd);
close(new_sd);
close(sd);
return(0);
CHAT CLIENT
#include <stdio.h>
#include <netdb.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include<arpa/inet.h>
#include<stdlib.h>
#include<unistd.h>
#include<string.h>
#define MAX 80
17EECP303
Computer Communication and Networking Laboratory Journal
char buff[MAX];
int n;
for(;;)
bzero(buff,sizeof(buff));
n=0;
fgets(buff,sizeof(buff),stdin);
if((strncmp(buff,"exit",4))==0)
printf("Client Exit...\n");
break;
n=strlen(buff);
write(sockfd,buff,n);
bzero(buff,sizeof(buff));
read(sockfd,buff,sizeof(buff));
17EECP303
Computer Communication and Networking Laboratory Journal
int n;
char buff[BUFLEN];
port=atoi(argv[1]);
exit(1);
server.sin_family = AF_INET;
server.sin_port = port;
server.sin_addr.s_addr = inet_addr("127.0.0.1");
17EECP303
Computer Communication and Networking Laboratory Journal
/* connecting to the server */
exit(1);
func(sd);
close(sd);
return(0);
17EECP303
Computer Communication and Networking Laboratory Journal
5.8 Conclusion of the experiment:
The chat application program is thus executed and socket programming is used to implement this application. The
expected output is obtained. The client and server are made to exchange the messages.
Experiment No: 6
6.2 Aim of the experiment: To write a socket program to implement FTP server and client
17EECP303
Computer Communication and Networking Laboratory Journal
FTP stands for file transfer protocol which is protocol used to transfer file from remote host. It uses client-server
architecture. FTP host stores the file. Client logs into host and client program sends command to get a file. It uses
two ports. Port 21 for TCP control connection and Port 20 for TCP data connection. Only the data connection is
terminated after transfer of every file but the control connection exists. Thus file transfer can be achieved using this
application layer protocol
• The program is run. The input text file gets copied to another file.
6.6 C Program/Commands:
/*** SERVER ***\
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include<arpa/inet.h>
#include<stdlib.h>
17EECP303
Computer Communication and Networking Laboratory Journal
#include<unistd.h>
#include<string.h>
port = atoi(argv[1]);
// port=5750;
17EECP303
Computer Communication and Networking Laboratory Journal
{
fprintf(stderr,"can't create a socket\n");
exit(1);
}
while(1)
{
client_len = sizeof(client);
17EECP303
Computer Communication and Networking Laboratory Journal
close(new_sd);
close(sd);
return(0);
}
fputs(buf, file);
bzero(buf, sizeof(buf));
}
17EECP303
Computer Communication and Networking Laboratory Journal
int main(int argc, char **argv)
{
int n;
int sd, port;
char buf[1024];
port=atoi(argv[1]);
/* create a stream socket */
if(( sd = socket(AF_INET, SOCK_STREAM, 0)) == -1)
{
fprintf(stderr, "can't create a socket\n");
exit(1);
}
writefile(sd);
close(sd);
return(0);
}
17EECP303
Computer Communication and Networking Laboratory Journal
6.7 Results: (Screen Shots)
17EECP303
Computer Communication and Networking Laboratory Journal
File transfer protocol is implemented. The input file gets copied into the output file. Thus the FTP is realized.
Experiment No: 7
A VLAN is a logical grouping of devices within a local area network (LAN) that communicate with each other as if
they were on the same physical network, regardless of their physical location. VLANs are used to enhance network
security, improve performance, and simplify network administration. A broadcast domain is a logical division of a
computer network where all devices can directly send broadcast messages to each other. In a traditional LAN, all
devices connected to the same physical network segment belong to the same broadcast domain. VLANs help create
multiple broadcast domains within a single physical network. Devices within the same VLAN can communicate
with each other directly without the need for routing. However, for communication between VLANs, a routing
device (such as a Layer 3 switch or router) is required. Inter-VLAN communication can be achieved through various
methods, including router-on-a-stick, Layer 3 switches, or virtual routing and forwarding (VRF).
17EECP303
Computer Communication and Networking Laboratory Journal
7.6 C Program/Commands:
set vlans ccn vlan-id 55
set vlans vlsi vlan-id 66
set interfaces ge-0/0/6 unit 0 family ethernet-switching vlan members ccn
set interfaces ge-0/0/10 unit 0 family ethernet-switching vlan members vlsi
set interfaces vlan unit 55 family inet address 192.168.10.1/24
set interfaces vlan unit 66 family inet address 30.30.10.1/24
set vlans ccn l3-interface irb.55
set vlans vlsi l3-interface irb.66
set interfaces ge-0/0/23 unit 0 family init addres 20.20.20.1/30
17EECP303
Computer Communication and Networking Laboratory Journal
set routing -options static route 0.0.0.0/0 next _hop 20.20.20.2