You are on page 1of 79

T.E.

(Comp) Computer Network Lab

Assignment No: 1 (Group A)

Aim: Introduction to Various Network Components & LAN

Part A: Setup a wired LAN using Layer 2 Switch and then IP switch of minimum four
computers. It includes preparation of cable, testing of cable using line tester, configuration
machine using IP addresses, testing using PING utility and demonstrate the PING packets
captured traces using Wire shark Packet Analyzer Tool.

Part B: Extend the same Assignment for Wireless using Access Point

Objective:

To understand the structure and working of various networks including the interconnecting
devices used in them.

To get hands on experience of making and testing cables

Pre-requisite: Knowledge of

Theory:

TYPES OF NETWORK

Common examples of area network types are:

 LAN - Local Area Network


 WAN - Wide Area Network

 MAN - Metropolitan Area Network

 SAN - Storage Area Network

 CAN - Campus Area Network

 PAN - Personal Area Network

LAN - Local Area Network

A LAN connects network devices over a relatively short distance. A networked office building,
school, or home usually contains a single LAN, though sometimes one building will contain a
few small LANs (perhaps one per room), and occasionally a LAN will span a group of nearby
buildings.

MAN-Metropolitan Area Network

A network spanning a physical area larger than a LAN but smaller than a WAN, such as a city. A
MAN is typically owned and operated by a single entity such as a government body or large
corporation.
T.E. (Comp) Computer Network Lab

WAN - Wide Area Network

As the term implies, a WAN spans a large physical distance. The Internet is the largest WAN,
spanning the Earth. A WAN is a geographically-dispersed collection of LANs. A network device
called a router connects LANs to a WAN. In IP networking, the router maintains both a LAN
address and a WAN address.

TYPES OF CABLES

Cable is the medium through which information usually moves from one network device to
another. There are several types of cable which are commonly used with LANs. In some cases, a
network will utilize only one type of cable, other networks will use a variety of cable types.

The type of cable chosen for a network is related to the network's topology, protocol, and size.
Understanding the characteristics of different types of cable and how they relate to other aspects
of a network is necessary for the development of a successful network.

The following sections discuss the types of cables used in networks and other related topics.

 Unshielded Twisted Pair (UTP) Cable


 Shielded Twisted Pair (STP) Cable

 Coaxial Cable

 Fiber Optic Cable

 Cable Installation Guides

 Wireless LANs

Unshielded Twisted Pair (UTP) Cable

Twisted pair cabling comes in two varieties: shielded and unshielded. Unshielded twisted pair
(UTP) is the most popular and is generally the best option for school networks

Unshielded twisted pair


T.E. (Comp) Computer Network Lab

The quality of UTP may vary from telephone-grade wire to extremely high-speed cable. The
cable has four pairs of wires inside the jacket. Each pair is twisted with a different number of
twists per inch to help eliminate interference from adjacent pairs and other electrical devices. The
tighter the twisting, the higher the supported transmission rate and the greater the cost per foot.
The EIA/TIA (Electronic Industry Association/Telecommunication Industry Association) has
established standards of UTP and rated six categories of wire (additional categories are
emerging)

Unshielded Twisted Pair Connector

The standard connector for unshielded twisted pair cabling is an RJ-45 connector. This is a
plastic connector that looks like a large telephone-style connector (See fig.). A slot allows the RJ-
45 to be inserted only one way. RJ stands for Registered Jack, implying that the connector
follows a standard borrowed from the telephone industry. This standard designates which wire
goes with each pin inside the connector.

RJ-45 connector

Shielded Twisted Pair (STP) Cable

Although UTP cable is the least expensive cable, it may be susceptible to radio and electrical
frequency interference (it should not be too close to electric motors, fluorescent lights, etc.). If
you must place cable in environments with lots of potential interference, or if you must place
cable in extremely sensitive environments that may be susceptible to the electrical current in the
UTP, shielded twisted pair may be the solution. Shielded cables can also help to extend the
maximum distance of the cables.

Shielded twisted pair cable is available in three different configurations:

1. Each pair of wires is individually shielded with foil.

2. There is a foil or braid shield inside the jacket covering all wires (as a group).

3. There is a shield around each individual pair, as well as around the entire group of wires
(referred to as double shield twisted pair).
T.E. (Comp) Computer Network Lab

Coaxial Cable

Coaxial cabling has a single copper conductor at its center. A plastic layer provides insulation
between the center conductor and a braided metal shield (See fig.)The metal shield helps to block
any outside interference from

Coaxial cable

Although coaxial cabling is difficult to install, it is highly resistant to signal interference. In


addition, it can support greater cable lengths between network devices than twisted pair cable.
The two types of coaxial

Thin coaxial cable is also referred to as thinnet. 10Base2 refers to the specifications for thin
coaxial cable carrying Ethernet signals. The 2 refers to the approximate maximum segment
length being 200 meters. In actual fact the maximum segment length is 185 meters. Thin coaxial
cable has been popular in

Thick coaxial cable is also referred to as thicknet. 10Base5 refers to the specifications for thick
coaxial cable carrying Ethernet signals. The 5 refers to the maximum segment length being 500
meters. Thick coaxial cable has an extra protective plastic cover that helps keep moisture away
from the center conductor. This makes thick coaxial a great choice when running longer lengths
in a linear bus network. One disadvantage of thick coaxial is that it does

Coaxial Cable Connectors

The most common type of connector used with coaxial cables is the Bayone-NeillConcelman
(BNC) connector (See fig.)Different types of adapters are available for BNC connectors,
including a T-connector, barrel connector, and terminator. Connectors on the cable are the
weakest points in any network. To help avoid problems with your network, always use the BNC
connectors that crimp, rather

BNC connector

Fiber Optic Cable

Fiber optic cabling consists of a center glass core surrounded by several layers of protective
materials (See fig.) It transmits light rather than electronic signals eliminating the problem of
T.E. (Comp) Computer Network Lab

electrical interference. This makes it ideal for certain environments that contain a large amount
of electrical interference. It has also made it the standard for connecting networks between

Fiber optic cable has the ability to transmit signals over much longer distances than coaxial and
twisted pair. It also has the capability to carry information at vastly greater speeds. This capacity
broadens communication possibilities to include services such as video conferencing and
interactive services. The cost of fiber optic cabling is comparable to copper cabling; however, it
is the center core of fiber cables is made from glass or plastic fibers (see fig). A plastic coating
then cushions the fiber center, and kevlar fibers help to strengthen the cables and prevent
breakage. The outer insulating jacket made of teflon or PVC.

Fiber optic cable

There are two common types of fiber cables -- single mode and multimode. Multimode cable
has a larger diameter; however, both cables provide high bandwidth at high speeds. Single mode
can provide more distance, but it is more expensive.

NETWORK DEVICES

Computer networking devices are units that mediate data in a computer network. A lst of
computer networking devices follows:

Gateway

A device sitting at a network node for interfacing with another network that uses different
protocols. It may contain devices such as protocol translators, impedance matching devices, rate
converters, fault isolators, or signal translators as necessary to provide system interoperability. It
also requires the establishment of mutually acceptable administrative procedures between the
two networks.

A protocol translation/mapping gateway interconnects networks with different network protocol


technologies by performing the required protocol conversions.

Gateways, also called protocol converters, can operate at any layer of the OSI model. The job of
a gateway is much more complex than that of a router or switch. Typically, a gateway must
convert one protocol stack into another. Routers exemplify special cases of gateways.

Router

A router is a computer networking device that forwards data packets across a network toward
their destinations, through a process known as routing. Routing occurs at layer 3 (the Network
layer e.g. IP) of the OSI seven-layer protocol stack.

A router acts as a junction between two or more networks to transfer data packets among them. A
router is different from a switch. A switch connects devices to form a Local area network (LAN).
T.E. (Comp) Computer Network Lab

One easy illustration for the different functions of routers and switches is to think of switches as
neighborhood streets, and the router as the intersections with the street signs. Each house on the
street has an address within a range on the block. In the same way, a switch connects various
devices each with their own IP address (es) on a LAN.

However, the switch knows nothing about IP addresses except its own management address.
Routers connect networks together the way that on-ramps or major intersections connect streets
to both highways and freeways, etc. The street signs at the intersection (routing table) show
which way the packets need to flow.

So for example, a router at home connects the Internet Service Provider's (ISP) network (usually
on an Internet address) together with the LAN in the home (typically using a range of private IP
addresses) and a single broadcast domain. The switch connects devices together to form the
LAN. Sometimes the switch and the router are combined together in one single package sold as a
multiple port router.

In order to route packets, a router communicates with other routers using routing protocols and
using this information creates and maintains a routing table. The routing table stores the best
routes to certain network destinations, the "routing metrics" associated with those routes, and the
path to the next hop router.

Routing is most commonly associated with the Internet Protocol, although other less popular
routed protocols are in use.

Bridge

A network bridge connects multiple network segments at the data link layer. It is sometimes
called a network switch, and it works by using bridging. Traffic from one network is forwarded
through it to another network. The bridge simply does what its name entails, by connecting two
sides from adjacent networks.

A repeater is a similar device that connects network segments at the physical layer. An Ethernet
hub is a type of repeater.

Bridging takes place at the data link layer of the OSI model. Therefore a bridge can only read the
Ethernet header which provides the MAC address of the source and destination address. When a
broadcast packet is transmitted, the bridge floods all the ports with the broadcast packets.
Bridges use two methods to resolve the network segment that a MAC address belongs to.

Transparent Bridging – This method uses a forwarding database to send packets across
network segments. The forwarding database is initially empty and entries in the database are
built as the bridge receives packets. If an address entry is not found in the forwarding table, the
packet is flooded to all ports of the bridge which sends the packet to all segments except the
source address. This type of bridging is common in Ethernet networks. To avoid frame looping, a
spanning tree is created from the network graph and bridges not present in it are kept inactive;
they can become active again if another bridge stops working.
T.E. (Comp) Computer Network Lab

Source route bridging – This method is used in Token Ring networks. In Ethernets, the term
"bridge" formally means a device that behaves according to the IEEE 802.1D standard - this is
most often referred to as a network switch in marketing literature.

Switch

A switch is a device that allocates traffic from one network segment to certain lines which
connect the segment to another network segment. So unlike a hub a switch splits the network
traffic and sends it to different destinations rather than to all systems on the network.

It performs transparent bridging (connection of multiple network segments with forwarding


based on MAC addresses) at full wire speed in hardware. The use of specially designed hardware
also makes it possible to have large numbers of ports (unlike a PC based bridge which is very
limited by expansion slot count).

If a network has only switches and no hubs then the collision domains are either reduced to a
single link or, if both ends support full duplex, eliminated altogether. The principle of a fast
hardware forwarding device with many ports can be extended to higher layers giving the
multilayer switch.

A switch can connect Ethernet, Token Ring, Fibre Channel or other types of packet switched
network segments together to form a heterogeneous network operating at OSI Layer 2 (though
there may be complications caused by the different MTUs of the standards).

As a frame comes into a switch, the switch saves the originating MAC address and the
originating (hardware) port in the switch's MAC address table. This table often uses content-
addressable memory, so it is sometimes called the "CAM table". The switch then selectively
transmits the frame from specific ports based on the frame's destination MAC address and
previous entries in the MAC address table. If the destination MAC address is unknown, for
instance, a broadcast address or (for simpler switches) a multicast address, the switch simply
transmits the frame out of all of the connected interfaces except the incoming port. If the
destination MAC address is known, the frame is forwarded only to the corresponding port in the
MAC address table. If the destination port is the same as the originating port, the frame is filtered
out and not forwarded.

Switches, unlike hubs, use microsegmentation to create collision domains, one per connected
segment. This way, only the NICs which are directly connected via a point-topoint link, or
directly connected hubs are contending for the medium. If the switch and the equipment (other
than a hub) it connects to support full-duplex then the collision domain is eliminated entirely.

The higher level operation also allows some more advanced features that would be impractical
with simple hubs. For example Virtual LANs can be used in switches to reduce the size of the
broadcast domains and at the same time increase security and switches can also implement
spanning tree protocol allowing use of redundant links.

Hub

An Ethernet hub or concentrator connects multiple Ethernet segments together making them act
as a single segment. When using a hub, every attached device shares the same broadcast domain
T.E. (Comp) Computer Network Lab

and the same collision domain. Therefore, only one computer connected to the hub is able to
transmit at a time. Depending on the network topology, the hub provides a basic level 1 OSI
model connection among the network objects (workstations, servers, etc). It provides bandwidth
which is shared among all the objects, compared to switches, which provide a dedicated
connection between individual nodes..

It is a device for connecting multiple twisted pair or fibre optic Ethernet devices together,
making them act as a single segment. It works at the physical layer of the OSI model, repeating
the signal received at one port out each of the other ports (but not the original one). The device is
thus a form of multiport repeater. Ethernet hubs are also responsible for forwarding a jam signal
to all ports if it detects a collision.

A hubbed Ethernet network behaves like a shared-medium, that is only one device can
successfully transmit at a time and each host remains responsible for collision detection and
retransmission. With 10BASE-T and 100BASE-T links (which generally account for most or all
of the ports on a hub) there are separate pairs for transmit and receive but they are used in half
duplex mode in which they still effectively behave like shared medium links

The need for hosts to be able to detect collisions limits the number of hubs and the total size of
the network. For 10 Mbit/s networks, up to 5 segments (4 hubs) are allowed between any two
end stations. For 100 Mbit/s networks, the limit is reduced to 3 segments (2 hubs) between any
two end stations, and even that is only allowed if the hubs are of the low delay variety. Some
hubs have special (and generally manufacturer specific) stack ports allowing them to be
combined in a way that allows more hubs than simple chaining through Ethernet cables, but even
so a large Fast Ethernet network is likely to require switches to avoid the chaining limits of hubs.

Most hubs detect typical problems, such as excessive collisions on individual ports, and partition
the port, disconnecting it from the shared medium. Thus, hub-based Ethernet is generally more
robust than coaxial cable-based Ethernet, where a misbehaving device can disable the entire
segment. Even if not partitioned automatically, a hub makes troubleshooting easier because
status lights can indicate the possible problem source or, as a last resort, devices can be
disconnected from a hub one at a time much more easily than a coaxial cable. They also remove
the need to troubleshoot faults on a huge cable with multiple taps.

Repeater

A repeater is an electronic device that receives a weak or low-level signal and retransmits it at a
higher level or higher power, so that the signal can cover longer distances without degradation.

In telecommunication, the term repeater has the following standardized meanings:

 An analog device that amplifies an input signal regardless of its nature (analog or digital).
 A digital device that amplifies, reshapes, retimes, or performs a combination of any of
these functions on a digital input signal for retransmission.

Repeaters are often used in trans-continental and trans-oceanic cables, because the attenuation
(signal loss) over such distances would be completely unacceptable without them. Repeaters are
used in both copper-wire cables carrying electrical signals, and in fibre optics carrying light.
T.E. (Comp) Computer Network Lab

In optical communications the term repeater is used to describe a piece of equipment that
receives an optical signal, converts that signal into an electrical one, regenerates it, and then
retransmits an optical signal. Since such a device converts the optical signal into an electrical
one, and then back to an optical signal, they are often known as OpticalElectrical-Optical (OEO)
repeaters.

NETWORK TOPOLOGY

 Point-to-point topology
 Bus (point-to-multipoint) topology

 Star topology

 Ring topology

 Tree topology

 Mesh topology

 Hybrid topology

This classification is based on the interconnection between computers — be it physical or


logical.

The physical topology of a network is determined by the capabilities of the network access
devices and media, the level of control or fault tolerance desired, and the cost associated with
cabling or telecommunications circuits.

Bus

Bus network topology

In local area networks where bus topology is used, each machine is connected to a single cable.
Each computer or server is connected to the single bus cable through some kind of connector. A
terminator is required at each end of the bus cable to prevent the signal from bouncing back and
forth on the bus cable. A signal from the source travels in both directions to all machines
connected on the bus cable until it finds the MAC address or IP address on the network that is the
intended recipient. If the machine address does not match the intended address for the data, the
machine ignores the data. Alternatively, if the data does match the machine address, the data is
accepted. Since the bus topology consists of only one wire, it is rather inexpensive to implement
T.E. (Comp) Computer Network Lab

when compared to other topologies. However, the low cost of implementing the technology is
offset by the high cost of managing the network. Additionally, since only one cable is utilized, it
can be the single point of failure. If the network cable breaks, the entire network will be down.

Star

A star topology is designed with each node (file server, workstations, and peripherals) connected
directly to a central network hub, switch, or concentrator (See fig.)

Data on a star network passes through the hub, switch, or concentrator before continuing to its
destination. The hub, switch, or concentrator manages and controls all functions of the network.
It also acts as a repeater for the data flow. This configuration is common with twisted pair cable;
however, it can also be used with coaxial cable or fiber optic cable.

Advantages of a Star Topology

 Easy to install and wire.


 No disruptions to the network when connecting or removing devices.

 Easy to detect faults and to remove parts.

Disadvantages of a Star Topology

 Requires more cable length than a linear topology.


 If the hub, switch, or concentrator fails, nodes attached are disabled.

 More expensive than linear bus topologies because of the cost of the hubs, etc.

Tree or Expanded Star


T.E. (Comp) Computer Network Lab

A tree topology combines characteristics of linear bus and star topologies. It consists of groups of
star-configured workstations connected to a linear bus backbone cable (See fig.). Tree topologies
allow for the expansion of an existing network, and enable schools to configure a network to
meet their needs.

Advantages of a Tree Topology

 Point-to-point wiring for individual segments.


 Supported by several hardware and software venders.

Disadvantages of a Tree Topology

 Overall length of each segment is limited by the type of cabling used.


 If the backbone line breaks, the entire segment goes down.

 More difficult to configure and wire than other topologies.

PROCEDURE

There are generally three main types of networking cables: straight-through, crossover
Rollover cables.

The Purpose of Straight-Through Cables :Straight-through cables get their name from how
they are made. Out of the 8 pins that exist on both ends of an Ethernet cable, each pin connects to
the same pin on the opposite side. Review the diagram below for a visual example:
T.E. (Comp) Computer Network Lab

OR

Notice how each wire corresponds to the same pin. This kind of wiring diagram is part of the
568A standard. The 568B standard achieves the same thing, but through different wiring. It is
generally accepted to use the 568A standard as pictured, since it allows compatibility with
certain telephone hardware- while 568B doesn’t.

Straight-through cables are primarily used for connecting unlike devices. A straight-through
cable is typically used in the following situations:

Use a straight-through cable when:

 Connecting a router to a hub


 Connecting a computer to a switch

 Connecting a LAN port to a switch, hub, or computer

The purpose of Crossover Cables

Crossover cables are very similar to straight-through cables, except that they have pairs of wires
that crisscross. This allows for two devices to communicate at the same time. Unlike straight-
through cables, we use crossover cables to connect like devices. A visual example can be seen
below:

Use a crossover cable when:

 Connecting a computer to a router


T.E. (Comp) Computer Network Lab

 Connecting a computer to a computer

 Connecting a router to a router

 Connecting a switch to a switch

 Connecting a hub to a hub

While the rule of thumb is to use crossover cables with like devices, some devices do not follow
standards. Others provide support for both types of cables. However, there is still something that
both crossover and straight-through cables can’t do.

The Purpose of Rollover Cables

Rollover cables, like other cabling types, got their name from how they are wired. Rollover
cables essentially have one end of the cable wired exactly opposite from the other. This
essentially “rolls over” the wires- but why would we need to do such a thing? Rollover cables,
also called Yost cables, usually connect a device to a router or switch’s console port. This allows
a programmer to make a connection to the router or switch, and program it as needed. A visual
example can be seen below:

Notice that each wire is simply “rolled over.” These types of cables are generally not used very
much, so are usually colored differently from other types of cables.

APPLICATION

1. Most networks in the real world use the above-mentioned devices to create networks.
T.E. (Comp) Computer Network Lab

Conclusion: Thus the concept of various network components was understood along with the
different categories of Networks and how to form them.

Assignment No: 2 (Group A)


T.E. (Comp) Computer Network Lab

Aim: Introduction to RS 232 and demonstration of Framing, Flow & Error Control in data
Link Layer

Objective:

To learn to perform PC-to-PC communication using the RS-232 port

To understand the concept of Data link layer, its functions and its implementation

Pre-requisite: Knowledge of Data Link Layer and Basics of Network

Theory: Introduction to RS(Recommended Standard)-232:

RS-232 standards(EIA-232) are defined by EIA/TIA (Electronic Industries Alliance


/Telecommunications Industry Association). RS-232 defines both the physical and electrical
characteristics of the interface. RS-232 is practically identical to ITU V.24 (signal description
and names) and V.28 (electrical). RS232 is an Active LOW voltage driven interface and operates
at +12V to -12V where:

Signal = 0 (LOW) > +3.0V (SPACE)


Signal = 1 (HIGH) < -3.0V (MARK)

1. Signal voltages in the range >-3.0V to +3.0V are regarded as being in the 'dead area'
(indeterminate value) and allow for absorption of noise. For more on the use of signals and other
heavy stuff.
2. The power level on RS232 pins is defined by TIA for short circuit protection to be 100mA.
Most RS232 drivers will provide lower short circuit protection (especially for laptops). A max of
50mA PER PIN may be available but the data sheet for the specific interface/chip should be
consulted before commiting to externally powered designs.

RS-232 standards(EIA-232) are defined by EIA/TIA. They have defined following standards

1. RS232 on DB9 and DB25 known as RS-232C


2. RS232 on DB9 and DB25 known as EIA/TIA - 574
3. RS232 on DB9 and DB25 known as RS-232D
4. RS232 on RJ45 known as RS-232D EIA/TIA-561
5. RS422,423 and 435 on DB25 Known as EIA/TIA RS-530-A

RS232 is the most known serial port used in transmitting the data in communication and
interface. Even though serial port is harder to program than the parallel port, this is the most
effective method in which the data transmission requires less wires that yields to the less cost.
The RS232 is the communication line which enables the data transmission by only using three
wire links. The three links provides ‘transmit’, ‘receive’ and common ground.

The ‘transmit’ and ‘receive’ line on this connecter send and receive data between the computers.
As the name indicates, the data is transmitted serially. The two pins are TXD & RXD. There are
other lines on this port as RTS, CTS, DSR, DTR, and RTS, RI. The ‘1’ and ‘0’ are the data which
defines a voltage level of 3V to 25V and -3V to -25V respectively.
T.E. (Comp) Computer Network Lab

The electrical characteristics of the serial port as per the EIA (Electronics Industry Association)
RS232C Standard specifies a maximum baud rate of 20,000bps, which is slow compared to
today’s standard speed. For this reason, we have chosen the new RS232D Standard, which was
recently released.

The RS-232D has existed in two types. i.e., D-TYPE 25 pin connector and D-TYPE 9 pin
connector, which are male connectors on the back of the PC. You need a female connector on
your communication from Host to Guest computer. The pin outs of both D9 & D-25 are show
below.

DTE (PC) and DCE (Modem)


Devices, which use serial cables for their communication, are split into two categories. These are
DCE (Data Communications Equipment) and DTE (Data Terminal Equipment.) Data
Communications Equipments are devices such as your modem, TA adapter, plotter etc while
Data Terminal Equipment is your Computer or Terminal. A typical Data Terminal Device is a
computer and a typical Data Communications Device is a Modem. Often people will talk about
DTE to DCE or DCE to DCE speeds. DTE to DCE is the speed between your modem and
computer, sometimes referred to as your terminal speed. This should run at faster speeds than the
DCE to DCE speed. DCE to DCE is the link between modems, sometimes called the line speed.

Most people today will have 28.8K or 33.6K modems. Therefore, we should expect the DCE to
DCE speed to be either 28.8K or 33.6K. Considering the high speed of the modem we should
expect the DTE to DCE speed to be about 115,200 BPS. (Maximum Speed of the 16550a UART)
. The communications program, which we use, has settings for DCE to DTE speeds. However,
the speed is 9.6 KBPS, 144 KBPS etc and the modem speed.

If we were transferring that text file at 28.8K (DCE- DCE), then when the modem compresses it
you are actually transferring 115.2 KBPS between computers and thus have a DCE- DTE speed
of 115.2 KBPS. Thus, this is why the DCE- DTE should be much higher than the modem's
connection speed. Therefore, if our DTE to DCE speed is several times faster than our DCE to
DCE speed the PC can send data to your modem at 115,200 BPS.

In serial communications the terminal end (PC) is called the Data Terminal Equipment (DTE)
and the modem end is called the Data Communications Equipment (DCE) as shown in the
diagram below.

Serial Communications with a modem

RS-232 signals have a direction (in or out) depending on whether they are with respect to a DTE
or a DCE. In all the pinout diagrams below the signal direction is with respect to the DTE (PC)
end.
T.E. (Comp) Computer Network Lab

What is NULL MODEM?


Null modem is used to connect two DTE's together. This is used to transfer files between the
computers using protocols like Zmodem protocol, xmodem protocol, etc
When PCs are connected back-to-back each end is acting as a DTE (there is no DCE in this case)
and consequently certain signals may have to be looped in the connection to satisfy any input
signal requirement. This is called a NULL (no) modem configuration. For example, when the
DTE raises Request to Send (RTS) it typically expects Clear to Send (CTS) from the DCE. Since
there is no DCE to raise CTS, the outgoing RTS signal is looped in the NULL modem cable to
the incoming CTS to satisfy the DTE's need for this signal

DB9 Male and Female Views

DB9: View looking into male connector

DB9: View looking into female connector

DB25 Male and Female Views


T.E. (Comp) Computer Network Lab

DB9: View looking into male connector

DB25: View looking into female connector

RS232C - DB9 and DB25 Pinout

Pin
Name Dir Description
No.
1- - Protective/shielded ground
2TD OUT Transmit Data (a.k.a TxD, Tx) (ASYNC)
3RD IN Receive Data (a.k.a RxD, Rx) (ASYNC)
4RTS OUT Request To Send (ASYNC)
5CTS IN Clear To Send (ASYNC)
6DSR IN Data Set Ready (ASYNC)
7SGND - Signal Ground
8CD IN Carrier Detect (a.k.a DCD).
9,10 - - Reserved for data set testing.
11 - - Unassigned
Secondary Carrier Detect. Only needed if second channel being
12 SDCD IN
used.
T.E. (Comp) Computer Network Lab

Secondary Clear to send. Only needed if second channel being


13 SCTS IN
used.
Secondary Transmit Data. Only needed if second channel being
14 STD OUT
used.
15 DB OUT Transmit Clock (a.k.a TCLK, TxCLK). Synchronous use only.
Secondary Receive Data. Only needed if second channel being
16 SRD IN
used.
17 DD IN Receive Clock (a.k.a. RCLK). Synchronous use only.
18 LL - Local Loopback
Secondary Request to Send. Only needed if second channel
19 SRTS OUT
being used.
20 DTR OUT Data Terminal Ready. (ASYNC)
21 RL/SQ - Signal Quality Detector/Remote loopback

Ring Indicator. DCE (Modem) raises when incoming call


22 RI IN
detected used for auto answer applications.
23 CH/CI OUT Signal Rate selector.
24 DA - Auxiliary Clock (a.k.a. ACLK). Secondary Channel only.
25 - - Unassigned

C-Type-9 Pin D-Type-9 pin D-Type-25 pin


Pin outs Function
no no. no.
3 3 2 RD Receive Data (Serial data input)
2 2 3 TD Transmit Data (Serial data output)
4 7 4 RTS Request to send
5 8 5 CTS Clear to send
6 6 6 DSR Data ready state
7 5 7 SG Signal ground
8 1 8 DCD Data Carrier detect
9 4 20 DTR Data Terminal Ready.
1 9 22 RI Protective Ground / Ring Indicator
T.E. (Comp) Computer Network Lab

RS232D on DB9 (EIA/TIA 574)


Signal functions are described in detail in our Signal/pin primer. The column
marked Dir shows the signal direction with respect to the DTE.
Pin
No Name Dir Notes/Description
1 DCD IN Data Carrier Detect. Raised by DCE when modem synchronized.
2 RD IN Receive Data (a.k.a RxD, Rx). Arriving data from DCE.
3 TD OUT Transmit Data (a.k.a TxD, Tx). Sending data from DTE.
4 DTR OUT Data Terminal Ready. Raised by DTE when powered on. In auto-
answer mode raised only when RI arrives from DCE.
5 SGND - Ground
6 DSR IN Data Set Ready. Raised by DCE to indicate ready.
7 RTS OUT Request To Send. Raised by DTE when it wishes to send. Expects
CTS from DCE.
8 CTS IN Clear To Send. Raised by DCE in response to RTS from DTE.
9 RI IN Ring Indicator. Set when incoming ring detected - used for auto-
answer application. DTE raised DTR to answer.

NULL MODEM Connections(RS232C)


When PCs are connected back-to-back each end is acting as a DTE (there is no DCE in
this case) and consequently certain signals may have to be looped in the connection to
satisfy any input signal requirement. This is called a NULL (no) modem configuration.
For example, when the DTE raises Request to Send (RTS) it typically expects Clear to
Send (CTS) from the DCE. Since there is no DCE to raise CTS, the outgoing RTS signal
is looped in the NULL modem cable to the incoming CTS to satisfy the DTE's need for
this signal. This is shown in the diagram below.

Serial Communications with a NULL modem configuration


Use when connecting two systems, for example two PCs, via their DB9 interfaces
without a modem. Typically called a back-to-back or NULL modem connection.
T.E. (Comp) Computer Network Lab

DB9 Signal DB9 Signal


Protective Protective
1 1
Ground Ground
2 TXD 3 RXD
3 RxD 2 TXD
RTS CTS
4 5
CTS RTS
5 4
Looped Back Looped Back
DTR,DSR DTR,DSR
6,8 6,8
Looped Back Looped Back
7 SG 7 SG

Above-mentioned figure shows the wiring of the null modem. The main feature indicated
here is that the to make the computer to chat with the modem rather than another
computer. The guest & host computer connected through the TD, RD, and SG pins. Any
data that is transmitted through TD line from the Host to Guest is received on RD line.
The Guest computer must have the same setup as the Host. The signal ground (SG) line
of the both must be shorted so that grounds are common to each computer.
The Data Terminal Ready (DTR) is looped back to Data Set Ready and
Carrier Detect on both computers. When the Data Terminal Ready is asserted
active, then the Data Set Ready and Carrier Detect immediately become active. At
this point, the computer thinks the Virtual Modem to which it is connected is ready
and has detected the carrier of the other modem.
All left to worry about now is the Request to Send and Clear To Send. As both
computers communicate together at the same speed, flow control is not needed thus
these two lines are also linked together on each computer. When the computer wishes to
send data, it asserts the Request to Send high and as it is hooked together with the Clear
to Send, It immediately gets a reply that it is ok to send and does so.
The Ring indicator line is only used to tell the computer that there is a ringing
signal on the phone line. As we do not have, a modem connected to the phone line this is
left disconnected
To know about the RS232 ports available in your computer, Right click on "My
Computer", Goto 'Properties', Select tab 'Device Manager', go to Ports( COM & LPT ),
In that you will find 'Communication Port(Com1)' etc. If you right click on that and go to
properties, you will get device status. Make sure that you have enabled the port( Use this
port is selected).
Modem Connections for RS232D
If this pinout does not work for you then you could try our Signal/pin primer because
you may need to SPOOF connections.

DB9 Signal DB9 Signal


2 RD 3 TD
3 TD 2 RD
T.E. (Comp) Computer Network Lab

4 DTR 6,1 DSR, DCD

DSR,
6,1 4 DTR
DCD
7 RTS 8 CTS
8 CTS 7 RTS
5 SGND 5 SGND
9 RI 9 RI

Figure: Above shows the connections of the Null modem using RS-232D connecter

How to program the Serial Port using C/C++?


There are two popular methods of sending data to or from the serial port in Turbo C.
I. One is using outportb(PORT_ID, DATA) or
outport(PORT_ID,DATA) defined in “dos.h”.
II. Another method is using bioscom() function defined in “bios.h”.

Using outportb() :
The function outportb () sends a data byte to the port ‘PORT_ID’. The
function outport() sends a data word. These functions can be used for any port
including serial port, parallel ports. Similarly to receive data these are used.

 inport reads a word from a hardware port


 inportb reads a byte from a hardware port
T.E. (Comp) Computer Network Lab

 outport outputs a word to a hardware port


 outportb outputs a byte to a hardware port

Declaration:
 int inport(int portid);
 unsigned char inportb(int portid);
 void outport(int portid, int value);
 void outportb(int portid, unsigned char value);

Remarks:
 inport works just like the 80x86 instruction IN. It reads the low
byte of a word from portid, the high byte from portid + 2.
 inportb is a macro that reads a byte
 outport works just like the 80x86 instruction OUT. It writes the
low byte of value to portid, the high byte to portid + 1.
 outportb is a macro that writes value Argument
portid:

 Inport- port that inport and inportb read from;


 Outport- port that outport and outportb write to value:
 Word that outport writes to portid;
 Byte- that outportb writes to portid.

If you call inportb or outportb when dos.h has been included, they are treated
as macros that expand to inline code.
If you don't include dos.h, or if you do include dos.h and #undef the macro(s),
you get the function(s) of the same name.

Return Value:
# inport and inportb return the value read
# outport and outportb do not return

For more details of these functions read article from beondlogic.com

Using bioscom:
The macro bioscom () and function _bios_serialcom() are used in this method in the
serial communication using RS-232 connecter. First we have to set the port with the
T.E. (Comp) Computer Network Lab

settings depending on our need and availability. In this method, same function is used to
make the settings using control word, to send data to the port and check the status of the
port. These actions are distinguished using the first parameter of the function. Along with
that we are sending data and the port to be used to communicate.
Here are the deatails of the Turbo C Functions for communication ports.

Declaration:
bioscom(int cmd, char abyte, int port)
_bios_serialcom(int cmd ,int port, char abyte)
bioscom() and _bios_serialcom() uses the bios interrupt 0x14 to perform various
communicate the serial communication over the I/O ports given in port.
cmd: The I/O operation to be performed.

cmd (boiscom) cmd(_bios_serialcom) Action

0 _COM_INIT Initialise the parameters to the port


1 _COM_SEND Send the character to the port
2 _COM_RECEIVE Receive character from the port
Returns the current status of the
3 _COM_STATUS
communication port

portid: port to which data is to be sent or from which data is to be read.


0: COM1
1: COM2
2: COM3

abyte:
when cmd =2 or 3 (_COM_SEND or _COM_RECEIVE) parameter abyte is ignored.
When cmd = 0 (_COM_INIT), abyte is an OR combination of the following bits (One
from each group):
T.E. (Comp) Computer Network Lab

value of abyte
Meaning
Bioscom _bios_serialcom
0x02 _COM_CHR7 7 data bits
0x03 _COM_CHR8 8 data bits
0x00 _COM_STOP1 1 stop bit
0x04 _COM_STOP2 2 stop bits
0x00 _COM_NOPARITY No parity
0x08 _COM_ODDPARITY Odd parity
0X10 _COM_EVENPARITY Even parity

0x00 _COM_110 110 baud

0x20 _COM_150 150 baud

0x40 _COM_300 300 baud

0x60 _COM_600 600 baud

0x80 _COM_1200 1200 baud

0xA0 _COM_2400 2400 baud


0xC0 _COM_4800 4800 baud
0xE0 _COM_9600 9600 baud

For example, if
abyte = 0x8B = (0x80 | 0x08 | 0x00 | 0x03) = (_COM_1200 | _COM_ODDPARITY |
_COM_STOP1 | _COM_CHR8)

the communications port is set to


1200 baud (0x80 = _COM_1200)

Odd parity (0x08 = _COM_ODDPARITY)


1 stop bit (0x00 = _COM_STOP1)
8 data bits (0x03 = _COM_CHR8)

To initialise the port with above settings we have to write,


bioscom(0, 0x8B, 0);
To send a data to COM1, the format of the function will be bioscom(1, data, 0).
T.E. (Comp) Computer Network Lab

Similarly bioscom(1, 0, 0 ) will read a data byte from the port.


The following example illustrate how to serial port programs. When a data is available in
the port, it inputs the data and displays onto the screen and if a key is pressed the ASCII value
will be sent to the port.

#include <bios.h>
#include <conio.h>
#define COM1 0
#define DATA_READY 0x100
#define SETTINGS ( 0x80 | 0x02 | 0x00 | 0x00)
int main(void)
{
int in, out, status;
bioscom(0, SETTINGS, COM1); /*initialize the port*/
cprintf("Data sent to you: ");
while (1)
{
status = bioscom(3, 0, COM1); /*wait until get a data*/
if (status & DATA_READY)
if ((out = bioscom(2, 0, COM1) & 0x7F) != 0) /*input a data*/
putch(out);
if (kbhit())
{
if ((in = getch()) == 27) /* ASCII of Esc*/
break;
bioscom(1, in, COM1); /*output a data*/
}
}
return 0;
}

When you compile and run the above program in both the computers, The characters typed
in one computer should appear on the other computer screen and vice versa. Initially, we set
the port to desired settings as defined in macro settings. Then we waited in an idle loop until
a key is pressed or a data is available on the port. If any key is pressed, then kbhit() function
returns non zero value. So will go to getch function where we are finding out which key is
pressed. Then we are sending it to the com port. Similarly, if any data is available on the
port, we are receiving it from the port and displaying it on the screen.

To check the port, If you have a single computer, you can use loop-back
connection as follows. This is most commonly used method for developing
T.E. (Comp) Computer Network Lab

communication programs. Here, data is transmitted to that port itself. Loop-back plug
connection is as follows.

If you run the above program with the connection as in this diagram, the character
entered in the keyboard should be displayed on the screen. This method is helpful in
writing serial port program with single computer. Also you can make changes in the port
id if your computer has 2 rs232ports. You can connect the com1 port to com2 of the same
computer and change the port id in the program. The data sent to the port com1 should
come to port com2. then also whatever you type in the keyboard should appear on the
screen.

Sample Program for Linux


PROGRAM:

Sender:

/* Sender*/

#include <stdio.h> /* Standard input/output definitions */

#include <string.h> /* String function definitions */

#include <unistd.h> /* UNIX standard function definitions */

#include <fcntl.h> /* File control definitions */

#include <errno.h> /* Error number definitions */

#include <termios.h> /* POSIX terminal control definitions */

/ sudo chmod a+rw /dev/ttyS0

/*

* 'open_port()' - Open serial port 1.


T.E. (Comp) Computer Network Lab

* Returns the file descriptor on success or -1 on


error. */

int open_port(void)

int fd; /* File descriptor for the port */

fd = open("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NDELAY);


if (fd == -1)

{ /* Could not open the port */

fprintf(stderr, "open_port: Unable to open /dev/ttyS0 - %s\n",

strerror(errno));

else

printf(" Port Opened Successfully\n");

return (fd);

void main()

int mainfd=0,n=0; /* File descriptor */ char chout;

struct termios options;

mainfd = open_port();

fcntl(mainfd, F_SETFL, FNDELAY); /* Configure port reading */

/* Get the current options for the port */

tcgetattr(mainfd, &options);
T.E. (Comp) Computer Network Lab

cfsetispeed(&options, B9600); /* Set the baud rates to 9600 */

cfsetospeed(&options, B9600);

/* Enable the receiver and set local mode


*/ options.c_cflag |= (CLOCAL | CREAD);

options.c_cflag &= ~PARENB; /* Mask the character size to 8 bits, no parity */

options.c_cflag &= ~CSTOPB;

options.c_cflag &= ~CSIZE;

options.c_cflag |= CS8; /* Select 8 data bits */

options.c_cflag &= ~CRTSCTS; /* Disable hardware flow control */

/* Enable data to be processed as raw input */

options.c_lflag &= ~(ICANON | ECHO | ISIG);

/* Set the new options for the port */

tcsetattr(mainfd, TCSANOW, &options);

while (1)

n=read(mainfd, &chout, sizeof(chout)); /* Read character from ABU */

/* if(n==0) printf("\n No User Input");

else

printf("User input =%d",n);*/

if (chout != 0)

printf("%c\n", chout);

chout=0;

//usleep(2000);
T.E. (Comp) Computer Network Lab

/* Close the serial port */

close(mainfd);

Reciever:

#include<stdio.h>
#include<termios.h>
#include<unistd.h>
#include<fcntl.h>
#include<string.h>
#include<errno.h>

int open_port()
{
int fd = 0;
fd = open("/dev/ttyS0",O_RDWR|O_NOCTTY|O_NDELAY);
if(fd == -1)
{
printf("Failed to connect!");
}
else return(fd);
}

int main()
{
int mfd = 0, n = 0;
char chout[20];
int i=0;
struct termios options;
mfd = open_port();
tcgetattr(mfd,&options);
cfsetispeed(&options,B9600);
cfsetospeed(&options,B9600);
options.c_cflag |= (CLOCAL|CREAD);
options.c_cflag &= ~PARENB;
options.c_cflag &= ~CSTOPB;
options.c_cflag &= ~CSIZE;

options.c_cflag |= CS8;
options.c_cflag &= ~CRTSCTS;
options.c_lflag &= ~(ICANON|ECHO|ISIG);
tcsetattr(mfd,TCSANOW,&options);
/*while(1)
{
n = read(mfd,&chout,sizeof(chout));
if(chout != 0)
T.E. (Comp) Computer Network Lab

{
printf("Received %c \n",chout[i]);
i++;
}
else
{
printf("Received failed");
break;
}
}*/
while(1)
{
n = write(mfd, "ATZ Manik\r",10);
if(n<0)
{
printf("Failed to send or transmit");
break;
}
}
close(mfd);
return 0;
}

APPLICATION

1. Serial port communication is used in many applications

FAQS

Please refer the above theory for answers

1. Explain the concept of a null modem


2. What are the means of accessing the serial port using code?
3. How do you set the various parameters associated with the communication
channel
T.E. (Comp) Computer Network Lab

Assignment No: 3 (Group A)

Aim: Write a program for error detection and correction for 7/8 bits ASCII codes using
Hamming Codes or CRC. Demonstrate the packets captured traces using Wireshark
Packet Analyzer Tool for peer to peer mode

Objective:

To understand the concept of hamming Code for error detection & Correction

To use the Wire shark Packet Analyzer Tool

Pre-requisite: Knowledge of Error detection & Correction and its use.

Theory: Hamming code is a set of error-correction codes that can be used to detect and
correct bit errors that can occur when computer data is moved or stored. Hamming code is
named for R. W. Hamming of Bell Labs. Like other error-correction code, Hamming code makes
use of the concept of parity and parity bit s, which are bits that are added to data so that the
validity of the data can be checked when it is read or after it has been received in a data
transmission. Using more than one parity bit, an error-correction code can not only identify a
single bit error in the data unit, but also its location in the data unit.
Calculate a Hamming code word that can correct 1-bit errors in the ASCII code for a line feed,
LF, 0x0a. We are going to calculate a code word that is capable of correcting all single-bit errors
in an 8-bit data element.

In the code word, there are m data bits and r redundant (check) bits, giving a total of n code word
bits.
n=m+r
Each valid code word of n bits contains m valid data bits. For each valid m-bit data entity, there
are n bits that can be changed to give an invalid code word. Thus the total number of code words
corresponding to a valid data entity is n+1 (n invalid plus 1 valid code word). As there are 2m
valid data patterns, the total number of code words is (n+1)2m. In an n-bit code word, the
possible number of patterns is 2n , and this limits the number of valid + invalid codes that can
exist.
Thus (n+1)2m ≤ 2 n
and, since n = m + r,
(m+r+1)2m ≤ 2 m+r
so (m+r+1)≤ 2 r
The least number of redundant bits that satisfies this inequality when m = 8 is r = 4 bits.
Thus, we have a 12-bit code word. Bits 1, 2, 4 and 8 will be the check bits.
The code word will be of the form rr0r 000r 1010 and we shall use even parity.

Code word r r 0 r 0 0 0 r 1 0 1 0
T.E. (Comp) Computer Network Lab

Bit No. 1 2 3 4 5 6 7 8 9 10 11 12

Approach to a solution

1. Decide on the number of bits in the code word


2. Determine the bit positions of the check bits
3. Determine which parity bits check which positions
4. Calculate the values of the parity bits
The bit positions covered by each parity bit can be calculated by writing each bit position as a
sum of the powers of 2:

1=1
2=2
3=1+2
4=4
5=1+4
6=2+4
7=1+2+4
8=8
9=1+8
10 = 2 + 8
11 = 3 + 8
12 = 4 + 8

Thus, Check bit 1 governs positions 1, 3, 5, 7, 9: Value = 1 (0 0 0 1)


Check bit 2 governs positions 2, 3, 6, 7, 10: Value = 0 (0 0 0 0)
Check bit 4 governs positions 4, 5, 6, 7, 12 = 0 (0 0 0 0)
Check bit 8 governs positions 8, 9, 10, 11, 12 = 0 (1 0 1 0)

Thus, the complete code word is 1000 0000 1010.

A 1-bit error in this code word can be corrected as follows:

First, calculate the parity bits. If all are correct, there is either no error, or errors in more than 1
bit. However, we are limiting ourselves to single-bit errors here. If the parity bits show an error,
add up all the erroneous parity bits, counting 1 for bit 1, 2 for bit 2, 4 for bit 4 and 8 for bit 8.
The result gives the position of the erroneous bit, which can be complemented to give the
correction.

For example, assume the code word is corrupted to give 1010 0000 1010.
Check parity:
Bit 1: B1 ⊕ B3 ⊕ B5 ⊕ B7 ⊕ B9 = 1 ⊕ 1 ⊕ 0 ⊕ 0 ⊕ 1 = 1
T.E. (Comp) Computer Network Lab

Bit 2: B2 ⊕ B3 ⊕ B6 ⊕ B7 ⊕ B10 = 0 ⊕ 1 ⊕ 0 ⊕ 0 ⊕ 0 = 1
Bit 4: B4 ⊕ B5 ⊕ B6 ⊕ B7 ⊕ B12 = 0 ⊕ 0 ⊕ 0 ⊕ 0 ⊕ 0 = 0
Bit 8: B8 ⊕ B9 ⊕ B10 ⊕ B11 ⊕ B12 = 0 ⊕ 1 ⊕ 0 ⊕ 1 ⊕ 0 = 0
Thus the error is in bit position 1 + 2 = 3, and bit 3 can be inverted to give the correct codeword:
1000 0000 1010

Conclusion: Thus the concept and use of Hamming code for Error detection & Correction was
understood with example & program.

Assignment No: 8 (Group A) & Assignment No 4 (Group B)

Aim: Write a program using UDP Sockets to enable file transfer (Script, Text, Audio and
Video one file each) between two machines. Demonstrate the packets captured traces using
Wire shark Packet Analyzer Tool for peer to peer mode.

Objective: To understand the concept of Socket, its type and implementation

To use the Wire shark Packet Analyzer Tool

Pre-requisite: Knowledge of protocols like TCP and UDP, basics of sockets and its use.

Theory: Sockets are the endpoints of a bidirectional communications channel. Sockets may
communicate within a process, between processes on the same machine, or between processes on
different continents. Sockets are bidirectional, meaning that either side of the connection is
capable of both sending and receiving data. Sometimes the one application that initiates
communication is termed the client and the other application the server

Sockets may be implemented over a number of different channel types: UNIX domain sockets,
TCP, UDP, and so on. The socket library provides specific classes for handling the common
transports as well as a generic interface for handling the rest.

Sockets have their own vocabulary:

Term Description
The family of protocols that will be used as the transport mechanism. These
domain values are constants such as AF_INET, PF_INET, PF_UNIX, PF_X25, and so
on.
The type of communications between the two endpoints, typically
type SOCK_STREAM for connection-oriented protocols and SOCK_DGRAM for
connectionless protocols.
Typically zero, this may be used to identify a variant of a protocol within a
protocol
domain and type.
hostname The identifier of a network interface:
 A string, which can be a host name, a dotted-quad address, or an IPV6
address in colon (and possibly dot) notation
T.E. (Comp) Computer Network Lab

 A string "<broadcast>", which specifies an INADDR_BROADCAST


address.
 A zero-length string, which specifies INADDR_ANY, or

 An Integer, interpreted as a binary address in host byte order.


Each server listens for clients calling on one or more ports. A port may be a
port Fixnum port number, a string containing a port number, or the name of a
service.

The socket Module:

To create a socket, you must use the socket.socket() function available in socket module, which
has the general syntax:

s = socket.socket (socket_family, socket_type, protocol=0)

Here is the description of the parameters:

 socket_family: This is either AF_UNIX or AF_INET, as explained earlier.


 socket_type: This is either SOCK_STREAM or SOCK_DGRAM.
 protocol: This is usually left out, defaulting to 0.

Programming with UDP/IP socket

There are a few steps involved in using sockets:

1. Create the socket


2. Identify the socket (name it)
3. On the server, wait for a message
4. On the client, send a message
5. Send a response back to the client (optional)
6. Close the socket

Step 1. Create a socket


A socket, s, is created with the socket system call:

For UDP/IP sockets, we want to specify the IP address family (AF_INET) and datagram service
(SOCK_DGRAM). Since there's only one form of datagram service, there are no variations of
the protocol, so the last argument, protocol, is zero. Our code for creating a UDP socket looks
like this:
T.E. (Comp) Computer Network Lab

#include <sys/socket.h>
...
if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
perror("cannot create socket");
return 0;
}
Step 2. Identify (name) a socket
When we talk about naming a socket, we are talking about assigning a transport address to the
socket (a port number in IP networking). In sockets, this operation is called binding an address
and the bindsystem call is used to do this. The analogy is that of assigning a phone number to the
line that you requested from the phone company in step 1 or that of assigning an address to a
mailbox.

The transport address is defined in a socket address structure. Because sockets were designed to
work with various different types of communication interfaces, the interface is very general.
Instead of accepting, say, a port number as a parameter, it takes a sockaddr structure whose
actual format is determined on the address family (type of network) you're using. For example, if
you're using UNIX domain sockets, bind actually creates a file in the file system.

The system call for bind is:

#include <sys/socket.h>

int

bind(int socket, const struct sockaddr *address, socklen_t address_len);

The first parameter, socket, is the socket that was created with the socket system call.For the
second parameter, the structure sockaddr is a generic container that just allows the OS to be able
to read the first couple of bytes that identify the address family. The address family determines
what variant of the sockaddr struct to use that contains elements that make sense for that specific
communication type. For IP networking, we use struct sockaddr_in, which is defined in the
header netinet/in.h.

This structure defines:

struct sockaddr_in {

__uint8_t sin_len;
T.E. (Comp) Computer Network Lab

sa_family_t sin_family;

in_port_t sin_port;

struct in_addr sin_addr;

char sin_zero[8];

};

Before calling bind, we need to fill out this structure. The three key parts we need to set are:

sin_family

The address family we used when we set up the socket. In our case, it's AF_INET.

sin_port
The port number (the transport address). You can explicitly assign a transport address
(port) or allow the operating system to assign one. If you're a client and don't need a well-
known port that others can use to locate you (since they will only respond to your
messages), you can just let the operating system pick any available port number by
specifying port 0. If you're a server, you'll generally pick a specific number since clients
will need to know a port number to which to address messages.

sin_addr
The address for this socket. This is just your machine's IP address. With IP, your machine
will have one IP address for each network interface. For example, if your machine has
both Wi-Fi and ethernet connections, that machine will have two addresses, one for each
interface. Most of the time, we don't care to specify a specific interface and can let the
operating system use whatever it wants. The special address for this is 0.0.0.0, defined by
the symbolic constant INADDR_ANY.

Since the address structure may differ based on the type of transport used, the third parameter
specifies the length of that structure. This is simply the size of the internet address
structure, sizeof(struct sockaddr_in).

The code to bind a socket looks like this:

#include <sys/socket.h>

...
struct sockaddr_in myaddr;
/* bind to an arbitrary return address */
T.E. (Comp) Computer Network Lab

/* because this is the client side, we don't care about the address */
/* since no application will initiate communication here - it will */
/* just send responses */
/* INADDR_ANY is the IP address and 0 is the socket */
/* htonl converts a long integer (e.g. address) to a network representation */
/* htons converts a short integer (e.g. port) to a network representation */

memset((char *)&myaddr, 0, sizeof(myaddr));


myaddr.sin_family = AF_INET;
myaddr.sin_addr.s_addr = htonl(INADDR_ANY);
myaddr.sin_port = htons(0);
if (bind(fd, (struct sockaddr *)&myaddr, sizeof(myaddr)) < 0) {
perror("bind failed");
return 0;
}
Step 3a. Send a message to a server from a client
With TCP sockets, we had to establish a connection before we could communicate. With UDP,
our sockets are connectionless. Hence, we can send messages immediately. Since we do not have
a connection, the messages have to be addressed to their destination. Instead of using
a write system call, we will use sendto, which allows us to specify the destination. The address is
identified through the sockaddrstructure, the same way as it is in bind and as we did when
using connect for TCP sockets.

#include <sys/types.h>

#include <sys/socket.h>

int

sendto(int socket, const void *buffer, size_t length, int flags, const struct sockaddr *dest_addr,

socklen_t dest_len)

The first parameter, socket, is the socket that was created with the socket system call and named
via bind. The second parameter, buffer, provides the starting address of the message we want to
T.E. (Comp) Computer Network Lab

send. length is the number of bytes that we want to send. The flags parameter is 0 and not useful
for UDP sockets. The dest_addr defines the destination address and port number for the message.
It uses the same sockaddr_in structure that we used in bind to identify our local address. As
with bind, the final parameter is simply the length of the address structure: sizeof(struct
sockaddr_in).

The server's address will contain the IP address of the server machine as well as the port number
that corresponds to a socket listening on that port on that machine. The IP address is a four-byte
(32 bit) value in network byte order (see htonl above).

In most cases, you'll know the name of the machine but not its IP address. An easy way of getting
the IP address is with the gethostbyname library (libc) function. Gethostbyname accepts a host
name as a parameter and returns a hostent structure:

struct hostent {

char *h_name; /* official name of host */

char **h_aliases; /* alias list */

int h_addrtype; /* host address type */

int h_length; /* length of address */

char **h_addr_list; /* list of addresses from name server */

};

If all goes well, the h_addr_list will contain a list of IP addresses. There may be more than one IP
addresses for a host. In practice, you should be able to use any of the addresses or you may want
to pick one that matches a particular subnet. You may want to check that (h_addrtype ==
AF_INET) and (h_length == 4) to ensure that you have a 32-bit IPv4 address. We'll be lazy here
and just use the first address in the list.

For example, suppose you want to find the addresses for google.com. The code will look like
this:

#include <stdlib.h>
#include <stdio.h>
#include <netdb.h>
/* paddr: print the IP address in a standard decimal dotted format */
T.E. (Comp) Computer Network Lab

void
paddr(unsigned char *a)
{
printf("%d.%d.%d.%d\n", a[0], a[1], a[2], a[3]);
}

main(int argc, char **argv) {


struct hostent *hp;
char *host = "google.com";
int i;

hp = gethostbyname(host);
if (!hp) {
fprintf(stderr, "could not obtain address of %s\n", host);
return 0;
}
for (i=0; hp->h_addr_list[i] != 0; i++)
paddr((unsigned char*) hp->h_addr_list[i]);
exit(0);
}

Here's the code for sending a message to the address of a machine in host. The variable fd is the
socket which was created with the socket system call.

#include <sys/types.h>
#include <sys/socket.h>
#include <stdio.h> /* for fprintf */
#include <string.h> /* for memcpy */
struct hostent *hp; /* host information */
T.E. (Comp) Computer Network Lab

struct sockaddr_in servaddr; /* server address */


char *my_messsage = "this is a test message";
/* fill in the server's address and data */
memset((char*)&servaddr, 0, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(port);
/* look up the address of the server given its name */
hp = gethostbyname(host);
if (!hp) {
fprintf(stderr, "could not obtain address of %s\n", host);
return 0;
}
/* put the host's address into the server address structure */
memcpy((void *)&servaddr.sin_addr, hp->h_addr_list[0], hp->h_length);

/* send a message to the server */


if (sendto(fd, my_message, strlen(my_message), 0, (struct sockaddr *)&servaddr,
sizeof(servaddr)) < 0) {
perror("sendto failed");
return 0;
}
Step 3b. Receive messages on the server
With TCP sockets, a server would set up a socket for listening via a listen system call and then
call accept to wait for a connection. UDP is connectionless. A server can immediately listen for
messages once it has a socket. We use the recvfrom system call to wait for an incoming datagram
on a specific transport address (IP address and port number).

The recvfrom call has the following syntax:

#include <sys/socket.h>
T.E. (Comp) Computer Network Lab

int

recvfrom(int socket, void *restrict buffer, size_t length, int flags, struct sockaddr *restrict
src_addr,

socklen_t *restrict *src_len)

The first parameter, socket is a socket that we created ahead of time (and used bind. The port
number assigned to that socket via the bind call tells us on what port recvfrom will wait for data.
The incoming data will be placed into the memory at buffer and no more than length bytes will
be transferred (that's the size of your buffer). We will ignore flags here. You can look at the man
page for recvfrom for details on this. This parameter allows us to process out-of-band data, peek
at an incoming message without removing it from the queue, or block until the request is fully
satisfied. We can safely ignore these and use 0. The src_addr parameter is a pointer to
a sockaddr structure that you allocate and will be filled in by recvfrom to identify the sender of
the message. The length of this structure will be stored in src_len. If you do not care to identify
the sender, you can set both of these to zero but you will then have no way to reply to the sender.

The recvfrom call returns the number of bytes that were read into buffer

Step 4. Bidirectional communication


We now have a client sending a message to a server. What if the server wants to send a message
back to that client? There is no connection so the server cannot just write the response back.
Fortunately, the recvfrom call gave us the address of the server.

It was placed in remaddr:

recvlen = recvfrom(s, buf, BUFSIZE, 0, (struct sockaddr *)&remaddr, &addrlen);

The server can use that address in sendto and send a message back to the recipient's address.

sendto(s, buf, strlen(buf), 0, (struct sockaddr *)&remaddr, addrlen)


Step 5. Close the socket
With TCP sockets, we saw that we can use the shutdown system call to close a socket or to
terminate communication in a single direction. Since there is no concept of a connection in UDP,
there is no need to call shutdown. However, the socket still uses up a file descriptor in the kernel,
so we can free that up with the close system call just as we do with files.

close(fd);
T.E. (Comp) Computer Network Lab

Conclusion: Thus the concept of socket was studied and the machines were connected for
sharing the file.

Assignment No: 12 (Group A)


T.E. (Comp) Computer Network Lab

Aim: Installing and configure DHCP server and write a program to install the software on
remote machine.

Objective: To understand the installation & use of DHCP server.

Pre-requisite: Knowledge of IP address, use of Internet, Client- server architecture.

Theory: DHCP (Dynamic Host Configuration Protocol)

Configuration of DHCP Server on Windows 2003


DHCP (Dynamic Host Configuration Protocol) is a protocol that allows clients on a network
to request network configuration settings from a server running the DHCP server service
which, in our case, will be Windows Server 2003. Additionally the protocol allows the clients
to self-configure those network configuration settings without the intervention of an
administrator. Some of the settings that a DHCP server can provide to its clients include the IP
addresses for the DNS servers, the IP addresses for the WINS servers, the IP address for the
default gateway (usually a router) and, of course, an IP address for the client itself.
This article will discuss and walk you through the steps of installing and configuring DHCP
on a Windows Server 2003 member server, specifically focusing on setting up a scope and its
accompanying settings.

Assigning the server a static IP address


Before we install the DHCP server service on Windows Server 2003, we need to assign the
Windows server a static IP address. To do this:
1. Go to Start >Control Panel >Network Connections , right-click Local Area Connection
and choose Properties .
2. When the Local Area Connection Properties window comes up, select Internet Protocol
(TCP/IP) and click the Properties button.
3.When the Internet Protocol (TCP/IP) window comes up, enter an IP address ,subnet
mask and default gateway IP address that is compatible with your LAN.
We've configured our settings according to our network, as shown below:
T.E. (Comp) Computer Network Lab

4. Enter 192.168.0.252 for the Preferred DNS server and 192.168.1.252 for the Alternate DNS
server. The Preferred and Alternate DNS server IP addresses are optional for the functionality
of the DHCP server, but we will populate them since you typically would in a real-world
network. Usually these fields are populated with the IP addresses of your Active Directory
domain controllers.
5. After filling out those fields, click OK and OK to save and close all windows.

Install DHCP server service on Windows Server 2003


Our server now has a static IP address and we are now ready to install the DHCP server
service. To do this:
1. Go to Start >Control Panel >Add or Remove Programs .
2. When the Add or Remove Programs window launches, click Add/Remove Windows
Components in the left pane.
T.E. (Comp) Computer Network Lab

3.When the Windows Components Wizard comes up, scroll down and highlight
Networking Services and then click the Details button.

4.When the Networking Services window comes up, place a check mark next to Dynamic
Host Configuration Protocol (DHCP) and click OK and OK again.
T.E. (Comp) Computer Network Lab

Note that, during the install, Windows may generate an error claiming that it could not find a
file needed for DHCP installation. If this happens, insert your Windows Server 2003 CD into
the server's CD-ROM drive and browse to the i386 directory. The wizard should
automatically find the file and allow you to select it. After that, the wizard should resume the
installation process.

Configure DHCP on Windows Server 2003


DHCP has now been successfully installed and we are ready to configure it. We will create a
new scope and configure some of the scope's options. To begin:

1. Launch the DHCP MMC by going to Start >Administrative Tools >DHCP .


Currently, the DHCP MMC looks empty and the server node in the left pane has a red arrow
pointing down. Keep that in mind because it will be significant later on.
T.E. (Comp) Computer Network Lab

2. Right-click the server node in the left pane and choose New Scope . This will launch the
New Scope Wizard.
3.On the New Scope Wizard, click Next .
4.Specify a scope name and scope description. For the scope Name , enter “ Building A,
Floor 1 .” For the scope Description , enter “ This scope is for Floor 1 of Building A .”
Afterwards, click Next .

The scope name can be anything, but we certainly want to name it something that describes
the scope's purpose. The scope Description is not required. It is there in case we needed to
provide a broader description of the scope.
T.E. (Comp) Computer Network Lab

5. Specify an IP address range and subnet mask. For the Start IP address enter 192.168.0.1,
for the End IP address enter 192.168.0.254 . Finally, specify a subnet mask of
255.255.255.0 and click Next.
Specifying the IP address range of a scope requires some knowledge of subnetting. Each
scope in a DHCP server holds a pool of IP addresses to give out to clients, and the range of IP
addresses must be within the allowed range of the subnet (that you specify on the subnet mask
field).
For simplicity we entered a classful, class C IP address range from 192.168.0.1 to
192.168.0.254. Notice that the range encompasses the IP address of our server, the DNS
servers and the default gateway, meaning that the DHCP server could potentially assign a
client an IP address that is already in use! Do not worry -- we will take care of that later.

6.Specify IP addresses to exclude from assignment. For the Start IP address , enter
192.168.0.240 and for the End IP address enter 192.168.0.254 , click Add , and then click
Next.
T.E. (Comp) Computer Network Lab

Certain network devices, such as servers, will need statically configured IP addresses. The IP
addresses may sometimes be within the range of IP addresses defined for a scope. In those
cases, you have to exclude the IP addresses from being assigned out by DHCP.
We have the opportunity here to define those IP addresses that are to be excluded. We
specified IP addresses 192.168.0.240 to 192.168.0.254 to ensure we've included our servers
plus a few spare IP addresses for future use.
7. Specify the lease duration for the scope. Verify that Days is 8 and click Next.
The lease duration is how long clients should keep their IP addresses before having to renew
them.
T.E. (Comp) Computer Network Lab

There are a few considerations at this point. If a short lease duration is configured, clients will
be renewing their IP addresses more frequently. The result will be additional network traffic
and additional strain on the DHCP server. On the other hand if a long lease duration is
configured, IP addresses previously obtained by decommissioned clients would remain leased
and unavailable to future clients until the leases either expire or are manually deleted.
Additionally if network changes occur, such as the implementation of a new DNS server,
those clients would not receive those updates until their leases expire or the computers are
restarted.
As Microsoft states, “lease durations should typically be equal to the average time the
computer is connected to the same physical network.” You would typically leave the default
lease duration in an environment where computers are rarely moved or replaced, such as a
wired network. In an environment where computers are often moved and replaced, such as a
wireless network, you would want to specify a short duration since a new wireless client
could roam within range at any time.
8.Configure DHCP Options. Make sure “ Yes, I want to configure these settings now ” is
selected and click Next to begin configuring DHCP options.
T.E. (Comp) Computer Network Lab

DHCP options are additional settings that the DHCP server can provide to clients when it
issues them with IP addresses. These are the other settings that help clients communicate on
the network. In the New Scope Wizard we can only configure a few options but from the
DHCP MMC we have several more options.
9. Specify the router IP address. Enter 192.168.0.254 as the IP address of the subnet's router,
click Add , and then click Next .
The first option we can configure is the IP address for the subnet's router for which this scope
is providing IP addresses. Keep in mind that this IP address must be in the same network as
the IP addresses in the range that we created earlier.

10. Configure domain name and DNS servers. On the next page, enter “firewall.cx" for the
domain name. Then enter 192.168.0.252 for the IP address of a DNS server, click Add , enter
192.168.1.252 as the IP address for another DNS server, and click Add again. When finished,
click Next.
If you had a DNS infrastructure in place, you could have simply typed in the fully qualified
domain name of the DNS server and clicked Resolve .
T.E. (Comp) Computer Network Lab

The DNS servers will be used by clients primarily for name resolution, but also for other
purposes that are beyond the scope of this article. The DNS domain name will be used by
clients when registering their hostnames to the DNS zones on the DNS servers (covered in the
'Advanced DHCP Server Configuration on Windows 2003' article).

11. Configure WINS servers. On the next screen, enter 192.168.0.251 as the IP address for the
first WINS server, click Add , enter 192.168.1.251 as the IP address for the second WINS
server, click Add again, and then click Finish .
T.E. (Comp) Computer Network Lab

12. Finally, the wizard asks whether you want to activate the scope. For now, choose “ No, I
will activate this scope later ” and click Next and then Finish to conclude the New Scope
Wizard and return to the DHCP MMC.
At this point we almost have a functional DHCP server. Let us go ahead and expand the scope
node in the left pane of the DHCP MMC to see the new available nodes:
 Address Pool – Shows the IP address range the scope offers along with any IP address
exclusions.
 Address Leases – Shows all the leased IP addresses.
 Reservations – Shows the IP addresses that are reserved. Reservations are made by specifying
the MAC address that the server would “listen to” when IP address requests are received by
the server. Certain network devices, such as networked printers, are best configured with
reserved IP addresses rather than static IP addresses.
 Scope Options – Shows configured scope options. Some of the visible options now are router,
DNS, domain name and WINS options.
 Server Options – Shows configured server options. This is similar to scope options except that
these options are either inherited by all the scopes or overridden by them (covered in
'Advanced DHCP Server Configuration on Windows 2003' article).
T.E. (Comp) Computer Network Lab

Earlier, we only defined exclusions for our servers, router plus a few more spare IP addresses.
In case you need to exclude more IP addresses, you can do it at this point by following these
instructions:
13. Select and right-click Address Pool and choose New Exclusion Range.
14. When the Add Exclusion window comes up, enter the required range and then click Add.
In our example, we've excluded the addition range 192.168.0.230 - 192.168.0.232.

Notice that the server node and scope node still has a red arrow pointing down. These red
arrows pointing down mean that the server and scope are not “turned on”.
The concept of “turning on” the scope is called “activating” and the concept of “turning on”
the server for DHCP service is called “authorizing”. Security has some influence in the
concept of authorizing a DHCP server and, to authorize a DHCP server, you must be a
member of the Enterprise Admins Active Directory group.

15. Right-click the server (server001.firewall.cx) and choose Authorize , then right-click the
scope (Building A, Floor 1) and choose Activate . If the red arrows remain, refresh the MMC
by going to Action >Refresh .
T.E. (Comp) Computer Network Lab

Congratulations! At this point, you should have a working DHCP server capable of providing
IP addresses!

Configuration of DHCP Server on Linux


Configure the DHCP server by matching the following conditions:
 Subnet and netmask should be 192.168.0.0 255.255.255.0
 Gateway Should be 192.168.0.254
 DNS Sever Should be 192.168.0.254
 Domain Name should be example.com
 Range from 192.168.0.10-50
You have DHCP server, which assigns the IP, gateway and DNS server ip to Clients. There is
one DNS servers having MAC address (00:50:FC:98:8D:00 in your LAN, But it always
required fixed IP address (192.168.0.10). Configure the DHCP server to assign the fixed IP
address to DNS server.
Configure dhcpserver,in this example we will configure a dhcp server and will lease ip address to
clients.For this ,we are using three systems one linux server one linux clients and one window
clients.
 Steps for configuration of dhcp server in linux
1. dhcp rpm is required to configure dhcp server. check it if not found then install
T.E. (Comp) Computer Network Lab

#setup
Select System service
from list [*]dhcpd

2. To assign IP to dhcp server


DHCP server have a static a ip address. First configure the ip address 192.168.0.254 with
netmask of 255.255.255.0 on server.
Run setup command form root user
#setup

this will launch a new window select network configuration

now a new window will show you all available LAN card select your LAN card ( if you don't see
any LAN card here mean you don't have install driver)
T.E. (Comp) Computer Network Lab

assign IP in this box and click ok.

click on ok, quit and again quit to come back on root prompt.
3. restart the network service so new ip address can take place on LAN card
#service network restart
main configuration file of dhcp server is dhcpd.conf. This file located on /etc directory. If this file
is not present there or you have corrupted this file, then copy new file first, if ask for overwrite
press y

4. now open /etc/dhcpd.conf


T.E. (Comp) Computer Network Lab

default entry in this file look like this

makethese change in this file to configure dhcp server

remove this line # - - - default gateway


set option routers to 192.168.0.254
set option subnet-mask to 255.255.255.0
optionnis domain to example.com
option domain-name to example.com
option domain-name-servers to 192.168.0.254
range dynamic-bootp to 192.168.0.10 192.168.0.50;

After change this file should look like this


T.E. (Comp) Computer Network Lab

5. How to assign fix ip address to any host


locate this paragraph and change hardware Ethernet to client's mac address and fixed -address to
ip address which you want to provide that host

after making necessary change save file and exit


now create a blank file use to store the allocated ip address information

6. Now restart dhcpd service and on it with chkconfig commands

 Linux Client configuration


T.E. (Comp) Computer Network Lab

1. Client configuration is very easy and straightforward. All you need to do is set ip address to
dynamic in the properties of lan card. In linux
#setup
select network configuration from menu list
Select lan card and enter on ok
Select USE DHCP and enter on ok
Now click on quit
and quit to come back on root prompt

2. Now restart the network service to obtain ip from dhcp server

Conclusion: Thus the installation of DHCP Server was successfully done & understood.
T.E. (Comp) Computer Network Lab

Assignment No: 11 (Group A)

Aim: Write a program for DNS lookup. Given an IP address input, it should return URL
and viceversa.

Objective: To understand the Concept & Architecture of DNS Server.

Pre-requisite: Knowledge of IP address, use of Internet, Client- server architecture.

Theory: DNS are the Internet’s equivalent of Phone book. They maintain a directory of Domain
Names and translate them into IP address. This is necessary because although Domain names are
easy for people to remember.
When DNS was not into existence one had to download a Host File containing host names and
their corresponding IP address. But with the increase in number of Host of Internet the size of
Host file also increased. This resulted in increased traffic on downloading this file. To solve this
problem DNS came into existence.
Domain Name System helps to resolve the Host name to an address. It uses a hierarchical
naming scheme and distributed database of IP addresses and associated names.

IP Address

IP address is a unique logical address assigned to a machine over the network. An IP address
exhibits the following properties:
IP address is the unique logical address assigned to each host present on the network.
IP address is 32 bit long
IP address consists of two components:
Network component & Host component
Each of the 4 bytes are represented by a number from 0 to 255, separated by dots.

Uniform Resource Locator (URL)


Refers to a Web address which uniquely identifies a document over the internet.

URL Types
There are two types of URL:
Absolute URL
T.E. (Comp) Computer Network Lab

It is a complete address of a resource on the web. This complete address is comprised of the
Protocol used, Server name, Path name and File name.
For ex: http://www.tutorialspoint.com/internet_technolgy/index.htm
http: is the Protocol
www.tutorialspoint.com : Server Name
index.htm: File name

Relative URL

Relative URL is the partial address of a webpage. Unlike absolute URL, the protocol and Server
part are omitted from Relative URL.

Domain Name System Architecture

The Domain Name System comprises of:


Domain Names
Domain Name is a symbolic string associated with an IP address. There are several domain
names available: com, edu, net, gov.
Domain Name Space
The Domain Name Space refers a hierarchy in the internet naming structure. This hierarchy has
multiple levels, with the root at the top.
Name Server
It Contains the DNS Database .This database comprise of various names and their corresponding
IP addresses. Since it is not possible for a single server to maintain entire DNS database,
therefore the information is distributed among many DNS servers.

Types of name Servers

There are three types of Name Server:


Root Server: It is the top level server which consists of the entire DNS tree. It does not contain
the information about domains but delegates the authority to the other server.

Primary Server: It stores a file about its Zone. It has authority to create, maintain, and update
the Zone file.

Secondary Server: It transfers complete information about a zone from another server which
may be primary or secondary server. The secondary server does not have the authority to create
or update a Zone file.

Zones
Zone is the collection of nodes subdomain under the main domain. The server maintains a
database called Zone file for every Zone.
T.E. (Comp) Computer Network Lab

DNS Working:
DNS translate the domain names into IP address automatically.

The steps are as follows:


When we type www.tutorialspoint.com into the browser, it asks the local DNS server
for its IP address.
When the local DNS does not find the IP address of requested domain name. It
forwards the request to the root DNS Server and again enquires about IP address of it.
The Root DNS server replies with delegation that I do not know the IP address of
www.tutorialspoint.com but know the IP address of DNS Server.
The local DNS server then asks the Com DNS server the same question.
The Com DNS Server replies the same that I do not know the IP address of
www.tutorialspoint.com but knows the address of tutorialspoint.com.
Then the local DNS asks the tutorialspoint.com DNS server the same question.
Then tutorialspoint.com DNS server replies with IP address of
www.tutorialspoint.com
Now the Local DNS sends the IP address of www.tutorialspoint.com to the computer
that sends the request.

Conclusion: The Concept and working of DNS Server was successfully studied.

Assignment No: 5 (Group A)

Aim: Write a program to demonstrate sub netting and find the subnet masks.

Objective: To understand the Concept & Subnet & Sub netting

Pre-requisite: Basic understanding of binary and decimal numbers.


T.E. (Comp) Computer Network Lab

Theory: A subnet is a small network inside a larger network. It is a logical grouping of


connected network devices that tend to be located in close physical proximity to each other on a
local area network—a LAN.

There are plenty of times when a large network might need to have smaller networks inside of it.
A simple example is a large company network with subnets for human resources or accounting
departments.

Network designers employ subnets as a way to partition networks into logical segments for
greater ease of administration. When subnets are properly implemented, both the performance
and security of networks are improved.

A single IP address at a large business network may accept a message or file from an outside
computer, but then it must decide which of the company's hundreds or thousands of computers in
the office should receive it. Subnetting gives the network a logical tier or organization that can
identify the correct path within the company.

What Is Subnetting?

Subnetting is the process of dividing a network into two or more subnets. An IP address has
numbers that identify the network ID and the host ID. A subnet address borrows some of the bits
from the host ID of the IP address. Subnetting is largely invisible to computer users who aren't
also network administrators.

Advantages of Using Subnets

Any office or school with a large number of computers can enjoy the advantages of using
subnets.

They include:

 Network performance and speed improve.


 Network congestion is reduced.
 Data delivery is more efficient.
 An organization can take full advantage of the network's capacity.
 Network security improves.
 Administration eases.
 Troubleshooting can be limited to a subnet rather than the entire network.
 The separation between different departments in an organization is maintained.
T.E. (Comp) Computer Network Lab

There aren't many disadvantages to subnetting. The process will likely require additional routers,
switches or hubs, which is an expense. Also, you'll need an experienced network administrator to
manage the network and subnets.

 Address - The unique number ID assigned to one host or interface in a network.


 Subnet - A portion of a network that shares a particular subnet address.
 Subnet mask - A 32-bit combination used to describe which portion of an address refers to
the subnet and which part refers to the host.
 Interface - A network connection.

Understand IP Addresses
An IP address is an address used in order to uniquely identify a device on an IP network. The
address is made up of 32 binary bits, which can be divisible into a network portion and host
portion with the help of a subnet mask. The 32 binary bits are broken into four octets (1 octet = 8
bits). Each octet is converted to decimal and separated by a period (dot). For this reason, an IP
address is said to be expressed in dotted decimal format (for example, 172.16.81.100). The value
in each octet ranges from 0 to 255 decimal, or 00000000 - 11111111 binary.
Here is how binary octets convert to decimal: The right most bit, or least significant bit, of an
octet holds a value of 20. The bit just to the left of that holds a value of 2 1. This continues until
the left-most bit, or most significant bit, which holds a value of 2 7. So if all binary bits are a one,
the decimal equivalent would be 255 as shown here:
1 1 1 11111
128 64 32 16 8 4 2 1 (128+64+32+16+8+4+2+1=255)

Here is a sample octet conversion when not all of the bits are set to 1.
0 1000001
0 64 0 0 0 0 0 1 (0+64+0+0+0+0+0+1=65)

And this sample shows an IP address represented in both binary and decimal.
10. 1. 23. 19 (decimal)
00001010.00000001.00010111.00010011 (binary)

These octets are broken down to provide an addressing scheme that can accommodate large and
small networks. There are five different classes of networks, A to E. This document focuses on
classes A to C, since classes D and E are reserved and discussion of them is beyond the scope of
this document.
Given an IP address, its class can be determined from the three high-order bits (the three left-
most bits in the first octet). Figure 1 shows the significance in the three high order bits and the
T.E. (Comp) Computer Network Lab

range of addresses that fall into each class. For informational purposes, Class D and Class E
addresses are also shown.

Figure 1

In a Class A address, the first octet is the network portion, so the Class A example in Figure 1 has
a major network address of 1.0.0.0 - 127.255.255.255. Octets 2, 3, and 4 (the next 24 bits) are for
the network manager to divide into subnets and hosts as he/she sees fit. Class A addresses are
used for networks that have more than 65,536 hosts (actually, up to 16777214 hosts!).
In a Class B address, the first two octets are the network portion, so the Class B example
in Figure 1 has a major network address of 128.0.0.0 - 191.255.255.255. Octets 3 and 4 (16 bits)
are for local subnets and hosts. Class B addresses are used for networks that have between 256
and 65534 hosts.
T.E. (Comp) Computer Network Lab

In a Class C address, the first three octets are the network portion. The Class C example
in Figure 1 has a major network address of 192.0.0.0 - 223.255.255.255. Octet 4 (8 bits) is for
local subnets and hosts - perfect for networks with less than 254 hosts.

Network Masks
A network mask helps you know which portion of the address identifies the network and which
portion of the address identifies the node. Class A, B, and C networks have default masks, also
known as natural masks, as shown here:
Class A: 255.0.0.0
Class B: 255.255.0.0
Class C: 255.255.255.0

An IP address on a Class A network that has not been subnetted would have an address/mask pair
similar to: 8.20.15.1 255.0.0.0. In order to see how the mask helps you identify the network and
node parts of the address, convert the address and mask to binary numbers.
8.20.15.1 = 00001000.00010100.00001111.00000001
255.0.0.0 = 11111111.00000000.00000000.00000000

Once you have the address and the mask represented in binary, then identification of the network
and host ID is easier. Any address bits which have corresponding mask bits set to 1 represent the
network ID. Any address bits that have corresponding mask bits set to 0 represent the node ID.
8.20.15.1 = 00001000.00010100.00001111.00000001
255.0.0.0 = 11111111.00000000.00000000.00000000
-----------------------------------
net id | host id

netid = 00001000 = 8
hostid = 00010100.00001111.00000001 = 20.15.1

Understand Subnetting
Subnetting allows you to create multiple logical networks that exist within a single Class A, B, or
C network. If you do not subnet, you are only able to use one network from your Class A, B, or
C network, which is unrealistic.
Each data link on a network must have a unique network ID, with every node on that link being a
member of the same network. If you break a major network (Class A, B, or C) into smaller
subnetworks, it allows you to create a network of interconnecting subnetworks. Each data link on
T.E. (Comp) Computer Network Lab

this network would then have a unique network/subnetwork ID. Any device, or gateway, that
connects n networks/subnetworks has n distinct IP addresses, one for each network / subnetwork
that it interconnects.
In order to subnet a network, extend the natural mask with some of the bits from the host ID
portion of the address in order to create a subnetwork ID. For example, given a Class C network
of 204.17.5.0 which has a natural mask of 255.255.255.0, you can create subnets in this manner:
204.17.5.0 - 11001100.00010001.00000101.00000000
255.255.255.224 - 11111111.11111111.11111111.11100000
--------------------------|sub|----

By extending the mask to be 255.255.255.224, you have taken three bits (indicated by "sub")
from the original host portion of the address and used them to make subnets. With these three
bits, it is possible to create eight subnets. With the remaining five host ID bits, each subnet can
have up to 32 host addresses, 30 of which can actually be assigned to a device since host ids of
all zeros or all ones are not allowed (it is very important to remember this). So, with this in
mind, these subnets have been created.
204.17.5.0 255.255.255.224 host address range 1 to 30
204.17.5.32 255.255.255.224 host address range 33 to 62
204.17.5.64 255.255.255.224 host address range 65 to 94
204.17.5.96 255.255.255.224 host address range 97 to 126
204.17.5.128 255.255.255.224 host address range 129 to 158
204.17.5.160 255.255.255.224 host address range 161 to 190
204.17.5.192 255.255.255.224 host address range 193 to 222
204.17.5.224 255.255.255.224 host address range 225 to 254

Note: There are two ways to denote these masks. First, since you use three bits more than the
"natural" Class C mask, you can denote these addresses as having a 3-bit subnet mask. Or,
secondly, the mask of 255.255.255.224 can also be denoted as /27 as there are 27 bits that are set
in the mask. This second method is used with CIDR. With this method, one of these networks
can be described with the notation prefix/length. For example, 204.17.5.32/27 denotes the
network 204.17.5.32 255.255.255.224. When appropriate, the prefix/length notation is used to
denote the mask throughout the rest of this document.

The network subnetting scheme in this section allows for eight subnets, and the network might
appear as:
T.E. (Comp) Computer Network Lab

Figure 2

Notice that each of the routers in Figure 2 is attached to four subnetworks, one subnetwork is
common to both routers. Also, each router has an IP address for each subnetwork to which it is
attached. Each subnetwork could potentially support up to 30 host addresses.
This brings up an interesting point. The more host bits you use for a subnet mask, the more
subnets you have available. However, the more subnets available, the less host addresses
available per subnet. For example, a Class C network of 204.17.5.0 and a mask of
255.255.255.224 (/27) allows you to have eight subnets, each with 32 host addresses (30 of
which could be assigned to devices). If you use a mask of 255.255.255.240 (/28), the break down
is:
204.17.5.0 - 11001100.00010001.00000101.00000000
255.255.255.240 - 11111111.11111111.11111111.11110000
--------------------------|sub |---

Since you now have four bits to make subnets with, you only have four bits left for host
addresses. So in this case you can have up to 16 subnets, each of which can have up to 16 host
addresses (14 of which can be assigned to devices).
Take a look at how a Class B network might be subnetted. If you have network 172.16.0.0 ,then
you know that its natural mask is 255.255.0.0 or 172.16.0.0/16. Extending the mask to anything
beyond 255.255.0.0 means you are subnetting. You can quickly see that you have the ability to
create a lot more subnets than with the Class C network. If you use a mask of 255.255.248.0
(/21), how many subnets and hosts per subnet does this allow for?
172.16.0.0 - 10101100.00010000.00000000.00000000
255.255.248.0 - 11111111.11111111.11111000.00000000
T.E. (Comp) Computer Network Lab

-----------------| sub |-----------

You use five bits from the original host bits for subnets. This allows you to have 32 subnets (2 5).
After using the five bits for subnetting, you are left with 11 bits for host addresses. This allows
each subnet so have 2048 host addresses (211), 2046 of which could be assigned to devices.

Note: In the past, there were limitations to the use of a subnet 0 (all subnet bits are set to zero)
and all ones subnet (all subnet bits set to one). Some devices would not allow the use of these
subnets. Cisco Systems devices allow the use of these subnets when the ip subnet zerocommand
is configured.

Examples

Sample Exercise 1

Now that you have an understanding of subnetting, put this knowledge to use. In this example,
you are given two address / mask combinations, written with the prefix/length notation, which
have been assigned to two devices. Your task is to determine if these devices are on the same
subnet or different subnets. You can use the address and mask of each device in order to
determine to which subnet each address belongs.
DeviceA: 172.16.17.30/20
DeviceB: 172.16.28.15/20

Determine the Subnet for DeviceA:


172.16.17.30 - 10101100.00010000.00010001.00011110
255.255.240.0 - 11111111.11111111.11110000.00000000
-----------------| sub|------------
subnet = 10101100.00010000.00010000.00000000 = 172.16.16.0

Looking at the address bits that have a corresponding mask bit set to one, and setting all the other
address bits to zero (this is equivalent to performing a logical "AND" between the mask and
address), shows you to which subnet this address belongs. In this case, DeviceA belongs to
subnet 172.16.16.0.
Determine the Subnet for DeviceB:
172.16.28.15 - 10101100.00010000.00011100.00001111
255.255.240.0 - 11111111.11111111.11110000.00000000
-----------------| sub|------------
subnet = 10101100.00010000.00010000.00000000 = 172.16.16.0
T.E. (Comp) Computer Network Lab

From these determinations, DeviceA and DeviceB have addresses that are part of the same
subnet.

Conclusion: The concept of Subnet & Subnetting was understood along with how to find the
subnet mask.
T.E. (Comp) Computer Network Lab

Assignment No: 7(Group A) & Assignment No: 3 (Group B)

Aim: Write a program using TCP socket for wired network for following a. Say Hello to
Each other ( For all students) b. File transfer ( For all students) c. Calculator (Arithmetic)
(50% students) d. Calculator (Trigonometry) (50% students) Demonstrate the packets
captured traces using Wireshark Packet Analyzer Tool for peer to peer mode.

Write a program using TCP sockets for wired network to implement

a. Peer to Peer Chat b. Multiuser Chat Demonstrate the packets captured traces using
Wireshark Packet Analyzer Tool for peer to peer mode.

Objective: To study the concept of socket and its implementation.

Pre-requisite: Knowledge of protocols like TCP and UDP, basics of sockets and its use.

Theory: Sockets are the endpoints of a bidirectional communications channel. Sockets may
communicate within a process, between processes on the same machine, or between processes on
different continents. Sockets are bidirectional, meaning that either side of the connection is
capable of both sending and receiving data. Sometimes the one application that initiates
communication is termed the client and the other application the server

Sockets may be implemented over a number of different channel types: UNIX domain sockets,
TCP, UDP, and so on. The socket library provides specific classes for handling the common
transports as well as a generic interface for handling the rest.

Sockets have their own vocabulary:

Term Description
The family of protocols that will be used as the transport mechanism. These
domain values are constants such as AF_INET, PF_INET, PF_UNIX, PF_X25, and so
on.
The type of communications between the two endpoints, typically
type SOCK_STREAM for connection-oriented protocols and SOCK_DGRAM for
connectionless protocols.
Typically zero, this may be used to identify a variant of a protocol within a
protocol
domain and type.
hostname The identifier of a network interface:
 A string, which can be a host name, a dotted-quad address, or an IPV6
address in colon (and possibly dot) notation
T.E. (Comp) Computer Network Lab

 A string "<broadcast>", which specifies an INADDR_BROADCAST


address.
 A zero-length string, which specifies INADDR_ANY, or

 An Integer, interpreted as a binary address in host byte order.


Each server listens for clients calling on one or more ports. A port may be a
port Fixnum port number, a string containing a port number, or the name of a
service.

The socket Module:

To create a socket, you must use the socket.socket() function available in socket module, which
has the general syntax:

s = socket.socket (socket_family, socket_type, protocol=0)

Here is the description of the parameters:

 socket_family: This is either AF_UNIX or AF_INET, as explained earlier.


 socket_type: This is either SOCK_STREAM or SOCK_DGRAM.
 protocol: This is usually left out, defaulting to 0.

Once you have socket object, then you can use required functions to create your client or server
program. Following is the list of functions required:

Server Socket Methods:

Method Description
s.bind() This method binds address (hostname, port number pair) to socket.
s.listen() This method sets up and start TCP listener.
This passively accept TCP client connection, waiting until connection arrives
s.accept()
(blocking).

Client Socket Methods:

Method Description
s.connect() This method actively initiates TCP server connection.

General Socket Methods:


T.E. (Comp) Computer Network Lab

Method Description

s.recv() This method receives TCP message

s.send() This method transmits TCP message

s.recvfrom() This method receives UDP message

s.sendto() This method transmits UDP message

s.close() This method closes socket

socket.gethostname() Returns the hostname.

A Simple Server:

To write Internet servers, we use the socket function available in socket module to create a
socket object. A socket object is then used to call other functions to setup a socket server.

Now call bind(hostname, port function to specify a port for your service on the given host.

Next, call the accept method of the returned object. This method waits until a client connects to
the port you specified, and then returns a connection object that represents the connection to that
client.

#!/usr/bin/python # This is server.py file

import socket # Import socket module

s = socket.socket() # Create a socket object


host = socket.gethostname() # Get local machine name
port = 12345 # Reserve a port for your service.
s.bind((host, port)) # Bind to the port

s.listen(5) # Now wait for client connection.


while True:
c, addr = s.accept() # Establish connection with client.
print 'Got connection from', addr
c.send('Thank you for connecting')
c.close() # Close the connection

A Simple Client:
T.E. (Comp) Computer Network Lab

Now we will write a very simple client program which will open a connection to a given port
12345 and given host. This is very simple to create a socket client using Python's socket module
function.

The socket.connect(hosname, port ) opens a TCP connection to hostname on the port. Once
you have a socket open, you can read from it like any IO object. When done, remember to close
it, as you would close a file.

The following code is a very simple client that connects to a given host and port, reads any
available data from the socket, and then exits:

#!/usr/bin/python # This is client.py file

import socket # Import socket module

s = socket.socket() # Create a socket object


host = socket.gethostname() # Get local machine name
port = 12345 # Reserve a port for your service.

s.connect((host, port))
print s.recv(1024)
s.close # Close the socket when done

Now run this server.py in background and then run above client.py to see the result.

# Following would start a server in background. $ python server.py &

# Once server is started run client as follows: $ python client.py

This would produce following result: Got connection from ('127.0.0.1', 48437) Thank you for
connecting.
T.E. (Comp) Computer Network Lab

Conclusion: Thus the concept of socket was studied and the machines were connected for
sharing the file.
T.E. (Comp) Computer Network Lab

Assignment No: 4 (Group A)

Aim: Write a program to simulate Go back N and Selective Repeat Modes of Sliding
Window Protocol in peer to peer mode and demonstrate the packets captured traces using
Wire shark Packet Analyzer Tool for peer to peer mode.

Objective: To Understand and apply the concept of Go back N & Selective Repeat Modes of
Sliding Window protocol.

Pre-requisite: Knowledge of OSI Model, DLL & its Function.

Theory: Go Back n is a connection oriented protocol in which the transmitter has a window of
sequence numbers that may be transmitted without acknowledgment. The receiver will only
accept the next sequence number it is expecting - other sequence numbers are silently ignored.

The protocol simulation shows a time-sequence diagram with users A and B, protocol entities A
and B that support them, and a communications medium that carries messages. Users request
data transmissions with DatReq(DATAn), and receive data transmissions as DatInd(DATAn).
Data messages are simply numbered DATA0, DATA1, etc. without explicit content. The
transmitting protocol sends the protocol message DT(n) that gives only the sequence number, not
the data. Once sequence numbers reach a maximum number (like 7), they wrap back round to 0.
An acknowledgement AK(n) means that the DT message numbered n is the next one expected
(i.e. all messages up to but not including this number have been received). Since sequence
numbers wrap round, an acknowledgement with sequence number 1 refers to messages 0, 1, 7, 6,
etc. Note that if a DT message is received again due to re-transmission, it is acknowledged but
discarded.

The protocol has a maximum number of messages that can be sent without acknowledgement. If
this window becomes full, the protocol is blocked until an acknowledgement is received for the
earliest outstanding message. At this point the transmitter is clear to send more messages.

The receiver delivers the protocol messages DT(n) to the user in order. Any received out of order
are ignored.

Advantages

 The Sender can send many frames at a time.

 Timer can be set for a group of frames

 Efficiency is more
T.E. (Comp) Computer Network Lab

Disadvantages

 Buffer Requirement

 Transmitter needs to store the last N Packets

 Scheme is inefficient when the delay is large & the data transmission rate is high

 Unnecessary retransmission of many error free packets

Selective Repeat Protocol

When a data packet is transmitted, its corresponding timer will start and when an
acknowledgement is received then the timer will be destroyed. On the other hand, if an
acknowledgement packet is not received, then the timer expires after certain time period and then
the packet will be resend. The receiver stores out of order packets as well, unlike GBN protocol,
but it will not deliver those packets to upper layer till the received packets are in order and thus a
delay will occur. Therefore, we can say that in GBN protocol, there is no concept of storing at
receiver end, but in Selective Repeat protocol, this concept exists.
In SR protocol, the packets in the consecutive order are delivered to the upper layer and if the
packets are not consecutive, then the receiver will wait, order the packets and then will send it to
the upper layer. After this, the window will slide and move to other not received packets.

Advantage of Selective Repeat Protocol Over Go Back N Protocol

Following are some of the advantages of Selective Repeat protocol over Go Back N
protocol:
 SR protocols avoids unnecessary retransmission of packets.
 When receiver gets an out of order packet it is acknowledged, but buffered by the
receiver. When the receiver gets all the packets, it orders them and then sends to upper
layer.
 The receiver re-acknowledges already received packets with certain sequence numbers
below the current window case, if the receiver does not do so, then the sender’s window
would not move forward.

Conclusion: The concept of Go back N and Selective Repeat Modes of Sliding Window
Protocol was understood & implemented.

You might also like