0% found this document useful (0 votes)
29 views41 pages

01fe20bec051 208

The document describes experiments on bit stuffing and byte stuffing techniques used in computer networks. It includes the theoretical background, block diagrams, procedures and C programs to implement bit stuffing and de-stuffing. It also describes an experiment on byte stuffing and de-stuffing with the aim to write a C program for the same.

Uploaded by

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

01fe20bec051 208

The document describes experiments on bit stuffing and byte stuffing techniques used in computer networks. It includes the theoretical background, block diagrams, procedures and C programs to implement bit stuffing and de-stuffing. It also describes an experiment on byte stuffing and de-stuffing with the aim to write a C program for the same.

Uploaded by

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

, Hubballi-31

KLE Technological University


School of Electronics and Communication Engineering

Computer Communication and Networking Laboratory Journal

Course code: 17EECP303

6th Semester

Name: Prajwal G Kodihalli


USN: 01FE20BEC051

Computer Communication and Networking Lab


SCHOOL OF ELECTRONICS ENGINEERING
Program: Electronics and Communication

17EECP303
Computer Communication and Networking Laboratory Journal

Demo Experiment

1.1 Title of the experiment: Lan Setup

1.2 Aim of the experiment: Introduction to hardware components and ethernet LAN

1.3 Theoretical background for the experiment:

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.

1.4 Block Diagram:

1.5 Step by step procedure to carry out the experiment:


 Determine LAN Requirements
 Choose the Switch
 Plan the Network Topology
 Prepare the Cabling
 Connect the Switch
 Connect Devices to the Switch
 Configure IP Addresses
 Test Connectivity

1.6 Conclusion of the experiment:


In conclusion, the LAN setup experiment using a switch and LAN cables is a straightforward process involving
equipment selection, device connectivity, network configuration, and testing. By following the steps outlined, a
functional LAN can be established

Computer Communication and Networking Lab 1


SCHOOL OF ELECTRONICS ENGINEERING
Program: Electronics and Communication

17EECP303
Computer Communication and Networking Laboratory Journal
Experiment No: 1

1.1 Title of the experiment: Bit Stuffing

1.2 Aim of the experiment: Write a C program to implement bit stuffing and de-stuffing

1.3 Theoretical background for the experiment:


Bit stuffing is a technique used in computer networks to ensure proper synchronization and error detection
during data transmission. It involves the insertion of extra bits into the data stream to prevent specific bit
patterns from being misinterpreted as control characters or special sequences. Bit stuffing is primarily used to
achieve data transparency, which means that the data being transmitted is free from any patterns that might be
interpreted as control characters by the network hardware or protocols. It ensures the integrity and accurate
reception of data.
Bit stuffing is typically applied between start and end delimiters. These delimiters mark the beginning and end
of a data frame or packet. Bit stuffing ensures that the data does not contain the same bit pattern as the
delimiter, which helps the receiver correctly identify the frame boundaries. The stuffing rule specifies when and
where to insert the extra bits. A common stuffing rule is to insert an extra '0' bit after every consecutive
sequence of five '1' bits. This ensures that the receiver can distinguish between a legitimate sequence of '1' bits
and a stuffed '1' bit.
On the receiving end, the stuffed bits need to be removed to extract the original data. The receiver follows the
reverse process by examining consecutive sequences of '1' bits and removing the following '0' bit.
1.4 Block Diagram:

Computer Communication and Networking Lab 2


SCHOOL OF ELECTRONICS ENGINEERING
Program: Electronics and Communication

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;

Computer Communication and Networking Lab 3


SCHOOL OF ELECTRONICS ENGINEERING
Program: Electronics and Communication

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]);
}
}

1.7 Results: (Screen Shots)

1.8 Conclusion of the experiment:


The Bit stuffing and de stuffing is implemented for the input data given. The output is verified for the various
input data. Thus, bit stuffing is used to synchronize data at the transmitter and receiver. The applications of bit
stuffing are to synchronize several channels before multiplexing. It is also used in CAN, HDLC and USB.

Computer Communication and Networking Lab 4


SCHOOL OF ELECTRONICS ENGINEERING
Program: Electronics and Communication

17EECP303
Computer Communication and Networking Laboratory Journal

Experiment No: 2

2.1 Title of the experiment: Byte Stuffing

2.2 Aim of the experiment: To write a C program to implement character stuffing and de stuffing.

2.3 Theoretical background for the experiment:

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.

2.4 Block Diagram:

Computer Communication and Networking Lab 5


SCHOOL OF ELECTRONICS ENGINEERING
Program: Electronics and Communication

17EECP303
Computer Communication and Networking Laboratory Journal

2.5 Step by step procedure to carry out the experiment:

• C program is written to implement character stuffing and de stuffing.

• 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()

Computer Communication and Networking Lab 6


SCHOOL OF ELECTRONICS ENGINEERING
Program: Electronics and Communication

17EECP303
Computer Communication and Networking Laboratory Journal
char flag[]={"DLE"};

char input[100];

char arraynew[100];

char temp[4];

printf("enter the string\n");

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++;

Computer Communication and Networking Lab 7


SCHOOL OF ELECTRONICS ENGINEERING
Program: Electronics and Communication

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';

printf("the input array was %s\n",input);

printf("the stuffed array is %s",arraynew);

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';

Computer Communication and Networking Lab 8


SCHOOL OF ELECTRONICS ENGINEERING
Program: Electronics and Communication

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';

printf("the destuffed array is %s",out);

2.7 Results: (Screen Shots)

2.8 Conclusion of the experiment:


The character stuffing and de stuffing is implemented for the input data given. The output is verified for the various
input data. Thus, character stuffing is used to synchronize data at the transmitter and receiver. As most computer
networks cannot reserve characters for use by the network it is not preferably used.

Computer Communication and Networking Lab 9


SCHOOL OF ELECTRONICS ENGINEERING
Program: Electronics and Communication

17EECP303
Computer Communication and Networking Laboratory Journal

Experiment No: 3
3.1 Title of the experiment: Cyclic Redundancy Code (CRC)

3.2 Aim of the experiment: To write a C program to implement CRC

3.3 Theoretical background for the experiment:


CRC (Cyclic Redundancy Check) is an error detection algorithm commonly used in computer networks to verify the
integrity of transmitted data. CRC is used to detect errors introduced during data transmission, such as bit flips,
noise, or data corruption. It calculates a checksum or hash value based on the data being transmitted and appends it
to the data. The receiver performs the same calculation on the received data and compares the calculated checksum
with the received checksum to detect any discrepancies.
CRC operates by performing polynomial division on the data bits using a predetermined polynomial called the
generator polynomial. The generator polynomial represents the characteristics of the CRC algorithm and is known to
both the sender and receiver. The selection of an appropriate generator polynomial is crucial for the effectiveness of
CRC. Commonly used generator polynomials include CRC-16, CRC-32, and CRC-CCITT. The choice of the
generator polynomial depends on factors such as the desired level of error detection and the expected characteristics
of the data being transmitted.
The sender divides the data by the generator polynomial, resulting in a remainder. This remainder, also known as the
CRC checksum, is appended to the data before transmission. The checksum is calculated by performing binary
division, applying bitwise XOR operations on the data bits and the generator polynomial. On the receiving end, the
received data is divided by the same generator polynomial. If the remainder obtained during the division process is
zero, the data is considered error-free. If the remainder is non-zero, it indicates the presence of errors in the data.

3.4 Block Diagram:

Computer Communication and Networking Lab 10


SCHOOL OF ELECTRONICS ENGINEERING
Program: Electronics and Communication

17EECP303
Computer Communication and Networking Laboratory Journal

3.5 Step by step procedure to carry out the experiment:


 Start
 Enter the message to be transmitted
 Append the message with 16(since it is 16-bit CRC) 0`s (i.e. if you input a 5 digit message, the appended
message should be 21-bits.)
 XOR appended message and transmit it.(Here, you compare with an already existing string such as
10001000000100001 and replace the bits the same way XOR operation works)
 Verify the message that is received is the same as the one sent.
 End

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++)

Computer Communication and Networking Lab 11


SCHOOL OF ELECTRONICS ENGINEERING
Program: Electronics and Communication

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];

Computer Communication and Networking Lab 12


SCHOOL OF ELECTRONICS ENGINEERING
Program: Electronics and Communication

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)

3.8 Conclusion of the experiment:


The CRC is implemented for the input data given. The output is verified for the various input data. Thus CRC is
used for error detection. It is widely used in communication system and the data is queried to be retransmitted if the
check values do not match at the receiver.

Computer Communication and Networking Lab 13


SCHOOL OF ELECTRONICS ENGINEERING
Program: Electronics and Communication

17EECP303
Computer Communication and Networking Laboratory Journal

Experiment No: 4

4.1 Title of the experiment: Echo Server

4.2 Aim of the experiment: To write a socket program using C to implement Echo server

4.3 Theoretical background for the experiment:

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.

4.4 Block Diagram:

Computer Communication and Networking Lab 14


SCHOOL OF ELECTRONICS ENGINEERING
Program: Electronics and Communication

17EECP303
Computer Communication and Networking Laboratory Journal

4.5 Step by step procedure to carry out the experiment:


• Socket program is written to implement the echo-server.
• The server and client programs are run on two different terminals.
• The server program is executed first and later the client program.
• The message is entered at the client end and it is sent to server which gets echoed back at the receiver.
4.6 C Program/Commands:

/******* SERVER ********\

#include <stdio.h>

#include <sys/types.h>

#include <sys/socket.h>

#include <netinet/in.h>

Computer Communication and Networking Lab 15


SCHOOL OF ELECTRONICS ENGINEERING
Program: Electronics and Communication

17EECP303
Computer Communication and Networking Laboratory Journal
#include<arpa/inet.h>

#include<stdlib.h>

#include<unistd.h>

#define BUFLEN 1024 /* buffer length */

int main(int argc, char **argv)

int n;

int yes=1;

int sd, new_sd, client_len, port;

struct sockaddr_in server, client;

char buf[BUFLEN];

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);

Computer Communication and Networking Lab 16


SCHOOL OF ELECTRONICS ENGINEERING
Program: Electronics and Communication

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");

// Reuse the port and address

if (setsockopt(sd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)) == -1) {

perror("setsockopt");

exit(1);

/* bind an address to the socket */

if(bind(sd, (struct sockaddr *)&server, sizeof(server)) == -1)

fprintf(stderr, "can't bind name to socket\n");

exit(1);

/* queue up to 5 connect requests */

listen(sd,5);

while(1)

Computer Communication and Networking Lab 17


SCHOOL OF ELECTRONICS ENGINEERING
Program: Electronics and Communication

17EECP303
Computer Communication and Networking Laboratory Journal
client_len = sizeof(client);

if((new_sd = accept(sd, (struct sockaddr *) &client, &client_len)) == -1)

fprintf(stderr, "can't accept client \n");

exit(1);

n = read(new_sd, buf, sizeof(buf));

printf("The message received by client : %s\n",buf);

write(new_sd, buf,n);

close(new_sd);

close(sd);

return(0);

/***** CLIENT ******\

#include <stdio.h>

#include <netdb.h>

#include <sys/types.h>

#include <sys/socket.h>

#include <netinet/in.h>

#include<arpa/inet.h>

Computer Communication and Networking Lab 18


SCHOOL OF ELECTRONICS ENGINEERING
Program: Electronics and Communication

17EECP303
Computer Communication and Networking Laboratory Journal
#include<stdlib.h>

#include<unistd.h>

#define BUFLEN 1024 /* buffer length */

int main(int argc, char **argv)

int n;

int sd, port;

char buf[BUFLEN];

struct sockaddr_in server;

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);

// bzero((char *)&server, sizeof(struct sockaddr_in));

Computer Communication and Networking Lab 19


SCHOOL OF ELECTRONICS ENGINEERING
Program: Electronics and Communication

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");

/* connecting to the server */

if(connect(sd, (struct sockaddr *)&server, sizeof(server)) == -1)

fprintf(stderr, "can't connect\n");

exit(1);

printf("Enter the message to be echoed: ");

scanf("%s",buf); /* get user's text */

write(sd, buf, BUFLEN); /* send it out */

printf("Echoed Messege:\n**************\n");

n = read(sd, buf, sizeof(buf));

printf("%s\n",buf);

close(sd);

return(0);

Computer Communication and Networking Lab 20


SCHOOL OF ELECTRONICS ENGINEERING
Program: Electronics and Communication

17EECP303
Computer Communication and Networking Laboratory Journal
4.7 Results: (Screen Shots)

4.8 Conclusion of the experiment:


The echo server program is thus executed and socket programming is used to implement it. The output is obtained and
the program is checked by sending and receiving different messages.

Experiment No: 5

5.1 Title of the experiment: Chat application

5.2 Aim of the experiment: To write a socket program using C to implement chat application

5.3 Theoretical background for the experiment:

Computer Communication and Networking Lab 21


SCHOOL OF ELECTRONICS ENGINEERING
Program: Electronics and Communication

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.

5.4 Block Diagram:

5.5 Step by step procedure to carry out the experiment:

• Socket program is written to implement the chat application.

• 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.

Computer Communication and Networking Lab 22


SCHOOL OF ELECTRONICS ENGINEERING
Program: Electronics and Communication

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 SERVER_TCP_PORT 5750 /* well known port */

#define BUFLEN 256 /* buffer length */

#define MAX 80

int flag=0;

int func(int sockfd)

char buff[MAX];

int n;

for(;;)

Computer Communication and Networking Lab 23


SCHOOL OF ELECTRONICS ENGINEERING
Program: Electronics and Communication

17EECP303
Computer Communication and Networking Laboratory Journal
if(flag==1)

break;

bzero(buff,MAX);

n=read(sockfd,buff,sizeof(buff));

printf("Message from client is:%s",buff);

bzero(buff,MAX);

n=0;

//while((buff[n++]=getchar())!='\n');

printf("Enter message to be sent to client:\n");

fgets(buff,sizeof(buff),stdin);

n=strlen(buff);

if(strncmp("exit",buff,4)==0)

printf("Server Exit ...\n");

flag=1;

break;

else

write(sockfd,buff,sizeof(buff));

bzero(buff,MAX);

} // for loop

Computer Communication and Networking Lab 24


SCHOOL OF ELECTRONICS ENGINEERING
Program: Electronics and Communication

17EECP303
Computer Communication and Networking Laboratory Journal

int main(int argc, char **argv)

int n;

int yes=1;

int sd, new_sd, client_len, port;

struct sockaddr_in server, client;

char buff[BUFLEN];

port = atoi(argv[1]);

// port=5750;

/* create a stream socket */

if((sd = socket(AF_INET, SOCK_STREAM, 0)) == -1)

fprintf(stderr,"can't create a socket\n");

exit(1);

/* bind an address to the socket */

// bzero((char *)&server, sizeof(struct sockaddr_in));

server.sin_family = AF_INET;

server.sin_port = port;

Computer Communication and Networking Lab 25


SCHOOL OF ELECTRONICS ENGINEERING
Program: Electronics and Communication

17EECP303
Computer Communication and Networking Laboratory Journal
server.sin_addr.s_addr =htonl(INADDR_ANY);

if (setsockopt(sd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)) == -1) {

perror("setsockopt");

exit(1);

if(bind(sd, (struct sockaddr *)&server, sizeof(server)) == -1)

fprintf(stderr, "can't bind name to socket\n");

exit(1);

/* queue up to 5 connect requests */

listen(sd,5);

while(1)

client_len = sizeof(client);

if((new_sd = accept(sd, (struct sockaddr *) &client, &client_len)) == -1)

fprintf(stderr, "can't accept client\n");

exit(1);

Computer Communication and Networking Lab 26


SCHOOL OF ELECTRONICS ENGINEERING
Program: Electronics and Communication

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 BUFLEN 256 /* buffer length */

#define MAX 80

Computer Communication and Networking Lab 27


SCHOOL OF ELECTRONICS ENGINEERING
Program: Electronics and Communication

17EECP303
Computer Communication and Networking Laboratory Journal

void func(int sockfd)

char buff[MAX];

int n;

for(;;)

bzero(buff,sizeof(buff));

printf("Enter the message to be sent: ");

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));

printf("Message from Server : %s",buff);

Computer Communication and Networking Lab 28


SCHOOL OF ELECTRONICS ENGINEERING
Program: Electronics and Communication

17EECP303
Computer Communication and Networking Laboratory Journal

int main(int argc, char **argv)

int n;

int sd, port;

char buff[BUFLEN];

struct sockaddr_in server;

//command line argument

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);

// bzero((char *)&server, sizeof(struct sockaddr_in));

server.sin_family = AF_INET;

server.sin_port = port;

server.sin_addr.s_addr = inet_addr("127.0.0.1");

Computer Communication and Networking Lab 29


SCHOOL OF ELECTRONICS ENGINEERING
Program: Electronics and Communication

17EECP303
Computer Communication and Networking Laboratory Journal
/* connecting to the server */

if(connect(sd, (struct sockaddr *)&server, sizeof(server)) == -1)

fprintf(stderr, "can't connect\n");

exit(1);

func(sd);

close(sd);

return(0);

5.7 Results: (Screen Shots)

Computer Communication and Networking Lab 30


SCHOOL OF ELECTRONICS ENGINEERING
Program: Electronics and Communication

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.1 Title of the experiment: File Transfer Protocol

6.2 Aim of the experiment: To write a socket program to implement FTP server and client

6.3 Theoretical background for the experiment:

Computer Communication and Networking Lab 31


SCHOOL OF ELECTRONICS ENGINEERING
Program: Electronics and Communication

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

6.4 Block Diagram:

6.5 Step by step procedure to carry out the experiment:

• Socket program is written to implement FTP.

• A text file is created in the same folder containing the program.

• The program is run. The input text file gets copied to another file.

• Thus, FTP is realized.

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>

Computer Communication and Networking Lab 32


SCHOOL OF ELECTRONICS ENGINEERING
Program: Electronics and Communication

17EECP303
Computer Communication and Networking Laboratory Journal
#include<unistd.h>
#include<string.h>

#define CHUNK 1024 /* read 1024 bytes at a time */

void readfile(int new_sd)


{
char buf[CHUNK];
int n;
FILE *file;

file = fopen("test1.txt", "r");


if(file ==NULL)
{
printf("\n Error in opening a file");
}
else
{
while(fgets(buf, sizeof(buf), file) !=NULL)
{
n=strlen(buf);
write(new_sd, buf,n);
bzero(buf, sizeof(buf));
}
}
fclose(file);
}

int main(int argc, char **argv)


{
int n;
int yes=1;
int sd, new_sd, client_len, port;
struct sockaddr_in server, client;
char buf[1024];

port = atoi(argv[1]);
// port=5750;

/* create a stream socket */


if((sd = socket(AF_INET, SOCK_STREAM, 0)) == -1)

Computer Communication and Networking Lab 33


SCHOOL OF ELECTRONICS ENGINEERING
Program: Electronics and Communication

17EECP303
Computer Communication and Networking Laboratory Journal
{
fprintf(stderr,"can't create a socket\n");
exit(1);
}

/* bind an address to the socket */


// bzero((char *)&server, sizeof(struct sockaddr_in));
server.sin_family = AF_INET;
server.sin_port = port;
server.sin_addr.s_addr =inet_addr("127.0.0.1");

if (setsockopt(sd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)) == -1) {


perror("setsockopt");
exit(1);
}

if(bind(sd, (struct sockaddr *)&server, sizeof(server)) == -1)


{
fprintf(stderr, "can't bind name to socket\n");
exit(1);
}

/* queue up to 5 connect requests */


listen(sd,5);

while(1)
{
client_len = sizeof(client);

if((new_sd = accept(sd, (struct sockaddr *) &client, &client_len)) == -1)


{
fprintf(stderr, "can't accept client\n");
exit(1);
}

n = read(new_sd, buf, sizeof(buf));


//printf("The message received by client : %s \n",buf);
//write(new_sd, buf,n);
readfile(new_sd);

Computer Communication and Networking Lab 34


SCHOOL OF ELECTRONICS ENGINEERING
Program: Electronics and Communication

17EECP303
Computer Communication and Networking Laboratory Journal

close(new_sd);

close(sd);
return(0);
}

/**** 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 CHUNK 1024

void writefile(int sd)


{
char buf[CHUNK];
int n,i;
FILE *file;

file = fopen("temp.txt", "w");


if(file==NULL)
{
printf("\n Error in opening a file");
}
while( (read(sd, buf, sizeof(buf))) > 0)
{

fputs(buf, file);
bzero(buf, sizeof(buf));
}

Computer Communication and Networking Lab 35


SCHOOL OF ELECTRONICS ENGINEERING
Program: Electronics and Communication

17EECP303
Computer Communication and Networking Laboratory Journal
int main(int argc, char **argv)
{
int n;
int sd, port;
char buf[1024];

struct sockaddr_in server;

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);
}

// bzero((char *)&server, sizeof(struct sockaddr_in));


server.sin_family = AF_INET;
server.sin_port = port;
server.sin_addr.s_addr = inet_addr("127.0.0.1");

/* connecting to the server */


if(connect(sd, (struct sockaddr *)&server, sizeof(server)) == -1)
{
fprintf(stderr, "can't connect\n");
exit(1);
}

printf("\n Enter the command");


scanf("%s",buf); /* get user's text */
write(sd, buf, sizeof(buf)); /* send it out */
//printf("\n\nEchoed Messege:\n**************\n");

// n = read(sd, buf, sizeof(buf));


// printf("%s\n\n\n",buf);

writefile(sd);
close(sd);
return(0);
}

Computer Communication and Networking Lab 36


SCHOOL OF ELECTRONICS ENGINEERING
Program: Electronics and Communication

17EECP303
Computer Communication and Networking Laboratory Journal
6.7 Results: (Screen Shots)

Computer Communication and Networking Lab 37


SCHOOL OF ELECTRONICS ENGINEERING
Program: Electronics and Communication

17EECP303
Computer Communication and Networking Laboratory Journal

6.8 Conclusion of the experiment:

File transfer protocol is implemented. The input file gets copied into the output file. Thus the FTP is realized.

Experiment No: 7

7.1 Title of the experiment: VLAN Setup 1

7.2 Aim of the experiment: Setting up VLAN using Switch

7.3 Theoretical background for the experiment:

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).

7.4 Block Diagram:

Computer Communication and Networking Lab 38


SCHOOL OF ELECTRONICS ENGINEERING
Program: Electronics and Communication

17EECP303
Computer Communication and Networking Laboratory Journal

7.5 Step by step procedure to carry out the experiment:


 Identify VLAN Requirements
 Access the Switch Configuration Interface
 Create VLANs
 Assign Ports to VLANs
 Verify VLAN Configuration
 Test VLAN Connectivity

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

Computer Communication and Networking Lab 39


SCHOOL OF ELECTRONICS ENGINEERING
Program: Electronics and Communication

17EECP303
Computer Communication and Networking Laboratory Journal
 set routing -options static route 0.0.0.0/0 next _hop 20.20.20.2

7.7 Conclusion of the experiment:


The VLAN setup experiment provided hands-on experience in configuring and implementing VLANs within a
network infrastructure. It highlighted the importance of proper VLAN configuration, VLAN membership
assignment and inter-VLAN communication.

Computer Communication and Networking Lab 40

You might also like