NP Lab Manual
NP Lab Manual
NP Lab Manual
LABORATORY MANUAL
NP LAB
1
INDEX
1 Syllabus 3
5 Experiments 7-59
6 Viva Questions 60
2
List of Lab Experiments
Experiment No:-1 Study of different type of NETWORK TOPOLOGIES
Experiment No:-3 Write a programs in C: hello client (The server listens for, and accepts,
a single TCP connection; it reads all the data it can from that
connection, and prints it to the screen; then it closes the connection)
Experiment No:-4 Write a programs in C: hello server
(The client connects to the server, sends the string “Hello, world!”,
then closes the connection )
Experiment No:-5 Write a programs in C for TCP and UDP chat server
Experiment No:-6 Write a programs in C: hello client (The server listens for, and accepts,
a single UDP connection; it reads all the data it can from that
connection, and prints it to the screen; then it closes the connection)
Experiment No:-7 Write a programs in C: hello server
(The client connects to the server, sends the string “Hello, world!”,
then closes the connection )
Experiment No:-8 Write an Echo server using TCP to estimate the round trip time
From client to the server. The server should be such that it can accept
multiple connections at any given time , with multiplexed I/O
operations
Experiment No:-9 Simulate Bellman-Ford Routing algorithm in NS2
LAN installation and configuration
3
4
Introduction to Socket Programming
Outline:
1.) Introduction
2.) The Client / Server Model
3.) The Socket Interface and Features of a TCP connection
4.) Byte Ordering
5.) Address Structures, Ports, and Address conversion functions
6.) Outline of a TCP Server
7.) Outline of a TCP Client
8.) Client-Server communication outline
9.) Summary of Socket Functions
1.) Introduction
In this Lab you will be introduced to socket programming at a very elementary level. Specifically, we
will focus on TCP socket connections which are a fundamental part of socket programming since they
provide a connection oriented service with both flow and congestion control. What this means to the
programmer is that a TCP connection provides a reliable connection over which data can be transferred
with little effort required on the programmers part; TCP takes care of the reliability, flow control,
congestion control for you. First the basic concepts will be discussed, then we will learn how to
implement a simple TCP client and server.
It is possible for two network applications to begin simultaneously, but it is impractical to require it.
Therefore, it makes sense to design communicating network applications to perform complementary
network operations in sequence, rather than simultaneously. The server executes first and waits to
receive; the client executes second and sends the first network packet to the server. After initial
contact, either the client or the server is capable of sending and receiving data.
5
3.) The Socket Interface and Features of a TCP connection
Wrapping (Encapsulation
)
Un Wrapping
6
The Internet does not strictly obey the OSI model but rather merges several of the protocols layers together.
Where is the socket programming interface in relation to the protocol stack?
Connection Oriented
Reliability
1. Handles lost packets
2. Handles packet sequencing
3. Handles duplicated packets
Full Duplex
Flow Control
Congestion Control
TCP UDP
Reliable, guaranteed Unreliable. Instead, prompt delivery of
Packets.
Connection-oriented Connectionless
Used in applications that require safety guarantee. (ex. Used in media applications. (ex. video or
File applications.) Voice transmissions.)
Flow control, sequencing of packets, error-control. No flow or sequence control, user must handle
These manually.
Uses byte stream as unit of transfer. Uses datagram’s as unit of transfer.
(stream sockets) (datagram sockets)
Allows to send multiple packets with a single ACK.
Allows two-way data exchange, once the connection is Allows data to be transferred in one direction
Established. (full-duplex) At once. (half-duplex)
e.g. Telnet uses stream sockets. e.g. TFTP (trivial file transfer protocol) uses
(everything you write on one side appears exact in same Datagram sockets.
order on the other side)
7
Sockets versus File I/O
Working with sockets is very similar to working with files. The socket() and accept() functions both
return handles (file descriptor) and reads and writes to the sockets requires the use of these handles (file
descriptors). In Linux, sockets and file descriptors also share the same file descriptor table. That is, if you
open a file and it returns a file descriptor with value say 8, and then immediately open a socket, you will
be given a file descriptor with value 9 to reference that socket. Even though sockets and files share the
same file descriptor table, they are still very different. Sockets have addresses associated with them
whereas files do not, notice that this distinguishes sockets form pipes, since pipes do not have addresses
with which they associate. You cannot randomly access a socket like you can a file with lseek(). Sockets
must be in the correct state to perform input or output.
Port numbers and IP Addresses (both discussed next) are represented by multi-byte data types which are
placed in packets for the purpose of routing and multiplexing. Port numbers are two bytes (16 bits) and
IP4 addresses are 4 bytes (32 bits), and a problem arises when transferring multi-byte data types between
different architectures. Say Host A uses“big-endian” architecture and sends a packet across the network
to Host B which uses a “little-endian” architecture. If Host B looks at the address to see if the packet is
for him/her (choose a gender!), it will interpret the bytes in the opposite order and will wrongly conclude
that it is not his/her packet. The Internet uses big-endian and we call it the network-byte-order, and it is
really not important to know which method it uses since we have the following functions to convert host-
byte-ordered values into network-byte-ordered values and vice versa:
8
To convert IP4 addresses (32 bits):
Host -> Network
Unit32_t host (uint32_t host port number)
IP4 addresses are 32 bits long. They are expressed commonly in what is known as dotted decimal
notation. Each of the four bytes which makes up the 32 address are expressed as an integer value
(0 – 255) and separated by a dot. For example, 138.23.44.2 is an example of an IP4 address in dotted
decimal notation. There are conversion functions which convert a 32 bit address into a dotted decimal
string and vice versa which will be discussed later.
Often times though the IP address is represented by a domain name, for example, hill.ucr.edu. Several
functions described later will allow you to convert from one form to another (Magic provided by DNS!).
The importance of IP addresses follows from the fact that each host on the Internet has a unique IP
address. Thus, although the Internet is made up of many networks of networks with many different types
of architectures and transport mediums, it is the IP address which provides a cohesive structure so that at
least theoretically, (there are routing issues involved as well), any two hosts on the Internet can
communicate with each other.
Ports:
Sockets are UNIQUELY identified by Internet address, end-to-end protocol, and port number.
That is why when a socket is first created it is vital to match it with a valid IP address and a port number.
In our labs we will basically be working with TCP sockets.
Ports are software objects to multiplex data between different applications. When a host receives a
packet, it travels up the protocol stack and finally reaches the application layer. Now consider a user
running an ftp client, a telnet client, and a web browser concurrently. To which application should the
packet be delivered? Well part of the packet contains a value holding a port number, and it is this number
which determines to which application the packet should be delivered.
So when a client first tries to contact a server, which port number should the client specify? For
many common services, standard port numbers are defined.
9
Ports 0 – 1023, are reserved and servers or clients that you create will not be able to bind to these ports
unless you have root privilege.
Ports 1024 – 65535 are available for use by your programs, but beware other network applications maybe
running and using these port numbers as well so do not make assumptions about the availability of
specific port numbers. Make sure you read Stevens for more details about the available range of port
numbers!
Address Structures:
Socket functions like connect(), accept(), and bind() require the use of specifically defined address
structures to hold IP address information, port number, and protocol type. This can be one of the more
confusing aspects of socket programming so it is necessary to clearly understand how to use the socket
address structures. The difficulty is that you can use sockets to program network applications using
different protocols. For example, we can use IP4, IP6, Unix local, etc. Here is the problem: Each different
protocol uses a different address structure to hold its addressing information, yet they all use the same
functions connect(), accept(), bind() etc. So how do we pass these different structures to a given socket
function that requires an address structure? Well it may not be the way you would think it should be done
and this is because sockets where developed a long time ago before things like a void pointer where
features in C. So this is how it is done:
This is the address structure which must be passed to all of the socket functions requiring an address
structure. This means that you must type cast your specific protocol dependent address structure to the
generic address structure when passing it to these socket functions.
Protocol specific address structures usually start with stockade_ and end with a suffix depending on that
protocol. For example:
10
Struct sockaddr_in (IP4, think of in as
internet) Struct sockaddr_in6 (IP6)
Struct sockaddr_un (UNIX local)
Struct sockaddr_dl (Data link)
//Fill in the address information into my Address Struct here, (will be explained in detail
shortly) Connect (socket file descriptor, (struct stockade *) &my Address Struct, size of (my
Address Struct));
struct sockaddr_in{
sa_family_t sin family /*Address/Protocol Family*/ (we’ll use PF_INET)
unit16_t sin port /* 16-bit Port number --Network Byte Ordered--
*/
struct invade sin_addr /*A struct for the 32 bit IP Address */
unsigned char sin zero[8] /*Just ignore this it is just padding*/
};
Struct in_addr {
unit32_t s_addr /*32 bit IP Address --Network Byte Ordered-- */
};
For the Subfamily variable sin family always use the constant: PF_INET or AF_INET
***Always initialize address structures with zero () or memo set () before filling them in ***
***Make sure you use the byte ordering functions when ne Cesar for the port and IP
address variables otherwise there will be strange things a happening to your packets***
To convert a string dotted decimal IP4 address to a NETWORK BYTE ORDERED 32 bit value use the
functions:
• inet_addr()
• initiation()
To convert a 32 bit NETWORK BYTE ORDERED to a IP4 dotted decimal string use:
• inet_ntoa()
11
6.) Outline of a TCP Server:
Creating a socket is in some ways similar to opening a file. This function creates a file descriptor
and returns it from the function call. You later use this file descriptor for reading, writing and using with
other socket functions
Parameters:
Family: AF_INET or PF_INET (These are the IP4 family)
Type: SOCK_STREAM (for TCP) or SOCK_DGRAM (for UDP)
Protocol: IPPROTO_TCP (for TCP) or IPPROTO_UDP (for UDP) or use 0
int bind(int socket_file_descriptor, const struct stockade * Local Address, socklen_t Address Length);
We need to associate an IP address and port number to our application. A client that wants to connect to
our server needs both of these details in order to connect to our server. Notice the difference between this
function and the connect () function of the client. The connect function specifies a remote address that the
client wants to connect to, while here, the server is specifying to the bind function a local IP address of
12
one of its Network Interfaces and a local port number.
The parameter socket_file_descriptor is the socket file descriptor returned by a call to socket() function.
The return value of bind () is 0 for success and –1 for failure.
**Again make sure that you cast the structure as a generic address structure in this function **
You also do not need to find information about the IP addresses associated with the host you are working
on. You can specify: INNADDR_ANY to the address structure and the bind function will use on of the
available (there may be more than one) IP addresses. This ensures that connections to a specified port will
be directed to this socket, regardless of which Internet address they are sent to. This is useful if host has
multiple IP addresses, then it enables the user to specify which IP address will be b_nded to which port
number.
Binding is like waiting by a specific phone in your house, and Listening is waiting for it to
The backlog parameter can be read in Stevens’ book. It is important in determining how many
connections the server will connect with. Typical values for backlog are 5 – 10.
The parameter socket_file_descriptor is the socket file descriptor returned by a call to socket() function.
The return value of listen () is 0 for success and –1 for failure.
int accept (int socket_file_descriptor, struct stockade * Client Address, socklen_t *add Len);
Accept () returns a new socket file descriptor for the purpose of reading and writing to the client. The
original file descriptor is used usually used for listening for new incoming connections. Servers will be
discussed in much more detail in a later lab.
It desuetude the next connection request on the queue for this socket of the server. If queue is empty,
this function blocks until a connection request arrives. (Read the reference book TCP/IP Implementation
in C for more details.)
**Again, make sure you type cast to the generic socket address structure**
Note that the last parameter is a pointer. You are not specifying the length, the kernel is and returning the
value to your application, the same with the Client Address. After a connection with a client is established
the address of the client must be made available to your server, otherwise how could you communicate
back with the client? Therefore, the accept () function call fills in the address structure and length of the
address structure for your use. Then accept () returns a new file descriptor, and it is this file descriptor
with which you will read and write to the client.
13
7.) Outline of a TCP Client
Step 2: Binding a socket: This is unnecessary for a client, what bind does is (and will be discussed
in detail in the server section) is associate a port number to the application. If you skip this step with
a TCP client, a temporary port number is automatically assigned, so it is just better to skip this step
with the client.
Once you have created a socket and have filled in the address structure of the server you want to
connect to, the next thing to do is to connect to that server. This is done with the connect function
listed above.
14
**This is one of the socket functions which requires an address structure so remember to type cast
it to the generic socket structure when passing it to the second argument **
Connect performs the three-way handshake with the server and returns when the connection is
established or an error occurs.
Once the connection is established you can begin reading and writing to the socket.
!!!! When a server receives (accepts) the client’s connection request => it forks a copy of itself and
lets the child handle the client. (make sure you remember these Operating Systems concepts)
15
Therefore on the server machine, listening socket is distinct from the connected socket.
Read/write: These are the same functions you use with files but you can use them with sockets as
well. However, it is extremely important you understand how they work so please read Stevens
carefully to get a full understanding.
Writing to a socket:
int write(int file descriptor, const void * buff, size message length);
The return value is the number of bytes written, and –1 for failure. The number of bytes written may
be less than the message length. What this function does is transfer the data from you application to a
buffer in the kernel on your machine, it does not directly transmit the data over the network. This is
extremely important to understand otherwise you will end up with many headaches trying to debug
your programs.
TCP is in complete control of sending the data and this is implemented inside the kernel. Due to
network congestion or errors, TCP may not decide to send your data right away, even when the
function call returns. TCP has an elaborate sliding window mechanism which you will learn about in
class to control the rate at which data is sent. Read pages 48-49, 77-78 in Stevens very carefully.
The value returned is the number of bytes read which may not be buffer length! It returns –1 for
failure. As with write(), read() only transfers data from a buffer in the kernel to your application , you
are not directly reading the byte stream from the remote host, but rather TCP is in control and buffers
the data for your application.
After you are finished reading and writing to your socket you most call the close system call on
the socket file descriptor just as you do on a normal file descriptor otherwise you waste system
resources.
The shut down () function: You can also shutdown a socket in a partial way which is often used when
forking off processes. You can shutdown the socket so that it won’t send anymore or you could also
shutdown the socket so that it won’t read anymore as well. This function is not so important now but
will be discussed in detail later. You can look at the man pages for a full description of this function.
16
12.) Summary of Functions
For specific and up-to-date information about each of the following functions, please use the online
man pages and Steven’s Unix Network Programming Vol. I.
Client:
• connect()
• bind()
Server:
• accept()
• bind()
• listen()
Data Transfer:
• send()
• recv()
• write()
• read()
Miscellaneous:
• zeros()
• mindset()
Host Information:
• unnamed()
• get host by name()
• get host by addr()
Address Conversion:
• initiation()
• inet_addr()
• inet_ntoa()
17
Experiment No.: 1
Aim. Study of different types of network topologies.
BUS Topology
Bus topology is a network type in which every computer and network device is connected to single
cable. When it has exactly two endpoints, then it is called Linear Bus topology.
1. It is cost effective.
2. Cable required is least compared to other network topology.
3. Used in small networks.
4. It is easy to understand.
5. Easy to expand joining two cables together.
18
RING Topology
It is called ring topology because it forms a ring as each computer is connected to another
computer, with the last one connected to the first. Exactly two neighbors for each device.
1. A number of repeaters are used for Ring topology with large number of nodes, because if
someone wants to send some data to the last node in the ring topology with 100 nodes,
then the data will have to pass through 99 nodes to reach the 100th node. Hence to prevent
data loss repeaters are used in the network.
2. The transmission is unidirectional, but it can be made bidirectional by having 2
connections between each Network Node, it is called Dual Ring Topology.
3. In Dual Ring Topology, two ring networks are formed, and data flow is in opposite direction
in them. Also, if one ring fails, the second ring can act as a backup, to keep the network up.
4. Data is transferred in a sequential manner that is bit by bit. Data transmitted, has to
pass through each node of the network, till the destination node.
1. Transmitting network is not affected by high traffic or by adding more nodes, as only
the nodes having tokens can transmit data.
2. Cheap to install and expand
19
Star Topology
• All computers/devices connect to a central device called hub or switch.
• Each device requires a single cable
• point-to-point connection between the device and hub.
• Most widely implemented
• Hub is the single point of failure
20
Disadvantages of Star topology
o A Central point of failure: If the central hub or switch goes down, then all the
connected nodes will not be able to communicate with each other.
o Cable: Sometimes cable routing becomes difficult when a significant amount of routing
is required.
Tree topology
o Tree topology combines the characteristics of bus topology and star topology.
o A tree topology is a type of structure in which all the computers are connected with each
other in hierarchical fashion.
o The top-most node in tree topology is known as a root node, and all other nodes are
the descendants of the root node.
o There is only one path exists between two nodes for the data transmission. Thus, it forms
a parent-child hierarchy.
21
Disadvantages of Tree topology
o Difficult troubleshooting: If any fault occurs in the node, then it becomes difficult to
troubleshoot the problem.
o High cost: Devices required for broadband transmission are very costly.
o Failure: A tree topology mainly relies on main bus cable and failure in main bus cable
will damage the overall network.
o Reconfiguration difficult: If new devices are added, then it becomes difficult to reconfigure.
Mesh topology
22
o Full Mesh Topology: In a full mesh topology, each computer is connected to all the
computers available in the network.
o Partial Mesh Topology: In a partial mesh topology, not all but certain computers
are connected to those computers with which they communicate frequently.
Reliable: The mesh topology networks are very reliable as if any link breakdown will not affect the
communication between connected computers.
Easier Reconfiguration: Adding new devices would not disrupt the communication between other
devices.
o Cost: A mesh topology contains a large number of connected devices such as a router
and more transmission media than other topologies.
o Management: Mesh topology networks are very large and very difficult to maintain and
manage. If the network is not monitored carefully, then the communication link failure
goes undetected.
o Efficiency: In this topology, redundant connections are high that reduces the efficiency of
the network.
23
Hybrid Topology
o Reliable: If a fault occurs in any part of the network will not affect the functioning of the
rest of the network.
o Scalable: Size of the network can be easily expanded by adding new devices
without affecting the functionality of the existing network.
o Flexible: This topology is very flexible as it can be designed according to the requirements
of the organization.
o Effective: Hybrid topology is very effective as it can be designed in such a way that
the strength of the network is maximized and weakness of the network is minimized.
o Complex design: The major drawback of the Hybrid topology is the design of the
Hybrid network. It is very difficult to design the architecture of the Hybrid network.
o Costly Hub: The Hubs used in the Hybrid topology are very expensive as these hubs are
different from usual Hubs used in other topologies.
o Costly infrastructure: The infrastructure cost is very high as a hybrid network requires a
lot of cabling, network devices, etc.
24
Experiment No.: 2
Aim: Study of LAN, MAN, WAN and connecting devices
There are various types of computer networks available. We can categorize them according to their
size as well as their purpose. The size of a network should be expressed by the geographic area and
number of computers, which are a part of their networks. It includes devices housed in a single room
to millions of devices spread across the world.
PAN
LAN
MAN
WAN
PAN is a computer network formed around a person. It generally consists of a computer, mobile,
or personal digital assistant. PAN can be used for establishing communication among these
personal devices for connecting to a digital network and the internet
Characteristics of PAN
Advantages of PAN
25
Disadvantages of PAN
It may establish a bad connection to other networks at the same radio bands.
Distance limits.
A Local Area Network (LAN) is a group of computer and peripheral devices which are connected in
a limited area such as school, laboratory, home, and office building. It is a widely useful network for
sharing resources like files, printers, games, and other application. The simplest type of LAN network
is to connect computers and a printer in someone's home or office. In general, LAN will be used as
one type of transmission medium.
It is a network which consists of less than 5000 interconnected devices across several buildings.
Characteristics of LAN
Advantages of LAN
Computer resources like hard-disks, DVD-ROM, and printers can share local area
networks. This significantly reduces the cost of hardware purchases.
You can use the same software over the network instead of purchasing the licensed
software for each client in the network.
Data of all network users can be stored on a single hard disk of the server computer.
You can easily transfer data and messages over networked computers.
26
It will be easy to manage data at only one place, which makes data more secure.
Local Area Network offers the facility to share a single internet connection among all
the LAN users.
Disadvantages of LAN
Here are the important cons/ drawbacks of LAN:
LAN will indeed save cost because of shared computer resources, but the initial cost of
installing Local Area Networks is quite high.
The LAN admin can check personal data files of every LAN user, so it does not offer good
privacy.
Unauthorized users can access critical data of an organization in case LAN admin is not
able to secure centralized data repository.
Local Area Network requires a constant LAN administration as there are issues related to
software setup and hardware failures
WAN (Wide Area Network) is another important computer network that which is spread across a
large geographical area. WAN network system could be a connection of a LAN which connects with
other LAN's using telephone lines and radio waves. It is mostly limited to an enterprise or an
organization.
Characteristics of LAN:
The software files will be shared among all the users; therefore, all can access to the
latest files.
Any organization can form its global integrated network using WAN.
27
Advantages of WAN
WAN helps you to cover a larger geographical area. Therefore business offices situated
at longer distances can easily communicate.
Contains devices like mobile phones, laptop, tablet, computers, gaming consoles, etc.
WLAN connections work using radio transmitters and receivers built into client devices.
Disadvantage of WAN
A Metropolitan Area Network or MAN is consisting of a computer network across an entire city,
college campus, or a small region. This type of network is large than a LAN, which is mostly limited
to a single building or site. Depending upon the type of configuration, this type of network allows you
to cover an area from several miles to tens of miles.
Characteristics of MAN
Here are important characteristics of the MAN network:
28
Advantages of MAN
It offers fast communication using high-speed carriers, like fiber optic cables.
It provides excellent support for an extensive size network and greater access to WANs.
The dual bus in MAN network provides support to transmit data in both directions
concurrently.
A MAN network mostly includes some areas of a city or an entire city.
Disadvantages of MAN
You need more cable to establish MAN connection from one place to another.
In MAN network it is tough to make the system secure from hackers
1) WLAN
WLAN (Wireless Local Area Network) helps you to link single or multiple devices using wireless
communication within a limited area like home, school, or office building. It gives users an ability
to move around within a local coverage area which may be connected to the network. Today most
modern day's WLAN systems are based on IEEE 802.11 standards.
A Storage Area Network is a type of network which allows consolidated, block-level data storage. It
is mainly used to make storage devices, like disk arrays, optical jukeboxes, and tape libraries.
29
3) System-Area Network
System Area Network is used for a local network. It offers high-speed connection in server-to-server
and processor-to-processor applications. The computers connected on a SAN network operate as a
single system at quite high speed.
POLAN is a networking technology which helps you to integrate into structured cabling. It allows
you to resolve the issues of supporting Ethernet protocols and network apps.
POLAN allows you to use optical splitter which helps you to separate an optical signal from a single-
mode optical fiber. It converts this single signal into multiple signals.
This type of network helps computer owners to interconnect with multiple computers. This network
allows sharing files, programs, printers, and other peripherals.
It is a free or paid service that keeps your web browsing secure and private over public WiFi hotspots.
30
Summary:
Type of computer networks can categorize according to their size as well as their purpose
PAN is a computer network which generally consists of a computer, mobile, or
personal digital assistant
LAN ( local area network) is a group of computer and peripheral devices which are
connected in a limited area
WAN (Wide Area Network) is another important computer network that which is
spread across a large geographical area
A metropolitan area network or MAN is consisting of a computer network across an
entire city, college campus, or a small region
WLAN is a wireless local area network that helps you to link single or multiple devices
using. It uses wireless communication within a limited area like home, school, or office
building.
SAN is a storage area network is a type of network which allows consolidated, block-level
data storage
System area network offers high-speed connection in server-to-server applications, storage
area networks, and processor-to-processor applications
POLAN is a networking technology which helps you to integrate into structured cabling
Home network (HAN) is a always built using two or more interconnected computers to form
a local area network (LAN) within the home
Enterprise private network (EPN) networks are build and owned by businesses that want
to securely connect various locations
Campus area network (CAN) is made up of an interconnection of LANs in a
specific geographical area
A VPN is a private network which uses a public network to connect remote sites or
users together
31
Experiment No.: 3
Aim: Write a programs in C: hello_client (The server listens for, and accepts, a single TCP
connection; it reads all the data it can from that connection, and prints it to the screen; then it closes
the connection)
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#define MAX 80
#define PORT 8080
#define SA struct sockaddr
void func(int sockfd)
{
char buff[MAX];
int n;
for (;;) {
bzero(buff, sizeof(buff));
printf("Enter the string : ");
n = 0;
while ((buff[n++] = getchar()) != '\n')
;
write(sockfd, buff, sizeof(buff));
bzero(buff, sizeof(buff));
read(sockfd, buff, sizeof(buff));
printf("From Server : %s", buff);
if ((strncmp(buff, "exit", 4)) == 0) {
printf("Client Exit...\n");
break;
}
}
}
int main()
{
int sockfd, connfd;
struct sockaddr_in servaddr, cli;
32
if (sockfd == -1) {
printf("socket creation failed...\n");
exit(0);
}
else
printf("Socket successfully created..\n");
bzero(&servaddr, sizeof(servaddr));
Compilation –
Server side:
gcc server.c -o server
./server
Client side:
gcc client.c -o client
./client
Output –
Server side:
Socket successfully created..
Socket successfully binded..
33
Server listening..
server acccept the client...
From client: hi
To client : hello
From client: exit
To client : exit
Server Exit...
Client side:
Socket successfully created..
connected to the server..
Enter the string : hi
From Server : hello
Enter the string : exit
From Server : exit
Client Exit...
34
Experiment No.: 4
//server
#include <stdio.h>
#include <netdb.h>
#include <netinet/in.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/types.h>
#define MAX 80
#define PORT 8080
#define SA struct sockaddr
35
}
}
// Driver function
int main()
{
int sockfd, connfd, len;
struct sockaddr_in servaddr, cli;
36
}
else
printf("server acccept the client...\n");
Compilation –
Server side:
gcc server.c -o server
./server
Client side:
gcc client.c -o client
./client
Output –
Server side:
Socket successfully created..
Socket successfully binded..
Server listening..
server acccept the client...
From client: hi
To client : hello
From client: exit
To client : exit
Server Exit...
Client side:
Socket successfully created..
connected to the server..
37
Enter the string : hi
From Server : hello
Enter the string : exit
From Server : exit
Client Exit...
38
Experiment No.: 5
Aim: Write a program to implement TCP Chat Server and UDP chat Server.
// Program for
chatappserver.c
#include<sys/socket.h>
#include<sys/types.h>
#include<stdio.h>
#include<arpa/inet.h>
#include<netinet/in.h>
#include<string.h>
#include<unistd.h>
#define SER_PORT
int a,sersock,newsock,n;
char str[25],str2[25];
socklen_t csize=sizeof(cliinfo);
seraddr.sin_family=AF_INET;
seraddr.sin_port=htons(SER_PORT);
seraddr.sin_addr.s_addr=htonl(INADDR_ANY);
if((sersock=socket(AF_INET,SOCK_STREAM,0))<0)
39
{
error("\n socket");
exit(0);
error("\nBIND");
exit(0);
if(listen(sersock,1)<0)
error("\n LISTEN");
error("\n ACCEPT");
exit(0);
else
read(newsock,str,sizeof(str));
do
40
printf("\n client msg:%s",str);
scanf("%s",str2);
write(newsock,str2,sizeof(str2));
listen(newsock,1);
read(newsock,str,sizeof(str));
n=strcmp(str,"BYE");
a=strcmp(str2,"BYE");
while(n!=0||a!=0);
close(newsock);
close(sersock);
return 0;
// Programfor
chatappclient.c
#include<stdio.h>
#include<sys/socket.h>
#include<sys/types.h>
#include<arpa/inet.h>
#include<netinet/in.h>
#include<unistd.h>
int a,clisock;
char str[20],str2[20];
struct sockaddr_in
cliaddr;
cliaddr.sin_port=htons(SER_PORT);
cliaddr.sin_family=AF_INET;
cliaddr.sin_addr.s_addr=inet_addr(arg[1]);
clisock=socket(AF_INET,SOCK_STREAM,0);
if(clisock<0)
perror("\n SOCKET");
exit(0);
if(connect(clisock,(struct sockaddr*)&cliaddr,sizeof(cliaddr))<0)
perror("\n CONNECT");
exit(0);
printf("\nclient connected to
%s",arg[1]); printf("\nCLIENT");
scanf("%s",&str);
if(write(clisock,str,sizeof(str))<0)
42
{
do
listen(clisock,1);
read(clisock,str2,sizeof(str2));
printf("\nserver msg:%s",str2);
printf("\nclient msg:");
scanf("%s",&str);
a=strcmp(str2,"BYE");
write(clisock,str2,sizeof(str2));
while(a!=0);
close(clisock);
return 0;
/* udpserver.c */
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <unistd.h>
43
#include <errno.h>
#include <string.h>
#include <stdlib.h>
int main()
{
int sock;
int addr_len, bytes_read;
char recv_data[1024];
struct sockaddr_in server_addr , client_addr;
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(5000);
server_addr.sin_addr.s_addr = INADDR_ANY;
bzero(&(server_addr.sin_zero),8);
while (1)
{
recv_data[bytes_read] = '\0';
printf("\n(%s,%d)said:",inet_ntoa(client_addr.sin_addr),ntohs(client_addr.sin_port));
printf("%s", recv_data);
fflush(stdout);
44
}
return 0;
}
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
int main()
{
int sock;
struct sockaddr_in server_addr;
struct hostent *host;
char send_data[1024];
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(5000);
server_addr.sin_addr = *((struct in_addr *)host->h_addr);
bzero(&(server_addr.sin_zero),8);
while (1)
{
printf("Type Something (q or Q to
quit):"); gets(send_data);
45
if ((strcmp(send_data , "q") == 0) || strcmp(send_data , "Q") == 0)
break;
else
sendto(sock, send_data, strlen(send_data), 0,
(struct sockaddr *)&server_addr, sizeof(struct sockaddr));
46
Experiment No.: 6
Aim: Write a programs in C: hello_client (The server listens for, and accepts, a single UDP
connection; it reads all the data it can from that connection, and prints it to the screen; then it
closes the connection)
Theory
In UDP, the client does not form a connection with the server like in TCP and instead just sends a
datagram. Similarly, the server need not accept a connection and just waits for datagrams to arrive.
Datagrams upon arrival contain the address of sender which the server uses to send data to the correct
client.
47
The entire process can be broken down into following steps :
UDP Server :
1. Create UDP socket.
2. Bind the socket to server address.
3. Wait until datagram packet arrives from client.
4. Process the datagram packet and send a reply to client.
5. Go back to Step 3.
UDP Client :
1. Create UDP socket.
2. Send message to server.
3. Wait until response from server is recieved.
4. Process reply and go back to step 2, if necessary.
5. Close socket descriptor and exit.
Necessary Functions :
int socket(int domain, int type, int protocol)
Creates an unbound socket in the specified domain.
Returns socket file descriptor.
Arguments :
domain – Specifies the communication
domain ( AF_INET for IPv4/ AF_INET6 for IPv6 )
type – Type of socket to be created
( SOCK_STREAM for TCP / SOCK_DGRAM for UDP )
protocol – Protocol to be used by socket.
0 means use default protocol for the address family.
int bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen)
Assigns address to the unbound socket.
Arguments :
sockfd – File descriptor of socket to be binded
addr – Structure in which address to be binded to is specified
addrlen – Size of addr structure
ssize_t sendto(int sockfd, const void *buf, size_t len, int
flags, const struct sockaddr *dest_addr, socklen_t
addrlen)
Arguments :
sockfd – File descriptor of socket
buf – Application buffer containing the data to be sent
len – Size of buf application buffer
flags – Bitwise OR of flags to modify socket behaviour
dest_addr – Structure containing address of destination
addrlen – Size of dest_addr structure
48
ssize_t recvfrom(int sockfd, void *buf, size_t len, int flags,
struct sockaddr *src_addr, socklen_t *addrlen)
Receive a message from the socket.
Arguments :
sockfd – File descriptor of socket
buf – Application buffer in which to receive data
len – Size of buf application buffer
flags – Bitwise OR of flags to modify socket behaviour
src_addr – Structure containing source address is returned
addrlen – Variable in which size of src_addr structure is returned
int close(int fd)
Close a file descriptor
Arguments :
fd – File descriptor
In the below code, exchange of one hello message between server and client is shown to demonstrate
the model.
// Driver code
int main() {
int sockfd;
char buffer[MAXLINE];
char *hello = "Hello from client";
struct sockaddr_in servaddr;
49
memset(&servaddr, 0, sizeof(servaddr));
int n, len;
close(sockfd);
return 0;
}
Output :
$ ./server
Client : Hello from client
Hello message sent.
$ ./client
Hello message sent.
Server : Hello from server
50
Experiment No.: 7
// Driver code
int main() {
int sockfd;
char buffer[MAXLINE];
char *hello = "Hello from server";
struct sockaddr_in servaddr, cliaddr;
memset(&servaddr, 0, sizeof(servaddr));
memset(&cliaddr, 0, sizeof(cliaddr));
int len, n;
n = recvfrom(sockfd, (char *)buffer, MAXLINE,
MSG_WAITALL, ( struct sockaddr *) &cliaddr,
&len);
buffer[n] = '\0';
printf("Client : %s\n", buffer);
sendto(sockfd, (const char *)hello, strlen(hello),
MSG_CONFIRM, (const struct sockaddr *) &cliaddr,
len);
printf("Hello message sent.\n");
return 0;
}
Output :
$ ./server
Client : Hello from client
Hello message sent.
$ ./client
Hello message sent.
Server : Hello from server
52
Experiment No.: 8
Aim: Write an Echo_server using TCP to estimate the round trip time
from client to the server. The server should be such that it can accept multiple connections at any
given time , with multiplexed I/O operations
memset(&saddr,0,sizeof(saddr));
sfd = socket(AF_INET,SOCK_STREAM,0);
saddr.sin_family = AF_INET;
inet_pton(AF_INET,"127.0.0.1",&saddr.sin_addr);
saddr.sin_port = htons(5004);
53
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <netinet/in.h>
#include <sys/types.h>
#include <sys/socket.h>
sfd = socket(AF_INET,SOCK_STREAM,0);
memset(&saddr,0,sizeof(saddr)); //Clear the Server address structure
for(; ;) {
caddrlen = sizeof(caddr);
nsfd = accept(sfd,(struct sockaddr*) &caddr,&caddrlen);
cn = recv(nsfd,buf,sizeof(buf),0);
if(cn == 0) {
exit(0);
}
54
Experiment No.: 9
Algorithm:
The Problem
Given the following graph, calculate the length of the shortest path from node 1 to node 2.
It’s obvious that there’s a direct route of length 6, but take a look at path: 1 -> 4 -> 3 -> 2. The length
of the path is 7 – 3 – 2 = 2, which is less than 6. BTW, you don’t need negative edge weights to get
such a situation, but they do clarify the problem.
This also suggests a property of shortest path algorithms: to find the shortest path form xto y, you
need to know, beforehand, the shortest paths to y‘s neighbours. For this, you need to know the paths
to y‘s neighbours’ neighbours… In the end, you must calculate the shortest path to the connected
component of the graph in which x and y are found.
That said, you usually calculate the shortest path to all nodes and then pick the ones you’re
intrested in.
The Algorithm
The Bellman-Ford algorithm is one of the classic solutions to this problem. It calculates the
shortest path to all nodes in the graph from a single source.
55
the path to the source as 0:
Relaxing an edge means checking to see if the path to the node the edge is pointing to can’t be
shortened, and if so, doing it. In the above graph, by checking the edge 1 -> 2 of length 6, you find
that the length of the shortest path to node 1 plus the length of theedge 1 -> 2 is less then infinity. So,
you replace infinity in node 2 with 6. The same can be said for edge 1 -> 4 of length 7. It’s also
worth noting that, practically, you can’t relax the edges whose start has the shortest path of length
infinity to it.
Now, you apply the previous step n – 1 times, where n is the number of nodes in the graph. In this
example, you have to apply it 4 times (that’s 3 more times).
56
Here, d[i] is the shortest path to node i, e is the number of edges and edges[i] is the i-th edge.
It may not be obvious why this works, but take a look at what is certain after each step. After the first
step, any path made up of at most 2 nodes will be optimal. After the step 2, any path made up of at
most 3 nodes will be optimal… After the (n – 1)-th step, any path made up of at most n nodes will be
optimal.
The Programme
The following programme just puts the bellman_ford function into context. It runs inO(VE) time, so
for the example graph it will do something on the lines of 5 * 9 = 45relaxations. Keep in mind that
this algorithm works quite well on graphs with few edges, but is very slow for dense graphs (graphs
with almost n2 edges)
#include <stdio.h>
typedef struct {
int u, v, w;
} Edge;
void printDist() {
int i;
printf("Distances:\n");
printf("\n\n");
}
57
void bellman_ford(int s) {
int i, j;
d[s] = 0;
/* printDist(); */
bellman_ford(0);
printDist();
return 0;
58
}
And here’s the input file used in the example (dist.txt):
5
06070
0 0 5 8 -4
0 -2 0 0 0
0 0 -3 9 0
20700
59
Experiment No.: 10
SOURCE CODE:
Server:
#include<string.h>
#include<stdio.h>
#include<netdb.h>
#include<netinet/in.h>
#include<sys/types.h>
#include<sys/socket.h>
#include<errno.h>
int main(int argc,char ** argv)
{
struct sockaddr_in saddr,caddr;
int r,len,ssid,csid,pid,pid1,i,n;
char wbuffer[1024],rbuffer[1024];
float c;
if(argc<2)
fprintf(stderr,"Port number not specified\n");
ssid=socket(AF_INET,SOCK_STREAM,0);
if(ssid<0)
perror("Socket failed\n");
bzero((char *)&saddr,sizeof(saddr));
saddr.sin_family=AF_INET;
saddr.sin_port=htons(atoi(argv[1]));
saddr.sin_addr.s_addr=INADDR_ANY; if(bind(ssid,
(struct sockaddr *)&saddr,sizeof(saddr))<0)
perror("Socket Bind\n");
listen(ssid,5);
len=sizeof(caddr);
csid=accept(ssid,(struct sockaddr *)&caddr,&len);
60
if(csid<0)
perror("Socket Accept\n");
fprintf(stdout,"TYPE MESSAGE TO CLIENT\n");
pid=fork();
if(pid==0)
{
while(1)
{
bzero(rbuffer,1024);
n=read(csid,rbuffer,1024);
if(n==0)
perror("Socket read\n");
else
fprintf(stdout,"MESSAGE FROM CLIENT: %s\n",rbuffer);
}
exit(0);
}
else
{
while(1)
{
bzero(wbuffer,1024);
fgets(wbuffer,1024,stdin);
n=write(csid,wbuffer,1024);
if(n==0)
perror("Socket Write");
}
}
return(0);
}
CLIENT:
#include<stdio.h>
#include<netdb.h>
#include<netinet/in.h>
#include<sys/types.h>
#include<sys/socket.h>
#include<errno.h>
int main(int argc,char ** argv)
{
struct sockaddr_in saddr;
struct hostent *server;
int n,ssid,csid,pid,pi;
char wbuffer[1024],rbuffer[1024];
char str[15];
if(argc<3)
61
fprintf(stderr,"Parameter inadequate\n");
csid=socket(AF_INET,SOCK_STREAM,0);
if(csid<0)
perror("Socket Failed\n");
bzero((char *)&saddr,sizeof(saddr));
server=gethostbyname(argv[1]);
saddr.sin_family=AF_INET;
saddr.sin_port=htons(atoi(argv[2]));
bcopy((char *)server->h_addr,(char *)&saddr.sin_addr.s_addr,server->h_length);
ssid=connect(csid,(struct sockaddr *)&saddr,sizeof(saddr));
if(ssid<0)
perror("Socket Connect\n");
fprintf(stdout,"ENTER MESSAGE TO SERVER:\n");
pid=fork();
if(pid==0)
{
while(1)
{
bzero(wbuffer,1024);
fgets(wbuffer,1024,stdin);
n=write(csid,wbuffer,sizeof(wbuffer));
if(n==0)
perror("Socket Write");
}
exit(0);
}
else
{
while(1)
{
bzero(rbuffer,1024);
n=read(csid,rbuffer,sizeof(rbuffer));
if(n==0)
perror("Socket Read\n");
else
fprintf(stdout,"MESSAGE FROM SERVER: %s\n",rbuffer);
}
return(0);
}
}
OUTPUT:
SERVER:
[05mecse090@networkserver ~]$ cc chatserv.c
[05mecse090@networkserver ~]$./a.out 9898
TYPE MESSAGE TO CLIENT
MESSAGE FROM CLIENT: hi
62
hai
CLIENT:
[05mecse090@networkserver ~]$ cc chatcli.c
[05mecse090@networkserver ~]$cc chatcli.c
[05mecse090@networkserver ~]$ ./a.out 127.0.0.1
ENTER MESSAGE TO SERVER:
hi
MESSAGE FROM SERVER: hai
RESULT:
Thus the c program for the simulation of sliding window protocol has beenexecuted and the output is
verified successfully.
63
Experiment No.: 11
Algorithm:
Client
Step 1: start the program
Step 2: Declare the variables and structure for sockets
Step 3: And then get the port number
Step 4: Create a socket using socket functions
Step 5: The socket is binded at the specified port
Step 6: Using the object, the port and address are declared
Step 7: Get the source file and the destination file from the user
Step 8: Use the send command for sending the two strings
Step 9: Receive the bytes sent from the
server Step 10: Print it in the console
Step 11: Close the socket
Server
Step 1: Start the program
Step 2: Declare the variables and structure for sockets
Step 3: And then get the port number
Step 4: Create a socket using socket functions
Step 5: Use the connect command for socket connection
Step 6: Use bind option to bind the socket address
Step 7: Use accept command to receive the connection from the client
Step 8: Receive command from the client
Step 9: Send the file to the client socket
Step 10: Close the connection
PROGRAM:
SERVER:
#include<stdio.h>
#include<sys/types.h>
#include<netinet/in.h>
#include<string.h>
#include<sys/socket.h>
int main()
{
int sd,nsd,i,port=1234;
char content[100]="\0",fname[100]="\0";
struct sockaddr_in ser,cli;
FILE *fp;
if((sd=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP))==-1)
64
{
printf("ERROR::SOCKET CREATION PROBLEM--CHECK THE PARAMETERS.\n");
return 0;
}
bzero((char *)&ser,sizeof(ser));
printf("THE PORT ADDRESS IS: %d\n",port);
ser.sin_family=AF_INET;
ser.sin_port=htons(port);
ser.sin_addr.s_addr=htonl(INADDR_ANY);
if(bind(sd,(struct sockaddr *)&ser,sizeof(ser))==-1)
{
printf("\nERROR::BINDING PROBLEM, PORT BUSY--PLEASE CSS IN THE SER AND
CLI\n");
return 0;
}
i=sizeof(cli);
listen(sd,1);
printf("\nSERVER MODULE\n");
printf("********************\n");
nsd=accept(sd,(struct sockaddr *)&cli,&i);
if(nsd==-1)
{
printf("\nERROR::CLIENT ACCEPTIN PROBLEM--CHECK THE DEIPTOR
PARAMETER.\n\n");
return 0;
}
printf("\nCLIENT ACCEPTED");
i=recv(nsd,fname,30,0);
fname[i]='\0';
fp=fopen(fname,"rb");
while(1)
{
i=fread(&content,1,30,fp);
content[i]='\0';
send(nsd,content,30,0);
strcpy(content,"\0");
if(i<30)
break;
}
send(nsd,"EOF",4,0);
printf("\nFILE TRANSFERED TO DESTINATION\n\n");
fclose(fp);
close(sd);
close(nsd);
return 0;
}
65
CLIENT:
#include<stdio.h>
#include<sys/types.h>
#include<netinet/in.h>
#include<string.h>
#include<sys/socket.h>
int main()
{
int sd,i,port=1234;
char content[100]="\0",fname[100]="\0",file[100]="\0";
struct sockaddr_in ser;
FILE *fp;
if((sd=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP))==-1)
{
printf("\nERROR::SOCKET CREATION PROBLEM--CHECK THE
PARAMETER.\n\n");
return 0;
}
bzero((char *)&ser,sizeof(ser));
printf("\nTHE PORT ADDRESS IS: %d\n",port);
ser.sin_family=AF_INET;
ser.sin_port=htons(port);
ser.sin_addr.s_addr=htonl(INADDR_ANY);
if(connect(sd,(struct sockaddr *)&ser,sizeof(ser))==-1)
{
printf("\nERROR::CANT CONNECT TO SERVER--CHECK PARAMETERS.\n\n");
return 0;
}
printf("\nTHIS IS THE CLIENT MODULE. THIS MODULE CAN ASK THE SERVER
A FILE");
printf("\n*****************************************************************\n\n");
printf("\nENTER THE PATHNAME OF SOURCE FILE::\n");
scanf("%s",fname);
printf("\nENTER THE PATHNAME OF DESTINATION FILE::\n");
scanf("%s",file);
send(sd,fname,30,0);
fp=fopen(file,"wb");
while(1)
{
i=recv(sd,content,30,0);
content[i]='\0'; if(!
strcmp(content,"EOF"))
break;
//fwrite(&content,strlen(content),1,fp);
printf("%s",content); strcpy(content,"\
0");
66
}
printf("\n\nFILE RECEIVED\n\n");
fclose(fp);
close(sd);
return 0;
}
OUTPUT:
SERVER:
67
Viva Questions
Experiment No.1
Network Topology is a physical layout of the computer network and it defines how the computers,
devices, cables etc are connected to each other.
Star topology consists of a central hub that connects to nodes. This is one of the easiest to setup
and maintain.
In star topology a main hub is present to which all other nodes of the network are connected.
Every data or information being transmitted or received in this topology has to pass through the
hub. The hub directs the data to its destination.
Topology in networks is the structure or pattern in which each and every node in the network is
connected. There are many topologies in networking like bus, tree, ring, star, mesh, and hybrid.
In bus topology, there is a single cable to which all the network nodes are connected. So whenever
a node tries to send a message or data to other nodes, this data passes through all other nodes in the
network.
68
Experiment No.:2
1 What is a Network?
A network is a set of devices connected to each other using a physical transmission medium.
2 What is a Node?
Two or more computers are connected directly by an optical fiber or any other cable. A node is a
point where a connection established. It is a network component that is used to send, receive and
forward the electronic information.
3 What is WAN?
WAN stands for Wide Area Network. It is an interconnection of computers and devices that are
geographically dispersed. It connects networks that are located in different regions and countries.
4 What is VPN?
VPN means Virtual Private Network, a technology that allows a secure tunnel to be created across
a network such as the Internet. For example, VPNs allow you to establish a secure dial-up
connection to a remote server.
69
Experiment No.: 3
1 What is TCP/IP?
TCP/IP is short for Transmission Control Protocol / Internet Protocol. This is a set of protocol
layers that is designed to make data exchange possible on different types of computer networks,
also known as heterogeneous network.
2 What is DNS?
DNS is Domain Name System. The main function of this network service is to provide host names
to TCP/IP address resolution.
3 What protocols fall under the Application layer of the TCP/IP stack?
The following are the protocols under TCP/IP Application layer: FTP, TFTP, Telnet and SMTP.
4 What is client/server?
Client/server is a type of network wherein one or more computers act as servers. Servers provide a
centralized repository of resources such as printers and files. Clients refers to workstation that
access the server.
5 Describe Ethernet.
Ethernet is one of the popular networking technologies used these days. It was developed during
the early 1970s and is based on specifications as stated in the IEEE. Ethernet is used in local area
networks.
70
Experiment No.: 4
71
Experiment No.: 5
3 What Is TCP/IP?
TCP/IP is a name given to the collection (or suite) of networking protocols that have been used to
construct the global Internet. The protocols are also referred to as the DOD (Dee-oh-Dee) or
Arpanet protocol suite because their early development was funded by the Advanced Research
Projects Agency (ARPA) of the US Department of Defense (DOD).
72
Experiment No.:6
1 What Are The Major Difference Between UDP And TCP/IP Protocol?
No. The IP address of a system is the logical address where as the address of the MODEM is
the MAC (Media Access Control) address, it is the physical address provided by the vendor.
73
Experiment No.: 7
1. What is IP address?
The 32 bits Internet address is that which defines a host or router. Uniquely and universally on the
internet. The portion that identifies the network is of the IP address called the net id. The portion
identifies the host or router on the network of the IP address that is called the host id. An IP
address defines connection to a network of a device.
2. Explain the three types of addresses in TCP/IP?
Three types of addresses used by computers using the TCP/IP
Physical address,
Internetwork address
Port address.
The physical address, is the address as defined by its LAN or WAN of a node. The IP address
defines a host on the Internet uniquely. the port address is an identifier which identifies a
process on a host.
TCP/IP questions
Packets make only the address of the next hop which is listed in the routing table. All hosts on a
network share one entry in the routing table in network specific routing in host specific in the
routing table full IP address of a host is given routing. A router is assigned to receive packets with
no match in the routing table in default routing.
74
4. What are the fields included in routing table?
The routing table consists of seven fields: These are a mask, a address of destination, a address of
next-hop, flags, reference count, use, and interface. The routing module applies the mask row by
row, to the received address of destination till a match is found. Classless addressing requires
geographical and hierarchical routing for preventing immense routing tables.
5. What is Fragmentation?
It is the division of a datagram into smaller units to accommodate of a data link protocol’s MTU.
The fields in the IP header which is related to fragmentation are the identification
number, the flags fragmentation, and the offset fragmentation. The IP datagram header is consists
of a fixed, 20- byte section and also a variable options section with a maximum of 40 bytes.
75
Experiment No.: 8
2 What is multiprogramming?
Multiprogramming is a rapid switching of the CPU back and forth between processes.
3 Name the seven layers of the OSI Model and describe them briefly.
Physical Layer - covers the physical interface between devices and the rules by which bits are
passed from one to another.
Data Link Layer - attempts o make the physical link reliable and provides the means to
activate, maintain, and deactivate the link.
Network Layer - provides for the transfer of information between end systems across
some sort communications network.
Transport Layer - provides a mechanism for the exchange of data between end systems.
Session Layer - provides the mechanism for controlling the dialogue between applications in end
systems.
Presentation Layer - defines the format of the data to be exchanged between applications and
offers application programs a set of data transformation services.
Application Layer - provides a means for application programs to access the OSI environment.
76
Experiment No.: 9
4 Explain Can We Have Too Many Apes And What Is The Impact?
We can absolutely have too many APs and this can actually be more troublesome than too
few APs. When devices on the same channel are co-located without enough channel separation
the result is wasted equipment and reduced performance.
77
Experiment No.: 10
Sliding window protocols are data link layer protocols for reliable and sequential delivery of data
frames. The sliding window is also used in Transmission Control Protocol. In this protocol,
multiple frames can be sent by a sender at a time before receiving an acknowledgment from the
receiver. The term sliding window refers to the imaginary boxes to hold frames. Sliding window
method is also known as windowing.
78
Experiment No.:11
1 What Is Ftp?
FTP stands for File Transfer Protocol. An FTP server allows clients to connect to it either
anonymously or with a username and password combination. After successful authentication,
files can be transferred back and forth between the server and client. The files are neither
encrypted nor compressed.
79