Sei sulla pagina 1di 36

Issue No.

: Date:
Computer Networks (CS203) Rev No.: Nil Rev. Date: Nil
Clause: Nil Page: 1 of 36
Lab Manual

DIT UNIVERSITY DEHRADUN


DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

Lab Manual for the Academic Year 2018-19

Subject : Computer Networks Lab


Subject code : CS203
Course coordinator : Dr Aditya K Saxena
HOD : Dr Vishal Bharti

Prepared by: Reviewed by: Approved by:


Dr Aditya K Saxena
Issue No.: Date:
Computer Networks (CS203) Rev No.: Nil Rev. Date: Nil
Clause: Nil Page: 2 of 36
Lab Manual

Table of Contents

S. No Content Page No.

1 System Requirements 5

2 Lab Objectives 5

Experiment Manual

Experiment Title of experiment


Page No.
No.
Simulate a network having two communication node using Cisco
1 6
packet Tracer.
Simulate a network having two communication node with one
2 7
switch(no intelligent).
Simulate a network having Two subnet using 2 switch, 2
3 Routers and 4 nodes using cisco packet tracer. 8

Create a DHCP server using cisco packet tracer.


4 10
Simulate a network using Star Topology Using Cisco packet
5 Tracer. 12

Simulate a network using Bus Topology Using Cisco packet


6 Tracer. 13

Simulate a network using Ring Topology Using Cisco packet


7 Tracer. 14

Simulate a network using Mesh Topology Using Cisco packet


8 Trace. 15

Implement NAT(network address translation) using Cisco


9 Packet Tracker 16

Create a DNS server using cisco packet tracer.


10 20

Prepared by: Reviewed by: Approved by:


Dr Aditya K Saxena
Issue No.: Date:
Computer Networks (CS203) Rev No.: Nil Rev. Date: Nil
Clause: Nil Page: 3 of 36
Lab Manual

Implement Bit Stuffing using C.


11 23
Implement Character Stuffing using C.
12 26
Implement Error detection method CRC using C.
13 28
Implement Error detection method Checksum using C.
14 33

Prepared by: Reviewed by: Approved by:


Dr Aditya K Saxena
Issue No.: Date:
Computer Networks (CS203) Rev No.: Nil Rev. Date: Nil
Clause: Nil Page: 4 of 36
Lab Manual

GENERAL INSTRUCTIONS FOR LABORATORY CLASSES:-


DO’S

(1) Without Prior permission do not enter into the Laboratory.

(2) While entering into the LAB students should carry ID cards.

(3) The Students should come with proper uniform.

(4) Students should come with the record note book into the laboratory.

(5) Students should maintain silence inside the laboratory.

(6) After completing the laboratory exercise, make sure to shut-down the system properly.

DONT’S

(1) Students bringing the bags inside the laboratory.

(2) Students wearing slippers/shoes insides the laboratory.

(3) Students using the computers in an improper way.

(4) Students bringing pen drive or other secondary storage device inside the laboratory.

(5) Students using mobile phones inside the laboratory.

(6) Students making noise inside the laboratory.

Prepared by: Reviewed by: Approved by:


Dr Aditya K Saxena
Issue No.: Date:
Computer Networks (CS203) Rev No.: Nil Rev. Date: Nil
Clause: Nil Page: 5 of 36
Lab Manual

System Requirements

1. Intel based desktop PC of 2 GHz or faster processor with at least 2 GB RAM and 500 MB

free disk space.

2. Need of networking tool for simulation of network using Cisco packet Tracer, Network

simulator 2.0

Lab Objectives

1. The overall goal of the field of Computer network is to study different types of protocol
standard and network model, simulate with the help of simulator.
2. The student will learn what is the roll of layered architecture of protocol of reliable
communication.
3. Student will learn the layered architecture of OSI and TCP/IP model and detail study of each
layer responsibility.
4. The student will get practical experiences of protocol standard of each layer by
implementing, debugging and testing in Programming language like C and C++ (during the
Lab).

Prepared by: Reviewed by: Approved by:


Dr Aditya K Saxena
Issue No.: Date:
Computer Networks (CS203) Rev No.: Nil Rev. Date: Nil
Clause: Nil Page: 6 of 36
Lab Manual

Practical - 1

Aim: Simulate a network having two communication node using Cisco


packet Tracer

Devices Used: Generic PCs, Cross-Over Cable

IP Configuration:
Generic PC1: 169.254.90.147
Generic PC2: 169.254.155.23
Subnet Mask: 255.255.0.0
CIDR: /16

OUTPUT

Prepared by: Reviewed by: Approved by:


Dr Aditya K Saxena
Issue No.: Date:
Computer Networks (CS203) Rev No.: Nil Rev. Date: Nil
Clause: Nil Page: 7 of 36
Lab Manual

Practical - 2

Aim: Simulate a network having two communication node in Cisco


packet Tracer using a Switch.

Devices Used: Generic PCs, Switch, Straight-Through Cable


IP Configuration:
Generic PC1: 169.254.90.147
Generic PC2: 169.254.155.23
Subnet Mask: 255.255.0.0
CIDR: /16

OUTPUT

Prepared by: Reviewed by: Approved by:


Dr Aditya K Saxena
Issue No.: Date:
Computer Networks (CS203) Rev No.: Nil Rev. Date: Nil
Clause: Nil Page: 8 of 36
Lab Manual

Practical - 3

Aim: Simulate a network having two subnets in Cisco packet Tracer using 2
routers and 2 switches

Devices Used- 4 generic PC, 2 Switch, 2 generic routers, straight through cable and dotted
Cable.

IP Configuration-
Generic PCO : 192.168.1.2
Generic PC1 : 192.168.1.3
Generic PC2 : 192.168.3.2
Generic PC3 : 192.168.3.3
Subnet Mask : 255.255.255.0
CIDR : /24
IP at fa0/0 : 192.168.2.2
Router0 fa1/0 : 192.168.1.1
IP at fa0/0 : 192.168.2.3
Router1 fa1/0 : 192.168.3.1

Commands used at Router0 :


Router>en
Router#config t
Router(config)#int fa0/0
Router(config-if)#ip address 192.168.2.2 255.255.255.0
Router(config-if)#no sh
Router(config-if)#exit
Router(config)#int fa1/0
Router(config-if)#ip address 192.168.1.1 255.255.255.0
Router(config-if)#no sh
Router(config-if)#exit
Router(config)#ip route 192.168.3.0 255.255.255.0 192.168.2.3
Prepared by: Reviewed by: Approved by:
Dr Aditya K Saxena
Issue No.: Date:
Computer Networks (CS203) Rev No.: Nil Rev. Date: Nil
Clause: Nil Page: 9 of 36
Lab Manual

Commands used at Router1 :


Router>en
Router#config t
Router(config)#int fa0/0
Router(config-if)#ip address 192.168.2.3 255.255.255.0
Router(config-if)#no sh
Router(config-if)#exit
Router(config)#int fa1/0
Router(config-if)#ip address 192.168.3.1 255.255.255.0
Router(config-if)#no sh
Router(config-if)#exit
Router(config)#ip route 192.168.1.0 255.255.255.0 192.168.2.2

OUTPUT

Prepared by: Reviewed by: Approved by:


Dr Aditya K Saxena
Issue No.: Date:
Computer Networks (CS203) Rev No.: Nil Rev. Date: Nil
Clause: Nil Page: 10 of 36
Lab Manual

Practical - 4

Aim: Create a DHCP server using cisco packet tracer


Devices Used- 4 generic PC, 2 Switch, 2 generic routers, straight through cable and dotted
Cable.

IP Configuration-
CIDR : /24
IP at fa1/0 : 172.16.1.1
Router0 fa0/0 : 192.168.1.1
IP at fa1/0 : 172.16.1.2
Router1 fa1/0 : 192.168.3.1

Commands used at Router0:


Router>en
Router#config t
Router(config)#int fa1/0
Router(config-if)#ip address 172.16.1.1 255.255.255.0
Router(config-if)#no sh
Router(config-if)#exit
Router(config)#int fa0/0
Router(config-if)#ip address 192.168.1.1 255.255.255.0
Router(config-if)#no sh
Router(config-if)#exit
Router(config)#ip route 192.168.3.0 255.255.255.0 172.16.1.2
Router(config)#ip dhcp excluded-address 192.168.1.1
Router(config)#ip dhcp pool internal-LAN
Router(dhcp-config)#network 192.168.1.0 255.255.255.0
Router(dhcp-config)#default-router 192.168.1.1
Router(dhcp-config)#exit

Commands used at Router1 :


Router>en
Router#config t
Router(config)#int fa1/0
Router(config-if)#ip address 172.16.1.2 255.255.255.0
Prepared by: Reviewed by: Approved by:
Dr Aditya K Saxena
Issue No.: Date:
Computer Networks (CS203) Rev No.: Nil Rev. Date: Nil
Clause: Nil Page: 11 of 36
Lab Manual

Router(config-if)#no sh
Router(config-if)#exit
Router(config)#int fa0/0
Router(config-if)#ip address 192.168.3.1 255.255.255.0
Router(config-if)#no sh
Router(config-if)#exit
Router(config)#ip route 192.168.1.0 255.255.255.0 172.16.1.1
Router(config)#ip dhcp excluded-address 192.168.3.1
Router(config)#ip dhcp pool internal-LAN
Router(dhcp-config)#network 192.168.3.0 255.255.255.0
Router(dhcp-config)#default-router 192.168.3.1
Router(dhcp-config)#exit

OUTPUT

Prepared by: Reviewed by: Approved by:


Dr Aditya K Saxena
Issue No.: Date:
Computer Networks (CS203) Rev No.: Nil Rev. Date: Nil
Clause: Nil Page: 12 of 36
Lab Manual

Practical - 5

Aim: Simulate a network using Star Topology Using Cisco packet Tracer

Devices Used- 3 Generic PC, 3 Switch, Straight Through Cable.

Star Topology – This topology for a Local Area Network (LAN) in which all nodes
are individually connected to a central connection point, like a hub or a switch.

IP Configuration-
Generic PC 0: 192.168.1.1

Generic PC 1: 192.168.1.2

Generic PC 2: 192.168.1.3

Subnet Mask: 255.255.255.0

OUTPUT

Prepared by: Reviewed by: Approved by:


Dr Aditya K Saxena
Issue No.: Date:
Computer Networks (CS203) Rev No.: Nil Rev. Date: Nil
Clause: Nil Page: 13 of 36
Lab Manual

Practical - 6

Aim: Simulate a network using Bus Topology Using Cisco packet Tracer

Devices Used- 3 Generic PC, 3 Switch, Straight Through Cable and Cross Over
Cable.

Bus Topology – This topology for a Local Area Network (LAN) in which all the
nodes are connected to a single cable.

IP Configuration-
Generic PC 0: 192.168.1.1

Generic PC 1: 192.168.1.2

Generic PC 2: 192.168.1.3

Subnet Mask: 255.255.255.0

OUTPUT

Prepared by: Reviewed by: Approved by:


Dr Aditya K Saxena
Issue No.: Date:
Computer Networks (CS203) Rev No.: Nil Rev. Date: Nil
Clause: Nil Page: 14 of 36
Lab Manual

Practical - 7

Aim: Simulate a network using Ring Topology Using Cisco packet Tracer

Devices Used- 4 Generic PC, 4 Switch, Straight Through Cable and Cross Over
Cable.
Ring Topology – This topology for a Local Area Network (LAN) in which each
node connects to exactly two other nodes, forming a single continuous pathway
for signals through each node - a ring.

IP Configuration-
Generic PC 0: 192.168.1.1
Generic PC 1: 192.168.1.2
Generic PC 2: 192.168.1.3
Generic PC 3: 192.168.1.4
Subnet Mask: 255.255.255.0
OUTPUT

Prepared by: Reviewed by: Approved by:


Dr Aditya K Saxena
Issue No.: Date:
Computer Networks (CS203) Rev No.: Nil Rev. Date: Nil
Clause: Nil Page: 15 of 36
Lab Manual

Practical - 8

Aim: Simulate a network using Mesh Topology Using Cisco packet Tracer

Devices Used- 4 Generic PC, 4 Switch, Straight Through Cable and Cross Over
Cable.
Mesh Topology – This topology for a Local Area Network (LAN) in which all
nodes cooperate to distribute data amongst each other.

IP Configuration-
Generic PC 0: 192.168.1.1
Generic PC 1: 192.168.1.2
Generic PC 2: 192.168.1.3
Generic PC 3: 192.168.1.4
Subnet Mask: 255.255.255.0
OUTPUT

Prepared by: Reviewed by: Approved by:


Dr Aditya K Saxena
Issue No.: Date:
Computer Networks (CS203) Rev No.: Nil Rev. Date: Nil
Clause: Nil Page: 16 of 36
Lab Manual

Practical - 9
Aim: Implement NAT(network address translation) using Cisco Packet Tracker

Devices Used- 2 Generic PCs, 1 Generic Switch, 2 Generic Routers, 1 Generic


Server Straight Through Cable and Cross-Over Cable.

IP Configuration-
CIDR : /24
At Router0:
fa0/0 : 27.0.1.2
fa1/0 : 192.168.1.1
At Router1:
fa0/0 : 27.0.1.1
fa1/0 : 10.0.0.1
At Server0:
fa0/0: 10.0.0.2
Default Gateway: 10.0.0.1

Commands used at Router 0 :


Router>en
Router#config
Router(config)#int fa 1/0
Router(config-if)#ip address 192.168.1.1 255.255.255.0
Router(config-if)#no sh
Router(config-if)#exit
Router(config)#int fa 0/0
Router(config-if)#ip address 27.0.1.2 255.255.255.0
Router(config-if)#no sh
Router(config-if)#exit

Router(config)#ip route 10.0.0.0 255.255.255.0 27.0.1.1


Router(config)#ip dhcp excluded-address 192.168.1.1
Router(config)#ip dhcp pool internal-LAN
Router(dhcp-config)#network 192.168.1.0 255.255.255.0
Prepared by: Reviewed by: Approved by:
Dr Aditya K Saxena
Issue No.: Date:
Computer Networks (CS203) Rev No.: Nil Rev. Date: Nil
Clause: Nil Page: 17 of 36
Lab Manual

Router(dhcp-config)#default-router 192.168.1.1
Router(dhcp-config)#exit

Router(config)#access-list 1 permit 192.168.1.0 0.0.0.255


Router(config)#ip nat inside source list 1 interface fa 0/0
Router(config)#int fa 1/0
Router(config-if)#ip nat inside
Router(config-if)#int fa 0/0
Router(config-if)#ip nat outside

Commands used at Router 1 :


Router>en
Router#config t
Router(config)#int fa 0/0
Router(config-if)#ip address 27.0.1.1 255.255.255.0
Router(config-if)#no sh
Router(config-if)#exit
Router(config)#int fa 1/0
Router(config-if)#ip address 10.0.0.1 255.255.255.0
Router(config-if)#no sh
Router(config-if)#exit
Router(config)#ip route 192.168.1.0 255.255.255.0 27.0.1.2

Prepared by: Reviewed by: Approved by:


Dr Aditya K Saxena
Issue No.: Date:
Computer Networks (CS203) Rev No.: Nil Rev. Date: Nil
Clause: Nil Page: 18 of 36
Lab Manual

OUTPUT

PDU Information at Device:

PC0:

Prepared by: Reviewed by: Approved by:


Dr Aditya K Saxena
Issue No.: Date:
Computer Networks (CS203) Rev No.: Nil Rev. Date: Nil
Clause: Nil Page: 19 of 36
Lab Manual

Router 0

Router 1

Prepared by: Reviewed by: Approved by:


Dr Aditya K Saxena
Issue No.: Date:
Computer Networks (CS203) Rev No.: Nil Rev. Date: Nil
Clause: Nil Page: 20 of 36
Lab Manual

Practical - 10
AIM: Create a DNS Server Using Cisco Packet Tracer.

Devices Used- Generic Switch, Generic PC0, Generic PC1, Router0


(2811),Router1 (2911), Copper Cross Over and Copper Straight Through Cables,
DNS Server, WEB Server.

Configuration Of Server:
DNS Server given IP address 8.8.8.8,
Subnet Mask: 255.255.255.0,
Default Gateway: 8.8.8.1

WEB Server given IP address 10.0.0.2,


Subnet Mask: 255.255.255.0,
Default Gateway: 10.0.0.1

Configuration Of PC’s:
Generic PC0:
IP address 192.168.1.2,
Default Gateway 192.168.1.1
DNS Server 8.8.8.8
Generic PC1:
IP address 192.168.1.3,
Default Gateway 192.168.1.1
DNS Server 8.8.8.8

Configuration Of Routers:

Router0:
Router>en
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#int fa0/0
Router(config-if)#ip address 192.168.1.1 255.255.255.0
Prepared by: Reviewed by: Approved by:
Dr Aditya K Saxena
Issue No.: Date:
Computer Networks (CS203) Rev No.: Nil Rev. Date: Nil
Clause: Nil Page: 21 of 36
Lab Manual

Router(config-if)#no sh
Router(config-if)#exit

Router(config)#int fa0/1
Router(config-if)#ip address 27.0.1.1 255.255.255.0
Router(config-if)#no sh
Router(config-if)#exit
Router(config)#ip route 8.8.8.0 255.255.255.0 27.0.1.2
Router(config)#ip route 10.0.0.0 255.255.255.0 27.0.1.2

Router1:
Router>en
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#int gig 0/0
Router(config-if)#ip address 27.0.1.2 255.255.255.0
Router(config-if)#no sh
Router(config-if)#exit

Router(config)#int gig0/1
Router(config-if)#ip address 10.0.0.1 255.255.255.0
Router(config-if)#no sh
Router(config-if)#exit

Router(config)#int gig0/2
Router(config-if)#ip address 8.8.8.1 255.255.255.0
Router(config-if)#no sh
Router(config-if)#exit
Router(config)#ip route 192.168.1.0 255.255.255.0 27.0.1.1

Prepared by: Reviewed by: Approved by:


Dr Aditya K Saxena
Issue No.: Date:
Computer Networks (CS203) Rev No.: Nil Rev. Date: Nil
Clause: Nil Page: 22 of 36
Lab Manual

OUTPUT

Prepared by: Reviewed by: Approved by:


Dr Aditya K Saxena
Issue No.: Date:
Computer Networks (CS203) Rev No.: Nil Rev. Date: Nil
Clause: Nil Page: 23 of 36
Lab Manual

Practical - 11
Aim: Perform Bit Stuffing using C.
#include<stdio.h>

int main() {

int i,k=0,fl=0;

int a[40] = {1,0,0,1,1,

1,1,1,1,0,

1,0,0,1,0,

1,1,1,1,1,

1,0,1,0,0,

0,1,1,1,1,

1,0,0,1,1,

1,0,1,0,0};

printf("The initial array : \n");

for(i=0; i<40; i++) {

printf("%d ",a[i]);

if((i+1)%5==0)

printf("\n");

int b[40];

for(i=0; i<40; i++) {

if(a[i]==1 && a[i+1]==1 && a[i+2]==1 && a[i+3]==1 && a[i+4]==1) {

b[k++]=1;

Prepared by: Reviewed by: Approved by:


Dr Aditya K Saxena
Issue No.: Date:
Computer Networks (CS203) Rev No.: Nil Rev. Date: Nil
Clause: Nil Page: 24 of 36
Lab Manual

b[k++]=1;

b[k++]=1;

b[k++]=1;

b[k++]=1;

b[k++]=0;

i=i+4;

fl++;

} else

b[k++]=a[i];

printf("\nBits added :%d \n\n",fl);

printf("The modified array : \n");

for(i=0; i<40+fl; i++) {

printf("%d ",b[i]);

if((i+1)%5==0)

printf("\n");

return 0;

Prepared by: Reviewed by: Approved by:


Dr Aditya K Saxena
Issue No.: Date:
Computer Networks (CS203) Rev No.: Nil Rev. Date: Nil
Clause: Nil Page: 25 of 36
Lab Manual

OUTPUT

Prepared by: Reviewed by: Approved by:


Dr Aditya K Saxena
Issue No.: Date:
Computer Networks (CS203) Rev No.: Nil Rev. Date: Nil
Clause: Nil Page: 26 of 36
Lab Manual

Practical - 12
Aim: Perform Character Stuffing using C.
#include<stdio.h>

int main(){

char s[40]={'w','a','v','t','v','k','g','n','t','c','g','v','t','c','\0'};

char s2[20];

int i,k=0,fl=0;

printf("The initial array : \n");

for(i=0;;i++){

printf("%c ",s[i]);

if(s[i]=='\0')

break;

for(i=0;;i++){

if(s[i]=='v'|| s[i]=='t'){

s2[k++]='v';

s2[k++]=s[i];

fl++;

else

s2[k++]=s[i];

if(s[i]=='\0')

break;

Prepared by: Reviewed by: Approved by:


Dr Aditya K Saxena
Issue No.: Date:
Computer Networks (CS203) Rev No.: Nil Rev. Date: Nil
Clause: Nil Page: 27 of 36
Lab Manual

printf("\nCharacters stuffed : %d\n",fl);

printf("The modified array : \n");

for(i=0;;i++){

printf("%c ",s2[i]);

if(s2[i]=='\0')

break;

return 0;

OUTPUT

Prepared by: Reviewed by: Approved by:


Dr Aditya K Saxena
Issue No.: Date:
Computer Networks (CS203) Rev No.: Nil Rev. Date: Nil
Clause: Nil Page: 28 of 36
Lab Manual

Practical - 13

Aim: Implement Error detection method CRC using C.


#include<stdio.h>

#include<conio.h>

void main()

int a[20],c[20],d[20],aux[20],r,i,j,l,in,flag,choice,key;

clrscr();

printf("\n ENTER THE SIZE OF DATA WORD : ");

scanf("%d",&l);

printf("\n ENTER THE DATA WORD : ");

for(i=0; i<l; i++)

scanf("%d",&a[i]);

printf("\n ENTER THE NUMBER OF REDUNDANT BITS : ");

scanf("%d",&r);

printf("\n ENTER THE DIVISOR : ");

for(i=0; i<(r+1); i++)

scanf("%d",&d[i]);

for(i=0; i<(l+r); i++){

if(i<l) c[i]=a[i];

Prepared by: Reviewed by: Approved by:


Dr Aditya K Saxena
Issue No.: Date:
Computer Networks (CS203) Rev No.: Nil Rev. Date: Nil
Clause: Nil Page: 29 of 36
Lab Manual

else c[i]=0;

printf("\n\n ... GENERATOR MODULE ... \n");

printf("\n\n THE INTERMEDIATE CODE WORD IS : ");

for(i=0; i<(l+r); i++)

printf("%d ",c[i]);

for(i=0; i<(l+r); i++)

aux[i]=c[i];

for(i=0; i<l; i++){

in=1;

if(c[i]==1){

for(j=i+1; j<(i+l); j++){

c[j]=c[j]^d[in];

in++;

else{

for(j=i+1; j<(i+l); j++)

c[j]=c[j]^0;

printf("\n\n THE REMAINDER AFTER DIVISION IS : ");

for(i=l; i<(l+r); i++)

Prepared by: Reviewed by: Approved by:


Dr Aditya K Saxena
Issue No.: Date:
Computer Networks (CS203) Rev No.: Nil Rev. Date: Nil
Clause: Nil Page: 30 of 36
Lab Manual

printf("%d ",c[i]);

printf("\n\n SENDER CODE WORD : ");

for(i=0; i<(l+r); i++){

if(i<l) c[i]=aux[i];

printf("%d ",c[i]);

printf("\n\n\n PRESS 1 IF YOU WANT TO CHANGE A BIT OR 0 TO CONTINUE : ");

scanf("%d",&choice);

if(choice==1){

printf("\n\n ENTER THE BIT YOU WANT TO CHANGE :");

scanf("%d",&key);

for(i=0; i<(l+r); i++){

if(i==(key-1)){

if(c[key-1]==0) c[key-1]=1;

else c[key-1]=0;

printf("\n\n\n CODE WORD AFTER ERROR : ");

for(i=0; i<(l+r); i++)

printf("%d ",c[i]);

Prepared by: Reviewed by: Approved by:


Dr Aditya K Saxena
Issue No.: Date:
Computer Networks (CS203) Rev No.: Nil Rev. Date: Nil
Clause: Nil Page: 31 of 36
Lab Manual

else printf("\n\n\n NO ERROR INSERTED IN CODE WORD... ");

printf("\n\n\n\n ... CHECKER MODULE ... ");

for(i=0; i<l; i++){

in=1;

if(c[i]==1){

for(j=i+1; j<(i+l); j++){

c[j]=c[j]^d[in];

in++;

else{

for(j=i+1; j<(i+l); j++)

c[j]=c[j]^0;

printf("\n\n\n THE SYNDROME ARRAY IS : ");

for(i=l; i<(l+r); i++)

printf("%d ",c[i]);

flag=0;

for(i=l; i<(l+r); i++){

if(c[i]!=0){

flag=1;

break;

Prepared by: Reviewed by: Approved by:


Dr Aditya K Saxena
Issue No.: Date:
Computer Networks (CS203) Rev No.: Nil Rev. Date: Nil
Clause: Nil Page: 32 of 36
Lab Manual

if(flag==1) printf("\n\n\n ERROR DETECTED !!!");

else printf("\n\n\n NO ERROR FOUND");

getch();

Output

Prepared by: Reviewed by: Approved by:


Dr Aditya K Saxena
Issue No.: Date:
Computer Networks (CS203) Rev No.: Nil Rev. Date: Nil
Clause: Nil Page: 33 of 36
Lab Manual

Practical - 14

Aim: Impelement Error detection method Checksum using C


#include<stdio.h>

#include<string.h>

int main()

char a[20],b[20];

char sum[20],complement[20];

int i,length;

printf("Enter first binary string\n");

scanf("%s",&a);

printf("Enter second binary string\n");

scanf("%s",&b);

if(strlen(a)==strlen(b)){

length = strlen(a);

char carry='0';

for(i=length-1;i>=0;i--)

if(a[i]=='0' && b[i]=='0' && carry=='0')

sum[i]='0';

carry='0';

else if(a[i]=='0' && b[i]=='0' && carry=='1')

Prepared by: Reviewed by: Approved by:


Dr Aditya K Saxena
Issue No.: Date:
Computer Networks (CS203) Rev No.: Nil Rev. Date: Nil
Clause: Nil Page: 34 of 36
Lab Manual

sum[i]='1';

carry='0';

else if(a[i]=='0' && b[i]=='1' && carry=='0')

sum[i]='1';

carry='0';

else if(a[i]=='0' && b[i]=='1' && carry=='1')

sum[i]='0';

carry='1';

else if(a[i]=='1' && b[i]=='0' && carry=='0')

sum[i]='1';

carry='0';

else if(a[i]=='1' && b[i]=='0' && carry=='1')

sum[i]='0';

carry='1';

else if(a[i]=='1' && b[i]=='1' && carry=='0')

Prepared by: Reviewed by: Approved by:


Dr Aditya K Saxena
Issue No.: Date:
Computer Networks (CS203) Rev No.: Nil Rev. Date: Nil
Clause: Nil Page: 35 of 36
Lab Manual

sum[i]='0';

carry='1';

else if(a[i]=='1' && b[i]=='1' && carry=='1')

sum[i]='1';

carry='1';

else

break;

printf("\nSum=%c%s",carry,sum);

for(i=0;i<length;i++)

if(sum[i]=='0')

complement[i]='1';

else

complement[i]='0';

if(carry=='1')

carry='0';

else

carry='1';

Prepared by: Reviewed by: Approved by:


Dr Aditya K Saxena
Issue No.: Date:
Computer Networks (CS203) Rev No.: Nil Rev. Date: Nil
Clause: Nil Page: 36 of 36
Lab Manual

printf("\nChecksum=%c%s",carry,complement);

else {

printf("\nWrong input strings");

Output

Prepared by: Reviewed by: Approved by:


Dr Aditya K Saxena

Potrebbero piacerti anche