CN Lab Mannual
CN Lab Mannual
REGULATION 2021
NAME :
REGISTER NUMBER:
DEGREE/BRANCH :
COURSE OBJECTIVES:
To understand the concept of layering in networks.
To know the functions of protocols of each layer of TCP/IP protocol suite.
To visualize the end-to-end flow of information.
To learn the functions of network layer and the various routing protocols
To familiarize the functions and protocols of the Transport layer
PRACTICAL EXERCISES:
1.Learn to use commands like tcpdump, netstat, ifconfig, nslookup and traceroute.
Capture ping and trace route PDUs using a network protocol analyzer and examine.
2.Write a HTTP web client program to download a web page using TCP sockets.
3.Applications using TCP sockets like:
a) Echo client and echo server
b) Chat
4.Simulation of DNS using UDP sockets.
5.Use a tool like Wireshark to capture packets and examine the packets
6.Write a code simulating ARP /RARP protocols.
7.Study of Network simulator (NS) and Simulation of Congestion Control
Algorithms using NS.
8.Study of TCP/UDP performance using Simulation tool.
9.Simulation of Distance Vector/ Link State Routing algorithm.
10.Simulation of an error correction code (like CRC)
COURSE OUTCOMES:
At the end of this course, the students will be able to:
CO 1: Explain the basic layers and its functions in computer networks.
CO 2: Understand the basics of how data flows from one node to another.
CO 3: Analyze routing algorithms.
CO 4: Describe protocols for various functions in the network.
CO 5: Analyze the working of various application layer protocols.
TABLE OF CONTENT
PAGE
S.NO DATE NAME OF THE EXPRIEMENT
NO SIGN
1. Networking Commands
9.
Study of TCP/UDP performance using Simulation tool.
AIM:
To study the basic networking commands.
NETWORKING COMMANDS:
C:\>arp –a: ARP is short form of address resolution protocol, It will show the IP address of your
computer along with the IP address and MAC address of your router.
C:\>hostname: This is the simplest of all TCP/IP commands. It simply displays the name of your
computer.
C:\>ipconfig: The ipconfig command displays information about the host (the computer your
sitting at)computer TCP/IP configuration.
C:\>ipconfig /all: This command displays detailed configuration information about your TCP/IP
connection including Router, Gateway, DNS, DHCP, and type of Ethernet adapter in your
system.
C:\>Ipconfig /renew: Using this command will renew all your IP addresses that you are currently
(leasing) borrowing from the DHCP server. This command is a quick problem solver if you are
having connection issues, but does not work if you have been configured with a static IP address.
C:\>Ipconifg /release: This command allows you to drop the IP lease from the DHCPserver.
C:\>ipconfig /flushdns: This command is only needed if you‟re having trouble with your
networks DNS configuration. The best time to use this command is after network configuration
frustration sets in, and you really need the computer to reply with flushed.
C:\>nbtstat –a: This command helps solve problems with NetBIOS name resolution. (Nbt stands
for NetBIOS over TCP/IP)
C:\>netdiag: Netdiag is a network testing utility that performs a variety of network diagnostic
tests, allowing you to pinpoint problems in your network. Netdiag isn‟t installed by default, but
can be installed from the Windows XP CD after saying no to the install. Navigate to the CD
ROM drive letter and open the support\tools folder on the XP CD and click the setup.exe icon in
the support\tools folder.
C:\>netstat: Netstat displays a variety of statistics about a computers active TCP/IP connections.
This tool is most useful when you‟re having trouble with TCP/IP applications such as HTTP, and
FTP.
C:\>nslookup: Nslookup is used for diagnosing DNS problems. If you can access a resource by
specifying an IP address but not it‟s DNS you have a DNS problem.
1
C:\>pathping: Pathping is unique to Window‟s, and is basically a combination of the Ping and
Tracert commands. Pathping traces the route to the destination address then launches a 25 second
test of each router along the way, gathering statistics on the rate of data loss along each hop.
C:\>ping: Ping is the most basic TCP/IP command, and it‟s the same as placing a phone call to
your best friend. You pick up your telephone and dial a number, expecting your best friend to
reply with “Hello” on the other end. Computers make phone calls to each other over a network
by using a Ping command. The Ping commands main purpose is to place a phone call to another
computer on the network, and request an answer. Ping has 2 options it can use to place a phone
call to another computer on the network. It can use the computers name or IP address.
C:\>route: The route command displays the computers routing table. A typical computer, with a
single network interface, connected to a LAN, with a router is fairly simple and generally doesn‟t
pose any network problems. But if you‟re having trouble accessing other computers on your
network, you can use the route command to make sure the entries in the routing table are correct.
C:\>tracert: The tracert command displays a list of all the routers that a packet has to go through
to get from the computer where tracert is run to any other computer on the internet.
RESULT:
Thus the above list of primitive has been studied.
2
EX.NO : 2 Write A Http Web Client Program To Download A
DATE : Web Page Using TCP Sockets
AIM:
To Write a HTTP web client program to download a web page using TCP sockets.
ALGORITHM:
PROGRAM:
import socket
s= socket.socket(socket.AF_INET,socket.socket,SOCK_STREAM)
s.connect((“aurcc.ac.in”,80))
s.sendall(b”GET/HTTP/1.1\r\nHost:www.aurcc.ac.in\r\nAccept:text/html\r\n\r\n”)
print(str(s.recv(4096),‟utf-8‟))
3
OUTPUT:
RESULT:
The webpage is successfully downloaded and the contents are displayed and verified.
4
EX.NO : 3
SOCKET PROGRAM FOR ECHO
DATE :
AIM:
To write a socket program for implementation of echo.
ALGORITHM:
CLIENT
1. Start the program.
2. Create a socket which binds the Ip address of server and the port address
to acquire service.
3. After establishing connection send a data to server.
4. Receive and print the same data from server.
5. Close the socket.
6. End the program.
SERVER
1. Start the program.
2. Create a server socket to activate the port address.
3. Create a socket for the server socket which accepts the connection.
4. After establishing connection receive the data from client.
5. Print and send the same data to client.
6. Close the socket.
7. End the program.
PROGRAM:
ECHO CLIENT
Import socket
Import sys
Client =socket.socket socket.socket(socket.AF_INET,socket.socket,SOCK_STREAM)
Server_address=(“localhost”,1000)
Client.connect(server_address)
Message=input()
Print(“sending”,message)
5
Client.sendall(message.encode())
Print(“ORIGINAL”,message)
Data=client.recv(1000).decode()
Print(“ECHO”,data)
Client.close()
ECHO SERVER
Import socket
Import sys
Client =socket.socket socket.socket(socket.AF_INET,socket.socket,SOCK_STREAM)
Server_address=(“localhost”,10000)
Server.bind(server_address)
Server.listen(1)
Print(“waiting for a connection”)
Connecting.client_address=server.accept()
Print(“connection established:”client_address)
Data=connection.recv(1000)
Print(“received”,data)
Connection.sendall(data)
Connection.close()
Server.close()
6
OUTPUT:
CLIENT
SERVER
RESULT:
Thus the program for simulation of echo server was written & executed.
7
EX.NO : 4
CLIENT- SERVER APPLICATION FOR CHAT
DATE :
AIM:
To write a client-server application for chat using TCP
ALGORITHM:
CLIENT
1. Start the program
2. To create a socket in client to server.
3. The client establishes a connection to the server.
4. The client accept the connection and to send the data from client to server.
5. The client communicates the server to send the end of the message
6. Stop the program.
SERVER
1. Start the program
2. To create a socket in server to client
3. The server establishes a connection to the client.
4. The server accept the connection and to send the data from server to client and
5. The server communicate the client to send the end of the message.
6. Stop the program.
PROGRAM
CLIENT
Import socket
Import sys
Client =socket.socket socket.socket(socket.AF_INET,socket.socket,SOCK_STREAM)
Server_address=(“localhost”,1000)
Client.connect(server_address)
Print(connecting to port”,sever address)
Message=input()
Client.sendall(message.encode())
While message!=”end”
8
Data=client.recv(1000).decode()
If data:
Print(data)
Message=input()
Client.sendall(message.encode())
Else:
Break:
Client.close()
SERVER
Import socket
Import sys
Client =socket.socket socket.socket(socket.AF_INET,socket.socket,SOCK_STREAM)
Server_address=(“localhost”,1000)
Server.bind.(server_address)
Server.listen(1)
Print(“waiting for the connection”)
Connection.client_address=server.accept()
Print(“connection established with”,client_address)
Message=””
While message!=”end”.
Data=connection.recv(1000).decode()
If data:
Print(data)
Message=input()
Connection.sendall(message.encode())
Else:
Break
9
Connection.close()
Server.close()
OUTPUT
CLIENT
SERVER
RESULT:
Thus the above program a client-server application for chat using TCP / IP was executed
and successfully.
10
EX.NO : 5
SIMULATION OF DNS USING UDP SOCKETS
DATE :
AIM:
To write a program to Simulation of DNS using UDP sockets.
ALGORITHM:
1.Start the program.
2.Get the frame size from the user
3.To create the frame based on the user request.
4 .To send frames to server from the client side.
5.If your frames reach the server it will send ACK signal to client otherwise it will send
NACK signal to client.
6.Stop the program
PROGRAM:
CLIENT:
Import socket
Hostname=socket.gethostname( )
Ipaddr=”127.0.0.1”
S = socket.socket socket.socket(socket.AF_INET,socket.socket,SOCK_DGRAM)
Addr=( ipaddr,1234)
C=”y”
Whie c.upper( ) == “y”;
Req_domain = input(“enter domain name for which the ip is needed”)
Send= s.sendto(req_domain.encode(),addr)
Data.address=s.recvfrom(1024)
Replay_ip = data.decode().strip()
print(“the ip for the domain name{req_domain}:{replay_ip}”)
c=(input(“continue? (y/n)”))
s.close()
SERVER
Import socket
Dns_table={“www.google.com:”:”192.165.1.1”,”www.youtube.com”:”192.165.1.2”,
“www.python.org”:”192.165.1.3”,”www.aurcc.ac.in”:”192.165.1.4”,
“www.amazon.in”:”192.165.1.5”,”www.gmail.com”:”192.165.1.6”}
S = socket.socket socket.socket(socket.AF_INET,socket.socket,SOCK_DGRAM)
print(“starting server”)
s.bind((“127.0.0.1”,1234))
while true:
data.address= s.recvfrom(1024)
print(f”{address}wants to fetch data”)
data = data.decode()
11
ip=dns_table.get(data,”not found”).encode()
send=s.sendto(ip,address)
s.close()
OUTPUT :
CLIENT
SERVER
RESULT:
Thus the above program a client-server application for chat using UDP was executed and
successfully
12
EX.NO : 6
Write a code simulating ARP protocols.
DATE :
AIM
To implement Address Resolution Protocol .
ALGORITHM
PROGRAM:
SERVER
Import socket
Table={„192.168.1.1‟,‟1E.4A.4A.11‟,
„192.168.2.1‟,‟5E.51.4B.01‟,
„192.168.1.3‟,‟4B.35.CD.32‟,
„192.168‟.4.1‟,‟AF.4D.1G.FF‟,
„192.168.3.2‟,‟C3.C5.EE.C2‟,
‟1E.4A.4A.11‟, „192.168.1.1‟,
‟5E.51.4B.01‟, „192.168.2.1‟,
‟4B.35.CD.32‟, „192.168.1.3‟,
‟AF.4D.1G.FF‟, „192.168‟.4.1‟,
‟C3.C5.EE.C2‟, „192.168.3.2‟,
}
s =socket.socket socket.socket(socket.AF_INET,socket.socket,SOCK_STREAM)
s.bind((“1234”))
s.listen()
clientsocket.address = s.accept()
print(“connection from”,address,”has establised”)
Ip = clientsocket.recv(1024)
Ip=i.decode(“utf-8”)
Mac = tabe.get(ip,”no entry for given address”)
Clientsocket.send(mac.encode())
s.close()
13
CLIENT
Import socket
s =socket.socket socket.socket(socket.AF_INET,socket.socket,SOCK_STREAM)
s.connect(“localhost”,1234)
a=input(“ARP or RARP:”)
if(a==”ARP”)
add = input(“enter ip”)
elseif(a==“RARP”)
add = input(“enter mac”)
s.send(add.encode())
mac = s.recv(1024)
mac = mac.decode(“utf-8”)
if(a==”ARP”):
print(„MAC of‟,add,‟is:‟,mac)
else:
print(„IP of‟,add,‟is:‟,mac)
s.close()
OUTPUT
RESULT
Thus the implementation of ARP is done & executed successfully.
14
EX.NO : 7
Write a Code Simulating RARP Protocols.
DATE :
AIM:
To write a program for simulating RARP protocols.
ALGORITHM:
CLIENT
1. Start the program
2. using datagram sockets UDP function is established
3. .Get the MAC address to be converted into IP address.
4. Send this MAC address to server.
5. Server returns the IP address to client.
SERVER
1. Start the program.
2. Server maintains the table in which IP and corresponding MAC addresses are stored.
3. Read the MAC address which is send by the client.
4. Map the IP address with its MAC address and return the IP address to client.
PROGRAM:
RARP SERVER
Import socket
Table={„192.168.1.1‟,‟1E.4A.4A.11‟,
„192.168.2.1‟,‟5E.51.4B.01‟,
„192.168.1.3‟,‟4B.35.CD.32‟,
„192.168‟.4.1‟,‟AF.4D.1G.FF‟,
„192.168.3.2‟,‟C3.C5.EE.C2‟,
‟1E.4A.4A.11‟, „192.168.1.1‟,
‟5E.51.4B.01‟, „192.168.2.1‟,
‟4B.35.CD.32‟, „192.168.1.3‟,
‟AF.4D.1G.FF‟, „192.168‟.4.1‟,
‟C3.C5.EE.C2‟, „192.168.3.2‟,
}
s =socket.socket socket.socket(socket.AF_INET,socket.socket,SOCK_STREAM)
s.bind((“1234”))
s.listen()
clientsocket.address = s.accept()
print(“connection from”,address,”has establised”)
15
Ip = clientsocket.recv(1024)
Ip=i.decode(“utf-8”)
Mac = tabe.get(ip,”no entry for given address”)
Clientsocket.send(mac.encode())
s.close()
RARP CLIENT
Import socket
s =socket.socket socket.socket(socket.AF_INET,socket.socket,SOCK_STREAM)
s.connect(“localhost”,1234)
a=input(“ARP or RARP:”)
if(a==”ARP”)
add = input(“enter ip”)
elseif(a==“RARP”)
add = input(“enter mac”)
s.send(add.encode())
mac = s.recv(1024)
mac = mac.decode(“utf-8”)
if(a==”ARP”):
print(„MAC of‟,add,‟is:‟,mac)
else:
print(„IP of‟,add,‟is:‟,mac)
s.close()
OUTPUT:
RESULT
Thus the implementation of RARP is done & executed successfully.
16
EX.NO : 8
Study of Network simulator (NS) and Simulation of Congestion
DATE : Control Algorithms using NS.
OBJECTIVE:
To study of network simulator (ns) and simulation of congestion control algorithms using ns.
SYSTEM REQUIREMENTS:
PC: Pentium or higher
One LAN card onboard or on PCI slot with 10/100Mbps speed. 128MB RAM
500MB free space on Hard drive CD ROM drive
Serial port, LPT port & USB port installed on system Operating System: Windows 2000 or
higher
THEORY:
LTS-01 Local area network / wireless local area network trainer system:
It is designed to help students understand the basic concepts, modes of operation and protocols
involved in networking. The trainer has integrated hardware flow control on panel board for
better understanding of different types of LAN topologies involved in networking. The trainer
system is provided with windows-based user friendly software with analysis of protocols,
different layers, network and measurement of error rate and throughput.
Students can easily do connections in different topologies and can learn actual data transfer
either through hardware or through simulated network concept. Facility is provided into system
software to introduce errors into packets being sent and analyze the effect of error on different
protocols and hence find the effect on through put graph as well.
Trainer and its various types of experimentation using this system. This system works into
server-client base. For any topology user has to select one server and select the network type
whether it is LAN or WLAN. To understand the topology concept user can connect two or more
clients to hardware. Depending on the topology selected user will have option to select protocols
for the selected topology. Upon selection of protocol user can then create network of connected
computers.
In any network which is created by user server can send or can communicate with any of the
clients however clients can communicate only with server, no client to client communication is
possible. Transmitter port protocol & network analysis can be done after communication is over
between server and clients. Throughput v/s Packet size graph can be plotted for which at least
two file transfers should be carried out. This plot can be printed to attach in the lab exercise
sheet.
17
For the LAN network LAN cards must be installed prior to start work on this trainer. For wire
less LAN USB ports should be available on the computers which are to be used for
experimentation. In WLAN wireless access cards gets connected to computer USB ports and
access point gets connected to hardware device.
L-SIM LAN Protocol Simulator & Analyzer Software:
It is designed to teach the basic concepts, topologies & various protocols involved in networking.
The software is provided with analysis of protocols, different layers, network and measurement
of error rate and throughput. Facility is provided to introduce errors into packets being sent and
analyze the effect of error on different protocols and hence find the effect on throughput graph as
well. Software is supported with neat operating instruction manual and online help.
MODEL WINDOW DIAGRAM FOR L-SIM
18
transmission. Merging & evolving technologies, coupled with increasing demands for efficient &
timely collection, processing & dissemination of information, have led to the development of
integrated systems that transmit & process all types of data.
These intgrated systems are broadly divided as follows
- DATA COMMUNICATION dealing with transmission, transmission media, signal decoding,
interfacing, data link control & multiplexing
- NETWORKING deals with the technology & architecture of communication network
- COMMUNICATION PROTOCOLS which covers the architecture as well
as analysis of individual protocols at various layers depending on the hardware & software
Network laboratory is designed & developed considering the curriculum offered by Anna
University. Trainers offered under network laboratory are designed for students at all level to
study and understand all the concepts of data communication, data transfer using serial and
parallel ports, Ethernet and wireless LAN with complete protocol understanding and actual
hands on with hardware & software with ease.
Network laboratory consists of DCT-03 Data communication trainer kit, LTS- 01 LAN /
Wireless LAN training system, L-SIM LAN / WLAN protocol simulator and analyzer software
& N-SIM Network simulation software.
The DCT-03: Data communication trainer is a unique trainer kit for the development of exercises
and theoretical-experimental courses to understand the basic concept and working of modes and
protocols in serial and parallel communication.
The trainer kit consists of functional blocks for serial and parallel communication system.
The trainer kit is highly innovative from a technological as well as an educational point of view.
The trainer kit is used as “basic unit” to examine all the peculiar operating standards of serial and
parallel communication system. The only external equipments required are two Computers with
serial and parallel communication ports and an Oscilloscope. Utmost care has been laid in the
design and quality control of all circuits, to ensure the repeatability of the results of the
experiments.
Data communication is a term referred when the sender and receiver are digital devices, which
communicate with each other by means of binary information. The objective of this trainer kit is
to clear the various aspects of the data communications which comprise of
• The information source or sender.
• The medium for carrying information.
• The information receiver.
• The communication protocols, which ensure proper transfer of data.
19
With an increasing demand in information exchange the field of data communication technique
is emerging as the only solution, to satisfy the various needs of today‟s communication sector
and to achieve very high bandwidth along with highest accuracy. The communication media is
shifting from analog signal transfer towards digital communication.
With PC becoming the biggest storage devices in digital form, it becomes the main source and
destination for information exchange. With rapid growth in both the communication technologies
as well as computer hardware and software technologies, these two fields are merged to form a
data communication network. Now the digital data is used for data, voice and image
transmission.
Depending upon the application the communication link can be of point to point communication
between two devices or a multipoint communication between at least 3 devices and data transfer
can be serial or in parallel form.
RESULT:
The study of network simulator (ns) and simulation of congestion control algorithms
using ns is executed and verified.
20
EX.NO : 9
Study of TCP/UDP performance using Simulation tool.
DATE :
AIM:
To Study of TCP/UDP performance using Simulation tool.
TOOLS USED:
Opnet Simulator
INTRODUCTION:
The transport layer protocols provide connection- oriented sessions and reliable data
delivery services. This paper seeks to reflect a comparative analysis between the two transport
layer protocols, which are TCP/IP and UDP/IP, as well to observe the effect of using these two
protocols in a client server network. The similarities and differences between TCP and UDP over
the Internet are also presented in our work. We implement a network structure using Opnet
Modeler and finally, based on the practical results obtained we present the conclusions-showing
the difference between these two protocols and how they work.
The transport layer is not just another layer. It is the heart of the whole protocol
hierarchy. Its task is to provide reliable, cost-effective data transport from the source machine to
the destination machine, independently of the physical network or networks currently in use.
TCP and UDP are transport layer components that provide the connection point through which
applications access network services. TCP and UDP use IP, which is a lower-layer best effort
delivery service. IP encapsulates TCP packets and UDP datagrams and delivers this information
across router-connected internet works.
The ultimate goal of the transport layer is to provide efficient, reliable, and cost-effective
service to its users, normally processes in the application layer. To achieve this goal, the
transport layer makes use of the services provided by the network layer. Without the transport
layer, the whole concept of layered protocols would make little sense e.g. The Transport Layer
prepares applications data for transport over the network and processes network data to be used
by applications. It is responsible for the end-to-end transfer of data over the network and is the
four of the OSI model. The Transport layer meets a number of functions:
- enabling the applications to communicate over the network at the same time when using a
single device;
- ensure that all amount of data is receive by the correct application;
- responsible for fragmentation and reassembly;
- develop mechanism for handling errors.
21
Comparison Between TCP And UDP
TCP
UDP
22
1.Response time for TCP and UDP
TCP
UDP
TCP TCP
UDP UDP
23
TCP
UDP
The main difference between these two protocols is that TCP provides reliability and
congestion control services, while UDP is orientated to improve performance.
The most important and common thing that TCP and UDP are using is the ability to set a
host-to-host communication channel, so the packets will be delivered between processes running
on two different computers. UDP is the right choice for application where reliability is not a
must but the speed and performance is. Instead, TCP, even if it takes more time for the
processes, has additional functions like same order delivery, reliability and flow control. As
future work, we plan to conduct several studies regarding packets routing in computer networks
to improve the fairness of data transmissions using different network protocols.
RESULT:
Thus the TCP/UDP performance has been simulated successfully using OPNET.
24
EX.NO : 10
Simulation of Distance Vector/ Link State Routing algorithm.
DATE :
AIM:
APPARATUS REQUIRED:
1. VI-RTSIM software.
2. Personal computer.
THEORY:
A Distance vector routing, each router periodically share its knowledge about the entire
network with it‟s neighbors.
The three keys to under this algorithm are
1. Knowledge about the whole network.
2. Routing only to neighbor.
3. Information sharing at regular intervals.
Knowledge about the whole work:
Each router shares its knowledge about entire network. It sends all of its collected
knowledge about the network to its neighbors.
Each router periodically sends its knowledge about the network only to those routers to
which it has direct links. It sends whatever knowledge it has.
Information sharing at regular intervals:
The every 30 seconds, each router sends its information about the whole network to its
neighbors.
Sharing Information:
Routing Table:
25
Each router gets its initial knowledge about the internet work and how it uses shared
information to update that knowledge.
The routing table has e columns network lost router ID.
The first block is final destination of packet.
The second block is no of hop count.
The third block is that to which a packet delivers must.
Updating algorithm:
Updating algorithm requires that the router first has one hop to the hop count field for
each advertised router.
The router should apply the below rules to each router, if the advertised destination is not
in routing table
If next hop field is same, router should replace the entry in the table with advertised one.
If next hop field is same, router should replace the entry in the table with advertised one.
If next hop field is not the same, advertised hop count is smaller than the one in the table,
the router should replace the entry in the table with new one.
IF advertised hop count is not smaller, the router should do no routing.
PROCEDURE
26
27
RESULT:
Thus Distance Vector routing algorithm has been implemented and shortest-path has
been circulated.
28
EX.NO : 11
Simulation of Link State Routing algorithm.
DATE :
AIM:
To implement the Link State Routing Algorithm
ALGORITHM
1. Start the process.
2. Give the data which is the message.
3. Compile and run the program.
4. Enter the received hamming code.
5. The error is corrected codeword.
PROGRAM
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
int main()
{
int i,j,k,count,err-pos=0,flag=0;
char dw[20],cw[20],data[20];
printf(“enter data as binary bit stream(7 bits):\n”);
scanf(“%s”,data);
for(i=1,j=0,k=0;i<12;i++)
{
if(i==(int)pow(2,j))
{
dw[i]=‟?‟;
j++;
}
else
{
29
dw[i]=data[k];
k++;
}
}
for(i=0;j<4;i++)
{
count=0;
for(j=(int)pow(2,i);j<12;j<12;j+=(int)pow(2,i))
{
for (k=0;k<(int)pow(2,i);k++)
{
if(dw[j]==‟1‟)count++;j++;
}
}
if(count%2==0)
dw[(int)pow(2,i)]=‟0‟;
else
dw[(int)pow(2,i)]=‟1‟;
}
printf(“in code word is\n\n”);
for(i=1;i<12;i++)
printf(“%c”,dw[i]);
printf(“\n\n enter the received hamming code\n\n”);
scanf(“%s”,cw);
for(i=12;i>0;i--)
cw[i]=cw[i-1];
for(i=0;i<4;i++)
{
count=0;
30
for(j=(int)pow(2,i);j<12;j+=(int)pow(2,i))
{
for(k=0;k<(int)pow(2,i);k++)
{
if(cw[j]==‟1‟)count++;j++;
}
}
if (count%2!=0)
err-pos=err-post+(int)pow(2,i);
}
if(err-pos==0)
printf(“\n\n there is no error in received code word \n”);
else
{
if(cw[err-pos]==dw[err-pos])
{
printf(“\n\n there are 2 or more errors in received code……\n\n”);
printf(“sorry…! hamming code cannot correct 2 or more errors….\n”);
flag=1;
}
else
printf(“in there is an error in bit position %d of received code word \n”,err-pos);
if(flag==0)
{
cw[err-pos]=(cw[err-pos]==‟1‟)?‟0‟:‟1‟;
printf(“\n\n corrected code word is \n\n”);
for(i=1;i<12;i++)
printf(“%c”,cw[i]);
}
31
}
printf(“\n\n”);
}
OUTPUT:
Enter data as binary bit stream(7 bits):
1110110
Code word is
11101100110
Enter the received hamming code
10101100110
There is an error in bit position 2 of received code word corrected code word is
11101100110
Enter data as binary bit stream(7 bits)
11101110
Code word is
11101100110
Enter the received hamming code
00101100110
There are 2 or more error in received code…
Sorry…!
RESULT:
Thus the error detection/error correction techniques were implemented successfully.
32