You are on page 1of 83

CSL 332 Networking Lab, B.

Tech CSE

Exp No. 1
BASICS OF NETWORK CONFIGURATION FILES AND NETWORKING
COMMANDS IN LINUX

Getting started with the basics of network configuration files and networking
commands in Linux.*

AIM: To study basics of network configuration files and networking commands in


Linux
To store IP addresses and other related settings, Linux uses a separate configuration file
for each network interface. All these configuration files are stored in the
/etc/sysconfig/network-scripts directory.Name of configuration files starts with the
ifcfg-.After the ifcfg-, to keep each file separate, name of the interface is used.

Sample output of the /etc/sysconfig/network-scripts directory:

Files Description
ifcfg-lo Stores the configuration of loopback device. Loopback device is a
virtual network interface. It is used to test the TCP/IP protocol
stocks in local host.

ifcfg-* Stores the configuration of the network interface. Each file only
stores the configuration of that interface, which it represents.

Stores the scripts which activate and deactivate their associated


ifup-* and protocols. For example, the ifup-ppp and ifdown files activate and
ifdown-* deactivate the ppp protocol respectively.

Department of Computer Science and Engineering Page 16


Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

Directive Description
BOOTPROTO Defines how the IP address should be obtained. Four values can
be used here; dhcp, bootp, none and static. Use the
value "dhcp", to obtain IP from the dhcp server. To boot from
a network boot server and get IP, use the value "bootp". To
assign IP manually, use the value "static". Use the
value "none" if you don't want to assign the IP address.
BRIDGE Specifies the name of the network bridge.
BROADCAST0 Broadcast address of the first IP configuration.
GATEWAY0 Gateway address of the first IP configuration.
DEFROUTE Specifies whether to use this interface as the default route or
not.
DEVICE Device name of the network interface.
DNS1 IP address of the first DNS server.
HWADDR Hardware address of the network interface.
IPADDR0 Specifies the first IP address of interface.
IPV6INIT Specifies whether to enable to IPv6 or not.
NAME Name of the interface. If not assigned manually, the device
name will be used.
NETMASK0 Netmask or subnet mask address of the first IP configuration.
NM_CONTROLLED Specifies whether the Network Manager service is allowed to
modify the settings stored in this file or not.
ONBOOT Whether to activate or not this interface on boot.
USERCTL Specifies whether the non-root users are allowed to activate
this interface or not.
UUID Unique ID of this interface.
TYPE Type of this interface.

Department of Computer Science and Engineering Page 17


Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

Settings stored in the interface’s configuration file are applied on the interface when we start the
system or activate the interface. To view these settings, cat command is used.
The following table lists important directives of this file with description.
In addition to the individual network interface configuration files in the /etc/sysconfig/network-
scripts directory, there are other, more global network configuration files. These files are:

etc/hosts file

This file is used to map the hostname with IP address. Once hostname and IP address are mapped,
hostname can be used to access the services available on the destination IP address. A hostname
can be mapped with an IP address in two ways; through the DNS server and through the /etc/hosts
file.
DNS server provides this facility in more dynamic and flexible way but also requires a lot of
complex configurations. Due to complexity, usually DNS server is not used in small
networks.The /etc/hosts file also provides this functionality in local system but requires manual
mapping of all hostnames with their IP addresses.Each row in this file represents a unique entry.
It contains an IP address in the first column, full or official hostname in the second column and
short or alias name in third column.

Sample output of the /etc/hosts file:

/etc/resolv.conf
The resolver configuration file provides access to DNS. This file usually has at least two lines,
one line specifying the IP address of a DNS server (or name server) and the other specifying the
search domain. The following example shows the name servers and the search domain:
#cat /etc/resolv.conf
search example.com
nameserver 192.168.154.2
nameserver 172.168.106.3
nameserver 193.32.3.25

/etc/sysconfig/network
Based on how the network interfaces are configured, this filemay contain none, one or two
configuration directives. If a system is configured to get IP configuration from the DHCP server,
there will be no configuration in this file.
Two directives that may appear in this file are; GATEWAY and NETWORKING.
GATEWAY directive shows the IP address of default gateway. This directive appears only if
the same IP address is used for the default gateway in all network interfaces.
NETWORKING directive is used to control the network service. It can be configured with two
values; yes and no. If the value "no" is used, the network service does not start.
Department of Computer Science and Engineering Page 18
Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

/etc/nsswitch.conf

This file is the system databases and name service switch configuration file. It provides
sources for common configuration databases and name resolution mechanisms. Entries
in this file identify the database name in the first field, then a colon, and then a list of
possible resolution mechanisms in the second field. The order in which the mechanisms
are listed determines the order in which queries on the specified database are resolved.

The following example indicates that host name resolution is attempted first by querying
local files, that is, /etc/hosts, and then by querying the DNS server if the host name is not
resolved:
# cat /etc/nsswitch.conf
...
hosts: files dns...

a) View the configuration, including addresses of your computers network


interfaces.

The "ipaddr show" command displays the current configuration and status of all
network interfaces. This command is used to know or view the following information.

Current status: - whether the interface is up or down.


Mac address: - physical address of the interface.
IPv4 address: - IPv4 address of the interface.
IPv6 address: - IPv6 address of the interface.

Sample output of ipaddr show:

To view information only about a specific interface, specify that interface’s name or ID
with the commands.

Department of Computer Science and Engineering Page 19


Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

b)Test the network connectivity between your computer and several other computers.
To check connectivity between two computers,use the ping command. The ping command uses
the following syntax.
#ping [ip address or name of remote system]
By default, the ping command works continuously. To stop this command, press the ctrl+c keys.
If reply from the remote system is there, both systems are connected.

Sample output of ping command

c)View the active TCP connections in the computer after visiting a website.

netstat (network statistics) is acommand-line network utility that displays network


connections for Transmission Control Protocol (both incoming and outgoing),It is used for
finding problems in the network and to determine the amount of traffic on the network as a
performance measurement.
Netstat provides statistics for the following:
Proto – The name of the protocol (TCP or UDP).
Local Address – The IP address of the local computer and the port number being used. The
name of the local computer that corresponds to the IP address and the name of the port is
shown unless the -n parameter is specified. An asterisk (*) is shown for the host if the server
is listening on all interfaces. If the port is not yet established, the port number is shown as an
asterisk.
Foreign Address – The IP address and port number of the remote computer to which the
socket is connected. The names that corresponds to the IP address and the port are shown
unless the -n parameter is specified. If the port is not yet established, the port number is
shown as an asterisk (*).
State – Indicates the state of a TCP connection. The possible states are as follows:
CLOSE_WAIT, CLOSED, ESTABLISHED, FIN_WAIT_1, FIN_WAIT_2, LAST_ACK,
LISTEN, SYN_RECEIVED, SYN_SEND, and TIME_WAIT. For more information about
the states of a TCP connection
Command used is netstat -at.

Department of Computer Science and Engineering Page 20


Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

Sample output of netstat command

d)Find the hardware/MAC address of another computer in the network using ARP

ARP table contains hardware address (MAC address) and software address (IP address) of
other systems available in LAN network. By default, a system builds and uses this table to
connect with other systems in LAN network.To view this table, use the ip neigh command.

Sample output

Result:
Observed network configuration files and executed various networking commands in Linux.

Department of Computer Science and Engineering Page 21


Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

Exp No. 2
SYSTEM CALLS USED FOR NETWORK PROGRAMMING IN LINUX

To familiarize and understand the use and functioning of system calls used for
network programming in Linux.

a)Write the system calls used for creating sockets and transferring data between two
nodes.

AIM: To study system calls used for creating sockets and transferring data between two
nodes.

Sockets are a form of interprocess communication that exists between two unrelated
processes which allows us to communicate over the internet using streams (TCP-
Transmission Control Protocol) or datagrams (UDP-User Datagram Protocol).

Figure 1. Socket system calls for connection oriented protocols

Department of Computer Science and Engineering Page 22


Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

Figure 2. Socket system calls for connectionless protocols

Server is started first; it will accept connections from the client. Once a connection is established,
then communication can occur through the read and write system calls to the file descriptor
associated with the socket.

socket

#include<sys/types.h>
#include<sys/socket.h>
int socket(int family, int type, int protocol);
Usage
s = socket(AF_INET, SOCK_STREAM, 0);
s is a small integer value, similar to a file descriptor with five pieces of information (5-
tuple):
The family AF_INET indicates that the socket will be created in the internet domain. The
AF_ prefix stands for "address family."SOCK_STREAM indicates that it will be a
connection-oriented protocol. SOCK_DGRAMindicates that it will be a connectionless
protocol.0 indicates to automatically fill in the protocol, which will be TCP when
SOCK_STREAM is used and UDP when SOCK_DGRAM is used.
bind

The bind system call assigns a name to an unnamed socket.


#include<sys/types.h>
#include<sys/socket.h>
int bind(int sockfd, struct sockaddr *myaddr, int addrlen);
The first argument is the socket descriptor returned from socket system call. The second
argument is a pointer to a protocol-specific address and the third argument is the size of
this address. If successful, bind returns 0; otherwise, it returns -1.

Usage
bind(s,(struct sockaddr *)&saddr,sizeof(saddr))

Department of Computer Science and Engineering Page 23


Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

s is the "socket descriptor" returned from the call to socket(),saddr is actually a


sockaddr_in structure (for the internet domain), thus casting is required. A sockaddr_in
structure is like:
struct sockaddr_in {
short sin_family; /*Set to AF_INET*/
u_shortsin_port; /*16 bit port number*/
struct in_addrsin_addr; /*Set to the host*/
char sin_zero[8]; /*unused*/
};
struct in_addr
{
u_long s-addr;
};
struct sockaddr
{
u_shortsa_family ;
char sa_data[14];//The content of 14 bytes of protocol
}

There are three uses of bind. Servers register their well-known address with the system.
It tells the system "this is my address and any messages received for this address are to be given
to me." Both connection-oriented and connectionless servers need to do this before accepting
client requests.A client can register a specific address for itself.A connectionless client needs to
assure that the system assigns it some unique address, so that the other end (the server) has a
valid return address to send its responses to.

connect

A client process connects a socket descriptor following the socket system call to establish a
connection with a server.
#include <sys/types.h>
#include <sys/socket.h>

int connect(int sockfd, struct sockaddr *servaddr, int addrlen);


The sockfd is a socket descriptor that was returned by the socket system call. The second and
third arguments are a pointer to a socket address, and its size, as described earlier.
For most connection-oriented protocols (TCP, for example), the connect system call results in
the actual establishment of a connection between the local system and the foreign system. The
connect system call does not return until the connection is established, or an error is returned to
the process.

listen

This system call is used by a connection-oriented server to indicate that it is willing to receive
connections.
#include <sys/types.h>
#include <sys/socket.h>

int listen(int sockfd, int backlog);

Department of Computer Science and Engineering Page 24


Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

It is usually executed after both the socket and bind system calls, and immediately before the
accept system call. The backlog argument specifies how many connection requests can be
queued by the system while it waits for the server to execute the accept system call. This
argument is usually specified as 5, the maximum value currently allowed.
accept

After a connection-oriented server executes the listen system call described above, an actual
connection from some client process is waited for by having the server execute the accept system
call.
#include <sys/types.h>
#include <sys/socket.h>
int accept(int sockfd, struct sockaddr *peer, int *addrlen);
accept takes the first connection request on the queue and creates another socket with the same
properties as sockfd. If there are no connection requests pending, this call blocks the caller until
one arrives.
The peer and addrlen arguments are used to return the address of the connected peer process (the
client). addrlen is called a value-result argument: the caller sets its value before the system call,
and the system call stores a result in the variable. For this system call the caller sets addrlen to
the size of the sockaddr structure whose address is passed as the peer argument.

send, sendto, recv and recvfrom

These system calls are similar to the standard read and write system calls, but additional
arguments are required.
#include <sys/types.h>
#include <sys/socket.h>

int send(int sockfd, char *buff, int nbytes, int flags);


int sendto(int sockfd, char *buff, int nbytes, int flags, struct sockaddr *to, int addrlen);
int recv(int sockfd, char *buff, int nbytes, int flags);
int recvfrom(int sockfd, char *buff, int nbytes, int flags, struct sockaddr *from, int *addrlen);
The first three arguments, sockfd, buff, and nbytes, to the four system calls are similar to the first
three arguments for read and write. The flags argument can be safely set to zero ignoring the
details for it. The to argument for sendto specifies the protocol-specific address of where the data
is to be sent. Since this address is protocol-specific, its length must be specified by addrlen.
Therecvfrom system call fills in the protocol-specific address of who sent the data into from. The
length of this address is also returned to the caller in addrlen. Note that the final argument to
sendtois an integer value, while the final argument to recvfrom is a pointer to an integer value.
close

The normal Unix close system call is also used to close a socket.
int close(int fd);
If the socket being closed is associated with a protocol that promises reliable delivery (e.g.,
TCP ), the system must assure that any data within the kernel that still has to be transmitted or
acknowledged, is sent.

Results:

Familiarized and understood the system calls used in socket programming in Linux.

Department of Computer Science and Engineering Page 25


Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

Exp No. 3
CLIENT-SERVER COMMUNICATION USING TCP SOCKET PROGRAMMING

a. Implement client-server communication using socket programming and TCP as


transport layer protocol

AIM: To implement calculator using socket programming and TCP as transport layer protocol
in C

Sample Input and Output:

Server

client

Department of Computer Science and Engineering Page 26


Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

b. Implement a multi-user chat server using TCP as transport layer protocol.

Multi-user Chat

AIM: To implementachat serversothat multipleuserscan chatsimultaneously


Description

To implement chat server the select function is used. It is a function called by a process.
When aprocess calls this function, the processgoes tosleep and wakes up only when one or
moreeventsoccurorwhen aspecified amount of timehas passed.

intselect(int maxfdp1,fd_set*readset,fd_set*writeset,fd_set*exceptset,conststructtimeval
*timeout);

Theheaderfilesrequired are<sys/select.h>and<sys/time.h>
The function returns -1 on error, count of ready descriptors and 0 on timeout. If we want the
kernel towait for as long as one descriptor becomes ready then we specify the timeout
argument as a nullpointer. readset, writeset and exceptset specify the descriptors that we
want the kernel to test forreading, writing and exception conditions. select uses descriptor
sets. Each set is an array of integers.Each bit in an integer corresponds to a descriptor. In a
32 bit integer, the first element of the arrayrepresents descriptors from 0 to 31. Second
element of the array represents descriptors from 32 to 63andso on. Wehavefourmacros
forthefd_set datatype.

voidFD_ZERO(fd_set*fdset);//clears all bitsin fd_set


void FD_SET(int fd, fd_set * fdset); // turns on the bit
for fd in fdsetvoid FD_CLR(int fd, fd_set * fdset); //
turns off the bit for fd in
fdsetintFD_ISSET(intfd,fd_set*fdset); //is thebit forfd
oninfdset
Usage:
fd_setrset;
FD_ZERO(&rset); // all bits
offFD_SET(1, &rset); // turn
on bit for fd
1FD_SET(4,&rset);//turnon
bitforfd4
setthat argumentofselect to NULL, i.e; for readset, writesetorexceptset.

Department of Computer Science and Engineering Page 27


Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

maxfdp1argument specifies the number of descriptors to be tested.It is equal to value of max


descriptor to be tested plus one. This is because descriptor starts with 0. When we call select
we specify the values of the descriptors that we are interested in and on return the result
indicates which descriptors are ready.We turn on all the bits in the descriptor sets that we are
interested in. On return of the call,descriptors that are not ready will have the corresponding
bit cleared in the descriptor set.
Wecanuseselecttocreateaserverwhichcanhandleclientswithoutforkingprocessfor each
client.

Sample Input and Output:


server

client1

client2

Result:
The program hasbeen executed successfully and the output is obtained and verified.

Department of Computer Science and Engineering Page 28


Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

Exp No. 4
CLIENT-SERVER COMMUNICATION USING UDP SOCKET PROGRAMMING

a. Implement client-server communication using socket programming and UDP as


transport layer protocol, input a string at client, Server to reverse the string, Reversed
string to be displayed at client.

AIM:
To exchange datagrams from client to server using UDP socket.

ALGORITHM:

Server
1. Create a UDP socket.
2. Bind the socket to the server address.
3. Wait until the datagram packet arrives from the client.
4. Process the datagram packet and send a reply to the client.
5. Go back to Step 3.

Client
1. Create a UDP socket.
2. Send a message to the server.
3. Wait until response from the server is received.
4. Process reply and go back to step 2, if necessary.
5. Close socket descriptor and exit.

Sample Input and Output:

server

client

Result:

The program hasbeen executed successfully and the output is obtained and verified.

Department of Computer Science and Engineering Page 29


Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

b. Implement a Concurrent Time Server application using UDP to execute the program
at a remote server. Client sends a time request to the server, server sends its system time
back to the client. Client displays the result.

Concurrent Time Server

AIM: Clients to send time request to the server, server send its system time back to the client.

Description:
A concurrent server handles multiple clients at the same time. The simplest technique for a
concurrent server is tocall the Unix fork function, i.e; creating one child proces s for each
client.
The current time and date is obtained by the library function time which returns the number
of secondssince the Unix Epoch: 00:00:00 January 1, 1970, UTC (Coordinated Universal
Time). ctime is afunctionthat converts this integer value into a humanreadable string.
Algorithm:
Client
1. Create UDP socket
2. Send a request for time to the server
3. Receive the time from the server
4. Display the result
Server

1. Create a UDP socket


2. Bind the port and address to the socket
3. while (1)
Receive time request from the client
create a child process using fork If child process
Use time and ctime functions to find out cuurent time
Send the time as a string to the client
Exit
4. end of while

Department of Computer Science and Engineering Page 30


Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

Sample Input and Output:

Server

Client

Result:
The program has been executed successfully and the output is obtained and verified.

Department of Computer Science and Engineering Page 31


Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

Exp No. 5
SIMULATE SLIDING WINDOW FLOW CONTROL PROTOCOLS

a. Simulate the Stop and Wait sliding window flow control protocol.

AIM: To implement a program for the Stop and Wait sliding window flow control protocol.

Description:

A sliding window protocol with a maximum window size of one is a protocol uses stop-and-wait
since the sender transmits a frame and waits for its acknowledgement before sending the next
one starting machine fetches the first packet from its network layer, builds a frame from it, and
sends it. When this frame arrives, the receiving data link layer checks to see if it is a duplicate.
If the frame is the one expected, it is passed to the network layer and the receiver's window is
slid up. The acknowledgement field contains the number of the last frame received without error.
If this number agrees with the sequence number of the frame the sender is trying to send, the
sender knows it is done with the frame stored in buffer and can fetch the next packet from its
network layer. If the sequence number disagrees, it must continue trying to send the same frame.

Department of Computer Science and Engineering Page 32


Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

Algorithm:
1. Start.
2. Transmit the first frame
3. Receive the acknowledgement for the first frame
4. Transmit the next frame
5. If an acknowledgement is not received for a particular frame, retransmit that frame.
6. Repeat the steps 5 to 7 till the number of frames reaches the limit.
7. Stop.

Sample Input and Output:

Department of Computer Science and Engineering Page 33


Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

Result:

The program has been executed successfully and the output is obtained and verified.

Department of Computer Science and Engineering Page 34


Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

Exp No. 6
IMPLEMENT AND SIMULATE ALGORITHM FOR DISTANCE VECTOR
ROUTING PROTOCOL

To implement and simulate algorithm for Distance Vector Routing protocol.

AIM:A program for distance vector algorithm to find suitable path for transmission.

Description:

Distance vector routing algorithms operate by having each router maintain a table giving
the best known distance to each destination and which line to get there. These tables are
updated by exchanging information with the neighbour's. In distance vector routing,
each router maintains a routing table indexed by, and containing one entry for, each
router in subnet. This entry contains two parts: the preferred outgoing line to use for that
destination, and an estimate of the time or distance to that destination.The router is
assumed to know the "distance" to each of its neighbour. If the metric is hops, the
distance is just one hop. If the metric is queue length, the router simply examines each
queue.
Here Bellman-Ford algorithm is used to implement distance vector routing algorithm.

Algorithm:

1. Start
2. The distance of the node to itself is assigned to zero and when a node is unreachable the
distance is accepted as 999.
3. Accept the input distance matrix from the user (costmat[][]) that represents the distance
between each node in the network.
4. Store the distance between nodes in a suitable variable.
5. Calculate the minimum distance between two nodes by iterating.
6. If the distance between two nodes is larger than the calculated alternate available path,
replace the existing distance with the calculated distance.
7. Print the shortest path calculated.
8. Stop.

Department of Computer Science and Engineering Page 35


Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

Sample Input and Output:

Department of Computer Science and Engineering Page 36


Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

Result:

The program hasbeen executed successfully and the output is obtained and verified.

Department of Computer Science and Engineering Page 37


Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

Exp No. 7
IMPLEMENTATION OF FILE TRANSFER PROTOCOL

AIM: -
Program to implement simple FTP server for file transfer to server.

Algorithm:
Server:
1. Start
2. Declare the variables and structures
3. Create a socket using socket function
4. The socket is binded to a specific port.
5.Start Listening for the Connection
6. Accept the Connection from the client
7. Receive the data from the client
8.Write the data into the file
9. Stop.
Client:
1.Start
2. Declare the variables and structures
3. Create a socket and execute the connection function
4. Open a new file with some contents
5. Read the data from the file and written to a new file by the server.
6. The content is displayed.
7. Close the Connection.

Department of Computer Science and Engineering Page 38


Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

Sample Input and Output:

ftpserver

ftpclient

hellocopy.txt

Result:
The program has been executed successfully and the output is obtained and verified.

Department of Computer Science and Engineering Page 39


Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

Exp No. 8
LEAKY BUCKET ALGORITHM

Implement congestion control using a leaky bucket algorithm.

AIM:To implementa program for congestion control using Leaky bucket algorithm.

Description:

It is a single-server queueing system with constant service time. Imagine a bucket with a small
hole in the bottom. No matter the rate at which water enters the bucket, the outflow is at a
constant rate, when there is any water in the bucket and zero when the bucket is empty. Also,
once the bucket is full, any additional water entering it spills over the sides and is lost (i.e., does
not appear in the output stream under the hole). The same idea can be applied to packets.
Conceptually, each host is connected to the network by an interface containing a leaky bucket,
that is, a finite internal queue. The leaky bucket consists of a finite queue. When a packet arrives,
if there is room on the queue it is appended to the queue; otherwise, it is discarded. At every
clock tick, one packet is transmitted.

Department of Computer Science and Engineering Page 40


Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

Algorithm:

1. Start.
2. Set the bucket size or the buffer size.
3. Set the output rate.
4. Transmit the packets such that there is no overflow.
5. Repeat the process of transmission until all packets are transmitted. (Reject packets
where its size is greater than the bucket size).
6. Stop.

Department of Computer Science and Engineering Page 41


Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

Sample Input and Output:

Department of Computer Science and Engineering Page 42


Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

Result:

The program has been executed successfully and the output is obtained and verified.

Department of Computer Science and Engineering Page 43


Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

Exp No. 9
UNDERSTANDING THE WIRESHARK TOOL
AIM
To understand the packet capturing tool called WireShark.
Description

WIRESHARK
A packet sniffer also known as packet analyzer or a network analyzer or protocol analyzer
is a computer program or a piece of computer hardware that can intercept and log traffic passing
over a digital network or part of a network. As data streams flow across the network, the sniffer
captures each packet and, if needed, decodes the packet's raw data, showing the values of various
fields in the packet, and analyzes its content according to the appropriate specification.Packet
capture is the process of intercepting and logging traffic.
Wireshark is a free and open-source packet analyzer. It is used for network
troubleshooting, analysis, software and communications protocol development, and education.
A network packet analyzer will try to capture network packets and tries to display that packet
data as detailed as possible. A network packet analyzer can be considered as a measuring device
used to examine what's going on inside a network cable, just like a voltmeter is used by an
electrician to examine what's going on inside an electric cable. In the past, such tools were either
very expensive, proprietary, or both. However, with the advent of Wireshark, all that has
changed. Wireshark is perhaps one of the best open source packet analyzers available today.
Originally named Ethereal, in May 2006 the project was renamed Wireshark. Wireshark is cross-
platform, using the GTK+ widget toolkit to implement its user interface, and using pcap to
capture packets.It runs on various Unix-like operating systems including Linux, OS X, BSD, and
Solaris, and on Microsoft Windows.

PURPOSES
The main purposes of Wireshark are:
⮚ Network administrators use it to troubleshoot network problems
⮚ Network security engineers use it to examine security problems
⮚ Developers use it to debug protocol implementations
⮚ People use it to learn network protocol internals

Department of Computer Science and Engineering Page 44


Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

FEATURES
The following are some of the many features Wireshark provides:
⮚ It works in promiscuous and non-promiscuous mode.
⮚ Promiscuous mode allows to see all the packets that the interface can see,even those
destined for other machines.
⮚ Non promiscuous mode captures only; allows to see packets destined for your machine,
which includes broadcast packets and multicast packets if your machine is part of a
multicast group.
⮚ Live data can be read from a number of types of network, including Ethernet, IEEE
802.11, PPP,and loopback.
⮚ Data display can be refined using a display filter.
⮚ Available for UNIX and Windows.
⮚ Capture live packet data from a network interface.
⮚ Display packets with very detailed protocol information.
⮚ Filter and Search packets on many criteria. Colorize packet display based on filters.

Department of Computer Science and Engineering Page 45


Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

WIRESHARK INTERFACES
Menu
The Wireshark menu sits on top of the Wireshark window

File
This menu contains items to open and merge capture files,save/print/export capture files
in whole or in part,and to quit from Wireshark.
File Set > List Files : To show a list of files in a file set. ox .
File Set > Next File : If the currently loaded file is part of a file set, jump to the next file in the
set. If it isn't part of a file set or just the last file in that set, this item is greyed out.
File Set > Previous File : If the currently loaded file is part of a file set, jump to the previous
file in the set. If it isn't part of a file set or just the first file in that set, this item is greyed out.
Export > File : To export all (or some) of the packets in the capture file to file.
Export > Selected Packet Bytes : To export the currently selected bytes in the packet bytes pane
to a binary file.
Print : To print all (or some) of the packets in the capture file.
Quit : To quit from Wireshark.

Department of Computer Science and Engineering Page 46


Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

Edit

This menu contains items to find a packet, time reference or mark one or more packets,
handle configuration profiles, and set your preferences.
Copy > Description : To copy the description of the selected item in the detail view to the
clipboard.
Copy > Fieldname : To copy the fieldname of the selected item in the detail view to the
clipboard.
Copy > Value : To copy the value of the selected item in the detail view to the clipboard.
Copy > As Filter : To use the selected item in the detail view to create a display filter.
Find Packet : To allows you to find a packet by many criteria.
Find Next : This menu item tries to find the next packet matching the settings from "Find
Packet..."
Find Previous : To find the previous packet matching the settings from "Find Packet..."
Mark Packet (toggle) : This menu item "marks" the currently selected packet.
Unmark All Displayed Packets : This menu item "unmarks" all displayed packets.
Find Next Mark : Find the next marked packet.
Find Previous Mark : Find the previous marked packet.
View
This menu controls the display of the captured data, including colorization of packets,
zooming the font, showing a packet in a separate window, expanding and collapsing trees in
packet details.
Department of Computer Science and Engineering Page 47
Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

Go
This menu contains items to go to a specific packet.
Capture
This menu allows you to start and stop captures and to edit capture filters
Interfaces... This menu item brings up a dialog box that shows what's going on at the
network interfaces Wireshark knows of.
Analyze
This menu contains items to manipulate display filters, enable or disable the dissection
of
protocols, configure user specified decodes and follow a TCP stream.
Display Filters : This menu item brings up a dialog box that allows you to create and edit display
filters.
Telephony
This menu contains items to display various telephony related statistic windows,
including a media analysis, flow diagrams, display protocol hierarchy statistics and much more.
Statistics
This menu contains items to display various statistic windows, including a summary of
the packets that have been captured, display protocol hierarchy statistics and much more.
Tools
This menu contains various tools available in Wireshark, such as creating Firewall ACL
Rules.
Internals
This menu contains items that show information about the internals of Wireshark.
Help
This menu contains items to help the user, e.g. access to some basic help, manual pages
of the various command line tools, online access to some of the web pages, and the usual about
dialog.

a) Using Wireshark, Capture packets transferred while browsing a selected website.


Investigate the protocols used in each packet, the values of the header fields and the size
of the packet.

AIM: To investigate the protocols used in each packet, the values of the header fields and the
size of the packet.

Department of Computer Science and Engineering Page 48


Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

b. To use Wireshark to observe Three Way Handshaking Connection Establishment,


Data Transfer and Three Way Handshaking Connection Termination in client server
communication using TCP

AIM: To observe Three Way Handshaking Connection Establishment, Data Transfer and Three
Way Handshaking Connection Termination in client server communication using TCP.

Theory:

Assume that both host (A) and server (B) side start from CLOSED status.

1. The server process create a TCB and use TCB prepares to accept the host's request.
After TCB born the server change status to LISTEN.

Department of Computer Science and Engineering Page 49


Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

2. The host does the same thing, create a TCB and use this TCB to send request, set the "SYN=1"
in the request header, and initates a arbitrary sequence number, seq=x. SYN paccket (which
means SYN=1) can not take any data content, but it will consume a sequence number. After
request sent, the host goes into SYN-SENT status.

3. After receiving the host's request:

● i. If the server accept to this connection, it will send back a confirm response. In the
response both SYN and ACK bits should be '1', and server side also initiates a SEQ
number, seq=y. The server will send its sequence number within packet which is used to
be acknowledged to the clinet's SYN packet. This packet can not take any data content
either, but it consumes a sequence number. So in this packet seq=y, ack=x+1. And the
server goes into SYN-RCVD status.
● ii. If the server rejects the connection, it just responses a RST packet to reset the
connection.

4. After the host received the server's response, it will send back also a confirm packet with ACK
bit sets to '1' and seq=x+1, ack=y+1.

After that, both side gose into ESTABLISHED status. This is what we called three-way
handshake.

Output:

Department of Computer Science and Engineering Page 50


Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

c. Explore at least the following features of Wireshark: filters, Flow graphs (TCP),
statistics, and protocol hierarchies.

AIM: To explore filters, Flow graphs (TCP), statistics, and protocol hierarchies

Applied the Filter TCP

Flow graphs (TCP)

Department of Computer Science and Engineering Page 51


Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

Applied Flow graph on TCP Flows

Statistics

Department of Computer Science and Engineering Page 52


Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

Protocol hierarchies

Result:
Explored wireshark tool and its features.

Department of Computer Science and Engineering Page 53


Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

Exp No. 10
CONFIGURING A NETWORK

Design and configure a network (wired and wireless LANs) with multiple subnets using
required network devices.Configure at least three of the following services in the network-
TELNET, SSH, FTP server, Web server, File server, DHCP server and DNS server

a. Design and configure a network (wired and wireless LANs) with multiple subnets
using required network devices

In this network there is 7 wired subnets and a wireless network.

For serial links only 2 ip addresses are required so we can use /30 as subnet mask ie,
255.255.255.252 is subnet mask. Each new subnets will be multiples of 4.so
192.168.10.0/30 (exacluding base network) , the subnetwork addresses are ,
192.168.10.4/30
192.168.10.8/30
192.168.10.12/30, for addressing the 3 serial links.
Then for 10 and 12 host need 4 bits in host part/28 or 255.255.255.240 is new subnet mask ,
with this subnetmask we can create the 2 subnets,
192.168.10.16/28
192.168.10.32/28 for the subnets.
For next 18 hosts and 28 hosts need 5 bits in host part and remaining 3 bits can be borrowed to
network part and the new subnet mask is 255.255.255.227 or /27
For the last 28 hosts the new subnet address is
192.168.10.64/27
192.168.10.96/27.

Then for the wireless network we can give the subnet mask as 192.168.10.128/26 and using
this subnet mask we can address 64 wireless devices.

Department of Computer Science and Engineering Page 54


Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

Thus by using VLSM , with the same network address we can address all the 7 subnets and a
wireless network.
b.Configure at least three of the following services in the network- TELNET, SSH, FTP
server, Web server, File server, DHCP server and DNS server

DHCP SERVER CONFIGURATION

DHCP is a network management protocol used in networks to dynamically assign IP addresses


and other network configuration information like default gateway, mask, DNS server address,
etc. It is an application layer protocol.

Step 1: First, open the cisco packet tracer desktop and select the devices and create a network
topology like this.

Step 2: Configure the Server with IPv4 address and Subnet Mask.
Parameters Address value

IPv4 Address 172.168.10.2

Subnet Mask 255.255.255.0

Default-Gateway 172.168.10.1

Department of Computer Science and Engineering Page 55


Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

Step 3: Configuring the DHCP server.


To configure the DHCP server first,
• Click on Server then, Go to services.
• Click on DHCP and turn on the services and, configure the DHCP server with the help of
the data given below.
• Delete the default values of Start IP Address and subnet Mask then save the info.
• Create two new pools.
POOL1 and POOL2 and fill the data as shown in the images below.

Department of Computer Science and Engineering Page 56


Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

Department of Computer Science and Engineering Page 57


Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

Step 4: Configuring Router with IPv4 Address and Subnet Mask.


IP Addressing Table for Router

S.NO Device Interface IPv4 Address Subnet Mask

FastEthernet0/0 172.168.10.1 255.255.255.0


router0
1. FastEthernet1/0 192.168.10.1 255.255.255.0

• To assign an IP address in router0, click on router0.


• Then, go to config and then Interfaces, and make sure to turn on the ports.
• Then, configure the IP address in FastEthernet according to IP addressing Table.
• Fill IPv4 address and subnet mask.

Department of Computer Science and Engineering Page 58


Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

Step 5: Configuring the PCs and changing the IP configuration.


• To assign an IP address in PC0, click on PC0.
• Then, go to desktop and IP configuration and there you will find IPv4 configuration.
• Change its state from static to DHCP.
• It will automatically fetch the data and configure itself.

Department of Computer Science and Engineering Page 59


Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

• Repeat the same procedure with other PCs to configure them thoroughly.

The final output will be like this.

Department of Computer Science and Engineering Page 60


Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

FILE TRANSFER PROTOCOL SERVER CONFIGURATION


we are going to design a file transfer protocol server configuration in cisco packet tracer and
checking the connectivity for uploading and downloading the file from remote PC.
Objectives:
• To Configure FTP Services on Server.
• To Upload a File into the FTP Server from Remote PC.
• To Download a File from the FTP Server from Remote PC.

Initially design a network topology like this.

Step-1: (Configuring Router0):


IP address IP Address Subnet
Subnet Mask
FastEthernet0/0 FastEthernet1/0 Mask

192.168.1.1 255.255.255.0 10.0.0.1 255.0.0 0

1. Select a 2911 Router from Network Devices and drag and drop to the workspace.
2. Select Router0 and Go to Config.
3. Configure the FastEthernet0/0by assigning IP address as 192.168.1.1 and subnet mask as
255.255.255.0 and turn on the port status
4. Configure the FastEthernet1/0by assigning IP address as 10.0.0.1 and subnet mask as
255.0.0.0 and turn on the port status.

Department of Computer Science and Engineering Page 61


Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

Department of Computer Science and Engineering Page 62


Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

Step-2: (Configuring PCs):

Device Name IP address Subnet Mask Default Gateway

PC 0 192.168.1.2 255.255.255.0 192.168.1.1

PC 1 192.168.1.3 255.255.255.0 192.168.1.1

Pc0

Department of Computer Science and Engineering Page 63


Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

Department of Computer Science and Engineering Page 64


Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

Step-3: (Configuring Server0):


1. Select a server from End devices and drag and drop to the workspace.
2. Go to the global settings in config and assign default gateway as 10.0.0.1
3. Go to FastEthernet0 and assign IP address and subnet mask as 10.0.0.2, 255.0.0.0
4. Go to services and open FTP Service.
5. Go to user setup and create a username and password.
6. Select all the permissions (Write, Read, Delete, Rename, List) and add the user.

Department of Computer Science and Engineering Page 65


Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

Checking connections from PC1 to the other hosts in the network using ping Command in
Command Prompt.

Department of Computer Science and Engineering Page 66


Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

Creating a file named “ftpupload” for writing(uploading) into FTP Server.

Department of Computer Science and Engineering Page 67


Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

Writing(uploading) the file named 2.txt into FTP Server from PC0 using put 2.txt command
and verifying this file transfer using dir command.

Department of Computer Science and Engineering Page 68


Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

Reading(Downloading) the file named 2.txt present in FTP Server from PC1 using get 2.txt
command and verifying this file transfer using dir command.

Department of Computer Science and Engineering Page 69


Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

DNS SERVER CONFIGURATION

A Domain Name System (DNS) server resolves host names into IP addresses.

1.Build the network topology.

2.Configure static IP addresses on the PCs and the server.


Server

IP address: 192.168.1.2 Subnet mask: 255.255.255.0 Default gateway: 192.168.1.1 DNS


Server: 192.168.1.2

Department of Computer Science and Engineering Page 70


Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

PC0

IP add: 192.168.1.3 Subnet mask: 255.255.255.0 Default gateway: 192.168.1.1 DNS


server: 192.168.1.2

Department of Computer Science and Engineering Page 71


Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

PC1

IP address: 192.168.1.4 Subnet mask: 255.255.255.0 Default


gateway: 192.168.1.1 DNS Server: 192.168.1.2

Department of Computer Science and Engineering Page 72


Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

3.Configure DNS service on the generic server.

To do this, click on the server, then Click on Services tab. Click on DNS server from the
menu. First turn ON the DNS service, then define names of the hosts and their
corresponding IP addresses

Name: PC0 Address: 192.168.1.3

Click on add then save. Repeat this for the PC1 and the server.

Department of Computer Science and Engineering Page 73


Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

Finally,

4. Test domain name – IP resolution. Ping the hosts from one another using their names
instead of their IP addresses. If the DNS service is turned on and all IP configurations are okay,
then ping should work.

For example, ping PC1 from PC0. Ping should be successful.

Department of Computer Science and Engineering Page 74


Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

Result:

Explored design and configuration of networks and how to configure commonly used services
in the network
.

Department of Computer Science and Engineering Page 75


Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

Exp No. 11
STUDY OF NS2 SIMULATOR

AIM: To study NS2 simulator


THEORY:
Introduction to Network Simulator-Version 2 (NS2):
NS2 is simply an event-driven simulation tool that has proved useful in studying the dynamic
nature of communication networks. Simulation of wired as well as wireless network functions
and protocols (e.g., routing algorithms, TCP, UDP) can be done using NS2.
Basic Architecture
NS2 consists of two key languages: C++ and Object-oriented Tool Command
Language (OTcl). While the C++ defines the internal mechanism (i.e., a backend)
of the simulation, the OTcl sets up simulation by assembling and configuring the
objects as well as scheduling discrete events (i.e., a frontend). The C++ and the
OTcl are linked together using TclCL.

Zlib : This is the required library for NAM.


Xgraph: This is a data plotter with interactive buttons for panning,zooming, printing, and
selecting display options.
NAM ( Network Animator): NAM is a TCL-based animation tool for viewing network
simulation traces and real traces of packet data. To use NAM, first generate a trace file that
contains topological information like nodes, links and packet traces. Once the trace file is
generated, NAM will read it, create a topology, pop up a window, do the layout if necessary,
and then pause at the time of the first packet is in the trace file. NAM provides control over
many aspects of animation through its user interface, and does animation using the following
building blocks: node, link, queue, packet, agent and monitor.

Department of Computer Science and Engineering Page 76


Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

NAM Animator screen

Traced file content


Installing NS2 Simulator
Open the terminal in a linux machine and type the following comments
For Ubuntu 20.04
sudo apt update
sudo apt get install ns2
sudo apt get install nam

Running NS2 Simulation


To execute the file open a terminal and type ns filename(ex: ns hello.tcl)

a) The network consists of TCP source node (n0) and destination node (n1) over an area
size of 500m x 500m. Node (n0) uses Agent/TCP/Reno as the sending TCP agent and FTP
traffic source. Node (n1) is the receiver of FTP transfers, and it uses Agent/TCP sink as

Department of Computer Science and Engineering Page 77


Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

its TCP-agent for the connection establishment. Run the simulation for 150 seconds and
show the TCP window size in two static nodes scenario with any dynamic routing
protocol. Run the script and analyze the output graph for the given scenario.
Simple two node wired network(TCP Connection)

Output:
Figure1:

Sending
TCP Packet

Receiving acknowledgment

b. Simulate the transmission of ping messages over a star network topology consisting of
‘n’ nodes and find the number of packets dropped due to congestion using NS2simulator
Description:
The network for this experiment uses six nodes n0 to n5. In this scenario, node n1 sends
constant bit-rate (CBR) traffic to node n5 using UDP agent. The UDP traffic travels
through n2 and n3 before reaching n5. Both n0 and n4 node sends ping message at
certain time intervals. Ping messages are dropped from the network when the traffic
through node n2 and n3 is full.

Department of Computer Science and Engineering Page 78


Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

Output

c) Simulate Link State Protocol in NS2


Description:
The first step is to initialize the network simulator, by creating a network simulator object.
After that, initialize rtproto (routing protocol) to Link State (LS).
Output:

In the output obtained there is a normal flow of packets from node 1 to node 4. We now
disable the link between nodes 2 and 3 at time 1 and the simulations changes as shown
below. The disabled link is shown in red and the packet flow this time changes direction
rather than the original route to node 4

Department of Computer Science and Engineering Page 79


Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

Result :
Simulated NS2 .

Department of Computer Science and Engineering Page 80


Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

ADDITIONAL
&
OPEN ENDED EXPERIMENTS

Department of Computer Science and Engineering Page 81


Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

Exp No. 12
ADDITIONAL EXPERIMENT
a. Implement TCP bidirectional communication between client and server
Note: Input a string at client, Server to reverse the string, Reversed string to be displayed at
client.

AIM:
To connect server and client using TCP socket and to exchange messages.

ALGORITHM:

Server
1. Create a socket with the socket() system call.
2. Initialize the socket address structure and bind the socket to an address using the bind()
system call.
3. Listen for connections with the listen() system call.
4. Accept a connection with the accept() system call. This call typically blocks until a client
connects to the server.
5. Receive and send data by using recv() and send().
6. Close the connection by using the close().

Client
1. Create a socket with the socket() system call.
2. Initialize the socket address structure as per the server and connect the socket to the
address of the server using the connect() system call.
3. Receive and send the data using the recv() and send().
4. Close the connection by calling the close() function.

Sample Input and Output:


Server

Client

Result:

The program has been executed successfully and the output is obtained and verified.

Department of Computer Science and Engineering Page 82


Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

Exp No. 13
OPEN ENDED EXPERIMENT
CONCURRENT FILE SERVER

AIM:-
To develop a concurrent file server which will provide the file requested by client if it
exists. Ifnot, server sends appropriate message to the client. Serversends its process ID
(PID) to clients fordisplayalongwith fileorthe message.

Description:

The file server creates listening sockets on two ports that have consecutive port numbers.
One is thelistening socket for control connection and the other is the listening socket for data
connection. Thesesockets have descriptors listen_controland listen_datarespectively. The
client creates a socket andconnects to the server using TCP connection.The client socket
descriptor is stored in sock_ctrl. Theserver creates a connection socket when the client makes
a TCP connection with the server. Thisconnection socket is stored in sock_ctrl. This
connection is for control information to pass betweenclient and server. Next, the server forks
a child process. Since the child is a perfect image of its parent,the child process will also
have descriptorslisten_control, listen_dataand sock_ctrl. The controlconnection will also be
duplicated between the client and the child process. The child process closes its listening
socket for control connection, i.e; listen_control. The parent server process closes its
connection socket for the control connection i.e; sock_ctrl. The client now makes a TCP
connection with the server for transferring data is stored in sock_data.The connection socket
for the data connectionis stored insock_datain theserver child process.

Algorithm

Client
1. Create the client TCP control connection to a port (port_num) of the server with
the client socket descriptor sock_ctrl.
2. while(1)
2.1 Create client socket descriptor sock_data for the data connection with server on
another port (portnum + 1). For each file transfer a new data connection is required.
2.2 Read the command from the terminal given by the user
2.3 Send the command to the server using control socket sock_ctrl.
2.4 If command == “close”
close sock_data and sock_ctrl
break
else
Enter the filename using the keyboard
Write the filename using control socket sock_ctrl to the server.
2.5 Use connect() for the data connection.

Department of Computer Science and Engineering Page 83


Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

2.6 read data using sock_data (file contents) from the server and write to the file
If file does not exist print the process id of server

Server
1. Initialize variable file_present to 1
2. Create listening socket for the control connection on port (port_num) and store it
in listen_control.
3. Create a listening socket for the data connection on port (port_num +1) and store
it in listen_data
4. while (1)
4.1 accepts the client control connection and returns the connect socket descriptor
sock_ctrl
4.2 fork a child process
if(childprocess)
close listening socket listen_control
4.2.1 while(1)
4.2.1.1 read command from the client on the control connection
if command == “close”
break
else
open the file
if (no file)
form a string “@FILE NOT FOUND PROCESS ID =
getprocess id” and store it in variable buffer
file_present = 0;
4.2.1.2 accept the data connection and return the socket descriptor
sock_data
4.2.1.3 if(file_present)
read file contents and write to sock_data
form a string “FILE filename RECEIVED FROM
SERVER WITH PROCESS ID = getprocess id” and store
it in variable buffer
else
write buffer using sock_data to the client
file_present = 1;
4.2.2 close all socket-descriptors.
child process exits

Sample Input and Output:

Department of Computer Science and Engineering Page 84


Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

Result:

The program hasbeen executed successfully and the output is obtained and verified.

Department of Computer Science and Engineering Page 85


Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

APPENDIX I: VIVA QUESTIONS

1. What is a socket?
A socket is used to connect an application to a network protocol. A socket enables
communication between a client and a server. The communication is started when the client
is assigned a local port number, and binds a socket to it. The client writes on the socket and
gets information from server by reading it.

2. Compare datagram and stream.


Stream can be considered as a pipe that allows full duplex connection. A datagram or a packet
on the other hand, has a source and a destination. There is no connection. Stream is like a
communication channel while datagram is completely self contained. Streams provide a
reliable and sequenced communication. Datagram’s on the other hand are unreliable and no
sequence maintained.

3. What is a stream socket?


A stream socket provides two way communications between a client and server. This
communication is reliable and sequenced. Stream sockets are above TCP to run across any
networks. They provide unduplicated flow of data and have well established mechanism for
creating and destroying connections and for detecting errors.

4. Define Broadcast, Unicast and Multicast.


Unicast: A term used in communication to describe a piece of information to send from one
point to another. There are only sender and receiver. All LANs support unicast transfer mode
and most applications that employ TCP transport protocol uses unicast messaging.
Broadcast: A term used for describing communication that is sent a piece of information
from one point to all other points. There is one sender and multiple receivers. All LANs
support broadcast transmission.
Multicast: A term described in communicating a piece of information sent from one or more
points to a set of other points. The senders and receivers are one or more.

5. Explain the classes of IP address


IP addresses are organized into classes. For convenience of humans, IP addresses are
expressed in the decimal format. Every number in each class is represented as binary to
computers.The four numbers in an IP address are known as ‘octets’. Each of them has eight
bit positions. The octets are divided into two sections: Net and Host. The first octet represents
Net for identifying the network and the Host contains the last octet. There are five IP classes.
Class A: The class A is used for very large networks. There are 1 to 126 are part of this class.
That means there are 126 Class A networks. Class A networks accounts for half of the total
available IP addresses.
Class B: It is used for medium size networks. The IP address with a first octet from 128 to
191 is part of this class. Class B networks have a first bit value of 1 and a second bit value of
0 in the first octet.
Class C: Class C is used for small to middle size networks. IP address with a first octet starts
from 102-223. Class C networks have a first bit value of 1, second bit value of 1 and a third
bit value of 0 in the first octet.

Department of Computer Science and Engineering Page 86


Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

Class D: It has first, second and third bit value as 1 and the fourth bit as 0. The other 28 bits
are used for identifying the group of computers which is intended for multicast messages.
Class E: Class E is used for identification purpose. The four bits value is 1. The other 28 bits
are used for identifying the group of computers which is intended for multicast messages

6. What is the User Datagram Protocol (UDP)?


User datagram protocol allows computer applications to send messages as datagram packets
from source to destination on an Internet Protocol, without using prior communications for
setting up special transmission paths. An unreliable service is provided by UDP which makes
the datagram packets may arrive irrespective of order. UDP is a better solution for time-
sensitive applications due to the reason ‘dropping packets is preferable to use delayed
packets’. Its stateless nature makes the server to answer smaller queries to huge number of
clients.

7. What is TCP / IP protocol?


Transmission Control Protocol / Internet Protocol: - It is a family of protocols used for
communication and connection between hosts on the internet. It is the most widely used
standard for transmitting data over the internet. The four layers in the protocol are (from
bottom to top):- Physical layer, Data link layer, Network layer, transport layer and application
layer, also called as the OSI model. In TCP/IP, IP is responsible for forwarding packets while
TCP ensures the correct delivery of data from client to server. TCP detects loss of data as
well.

8. Define the term Protocol.


Protocol is a standard way of communicating across a network. A protocol is the "language"
of the network. It is a method by which two dissimilar systems can communicate. TCP is a
protocol which runs over a network

9. Compare TCP vs. UDP.


TCP guarantees the delivery of data. UDP on the other hand, does not guarantee delivery of
data. TCP delivers messages in the order they were sent. UDP has no ordering mechanisms.
In TCP data is sent as a stream while UDP sends data as individual packets. UDP is faster
than TCP. TCP is a connection oriented protocol while UDP is connectionless.

10. Explain the concept of DHCP.


Dynamic Host Configuration Protocol is used assigning IP addresses to computers in a
network. The IP addresses are assigned dynamically. Certainly, using DHCP, the computer
will have a different IP address every time it is connected to the network. In some cases the
IP address may change even when the computer is in network. This means that DHCP leases
out the IP address to the computer for sometime. Clear advantage of DHCP is that the software
can be used to manage IP address rather than the administrator.

11. What are Ping and Tracert?


Ping and tracert are the commands used to send information to some remote computers to
receive some information. Information is sent and received by packets. Ping I particularly
used to check if the system is in network or not. It also gives packet lost information. In
windows ping command is written as ping ip_addressTracert is called as trace route. It is used

Department of Computer Science and Engineering Page 87


Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

to track or trace the path the packet takes from the computer where the command is given
until the destination. In windows ping command is written as tracertip_address

12. What is firewall?


A firewall is a hardware or software installed to provide security to the private networks
connected to the internet. They can be implemented in both hardware and software, or a
combination of both. All data entering or leaving the Intranet passes through the firewall
which allows only the data meeting the administrators’ rules to pass through it.

13. Define File Transfer Protocol.


File Transfer Protocol (FTP), a standard Internet protocol, is the simplest way to exchange
files between computers on the Internet. Like the Hypertext Transfer Protocol (HTTP), which
transfers displayable Web pages and related files, and the Simple Mail Transfer Protocol
(SMTP), which transfers e-mail, FTP is an application protocol that uses the Internet's TCP/IP
protocols. FTP is commonly used to transfer Web page files from their creator to the computer
that acts as their server for everyone on the Internet. It's also commonly used to download
programs and other files to your computer from other servers.

14. What is UDP?


UDP (User Datagram Protocol), like TCP, is a general-purpose communications protocol for
inter-process and inter-computer communications that runs on top of IP (Internet Protocol).
The details of TCP and UDP are quite different, however. One difference between TCP and
UDP is that TCP has more hand-shaking and error checking built into the protocol, and a
guarantee that data packets arrive in the correct order. Another difference is that instead of
starting the communications process by negotiating to open a socket directly between two
processes as in TCP, in UDP one process simply starts sending to a particular port at a
particular IP address, while another one begins receiving, and thus communication is
established. There is also some terminology that is different between the two protocols: TCP
sends "packets" through its sockets, and UDP sends "datagrams" or "datagram packets".

15. What is IP Multicast?


IP Multicast is a protocol that uses UDP for efficient broadcast of messages to multiple
receiving applications on multiple hosts. The broadcasting application sends its messages to
an IP address in a particular reserved range, and applications on other computers on the same
network listen to the same port on the same address to receive the message. In between,
assuming that both the sending and receiving computers, as well as the network, have IP
Multicasting installed, an efficient mechanism is used to send minimal copies of the message
through the network. Note that the "message" sent can be any type of data -- it doesn't have
to be text.

16. What do you mean by data communication?


It is the exchange of data between two devices via some form of transmission medium such
as wire cable. The communicating system must be part of a communication system made up
of a combination of hardware and software.The effectiveness of a data communication system
depends on three fundamental characteristics: delivery, accuracy and timeliness.

Department of Computer Science and Engineering Page 88


Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

17. What is a network?


It is a set of devices connected by communication links. A node can be a computer or any
other device capable of sending and/or receiving data generated by other nodes on the
network.

18. What is distributed processing?


It is a strategy in which services provided by the network reside at multiple sites.

19. What is point to point connection?


It provides a dedicated link between two devices. The entire capacity of the link is reserved
for transmission between the two devices e.g. when we change the TV channels by remote
control we establish a point to point connection between remote control and TV control
system.

20. What is multipoint connection?


In multipoint connection more than two specific devices share a single link.
Here the capacity of the channel is shared either separately or temporally.

21. What is a topology?


Topology of a network is defined as the geometric representation of the relationship of all the
links and linking devices (node) to one another.Four basic topologies are star, bus, ring and
mesh.
Star – Here each device has a dedicated point to point link only to a central controller called
hub.
Bus -It is multipoint. One long cable acts as a backbone to link all the devices in the network.
Ring -Here each device has a dedicated point to point connection only with the two devices
on either side of it.
Mesh -Here every device has a dedicated point to point link to every other device.

22. Define LAN, MAN and WAN.


LAN- A local area network (LAN) is a privately owned and links the devices in a single
office, building or campus. It allows resources to be shared between personal computers and
work stations.
MAN- A metropolitan-area network (MAN) spreads over an entire city.
It may be wholly owned and operated by a private company, eg local telephone company.
WAN – A wide area network (WAN) provides long distance transmission of data, voice,
image and video information over large geographic areas that comprise a country, a continent
or even whole world.

23. Define internet?


It is a network of networks.

24. What is a protocol?


It is a set of rules that governs data communication. A protocol defines what is communicated,
how it is communicated, and when it is communicated. The key elements of protocol are
syntax, semantics and timing.

Department of Computer Science and Engineering Page 89


Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

25. What is TCP/IP protocol model?


It is a five layered model which provides guidelines for the development of universally
compatible networking protocols. The five layers are physical, data link, network, transport
and application.

26. Describe the functions of five layers?


Physical- It transmits raw bits over a medium. It provides mechanical and electrical
specification.
Data link- It organizes bits into frames. It provides hop to hop delivery.
Network-It moves the packets from source to destination.It provide internetworking.
Transport-It provides reliable process to process message delivery and error recovery.
Application-It allows ti access to network resources.

27. What is ISO-OSI model?


Open Systems Interconnection or OSI model was designed by the International Organization
for Standardization (ISO) .It is a seven layer model. It is a theoretical model designed to show
how a protocol stack should be implemented. It defines two extra layers in addition to TCP/IP
model.
Session -It was designed to establish, maintain, and synchronize the interaction between
communicating system.
Presentation-It was designed to handle the syntax and semantics of the information exchanged
between the two systems. It was designed for data translation, encryption, decryption, and
compression.
28. What is multiplexing?
Multiplexing is the process of dividing a link, the phycal medium, into logical channels for
better efficiency. Here medium is not changed but it has several channels instead of one.

29. What are the different transmission media?


The transmission media is broadly categorized into two types
i)Guided media(wired)
ii)Unguided media(wireless)

30. What are the different Guided Media?


The media which provides a conduct from one device to another is called a guided media.
These include twisted pair cable, coaxial cable, and fiber-optic cable.

31. Describe about the different Guided Medias.


Twisted pair cable consists of two insulated cupper wires twisted together. It is used in
telephone line for voice and data communications.
Coaxial cable has the following layers: a metallic rod-shaped inner conductor, an insulator
covering the rod, a metallic outer conductor (shield), an insulator covering the shield, and a
plastic cover.Coaxial cable can carry signals of higher frequency ranges than twisted-pair
cable. Coaxial cable is used in cable TV networks and Ethernet LANs.Fiber-optic cables are
composed of a glass or plastic inner core surrounded by cladding, all encased in an outer
jacket.Fiber-optic cables carry data signals in the form of light. The signal is propagated along
the inner core by reflection. Its features are noise resistance, low attenuation, and high
bandwidth capabilities. It is used in backbone networks, cable TV nerworks, and fast Ethernet
networks.
Department of Computer Science and Engineering Page 90
Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

32. What do you mean by wireless communication?


Unguided media transport electromagnetic waves without using a physical conductor. This
type of communication is referred as wireless communication. Here signals are broadcaster
through air and thus available to anyone who has a device to receive it.

33. What do you mean by switching?


It is a method in which communication devices are connected to one another efficiently.
A switch is intermediary hardware or software that links devices together temporarily.
34.
35. What are the switching methods?
There are three fundamental switching methods: circuit switching, packet switching,
And message switching.In circuit switching, a direct physical connection between two
devices is created by space division switches, time division switches or both. In packet
switching data is transmitted using a packet switched network. Packet switched network is a
network in which data are transmitted in independent units called packets.

36. What are the duties of data link layer?


Data link layer is responsible for carrying packets from one hop (computer or router) to the
next. The duties of data link layer include packetizing, adderssing, error control, flow control,
medium access control..

37. Define cyclic redundancy check (CRC).


CRC appends a sequence of redundant bits derived from binary division to the data unit. The
divisor in the CRC generator is often represented as an algebraic polynomial.

38. What do you mean by flow control?


It is the regulation of sender’s data rate so that the receiver buffer doesn’t become
overwhelmed.i.e. flow control refers to a set of procedures used to restrict the amount of data
that the sender can send before waiting for acknowledgement.

39. What do you mean by error control?


Error control refers primarily to methods of error detection and retransmission. Anytime an
error is detected in an exchange, specified frames are retransmitted. This process is called
automatic repeat request (ARQ).

40. What do you mean by point to point protocol?


The point to point protocol was designed to provide a dedicated line for users who need
internet access via a telephone line or a cable TV connection. Its connection goes through
three phases: idle, establishing, authenticating, networking and terminating.

41. What do you mean by point to point protocol stack?


Point to point protocol uses a stack of other protocol to use the link, to authenticate the parties
involved, and to carry the network layer data. Three sets of protocols are defined: link control
protocol, Authentication protocol, and network control protocol.

Department of Computer Science and Engineering Page 91


Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

42. What do you mean by CSMA?


To reduce the possibility of collision CSMA method was developed. In CSMA each station
first listen to the medium (Or check the state of the medium) before sending. It can’t eliminate
collision.

43. What do you mean by Bluetooth?


It is a wireless LAN technology designed to connect devices of different functions such as
telephones, notebooks, computers, cameras, printers and so on. Bluetooth LAN Is an adhoc
network that is the network is formed spontaneously? It is the implementation of protocol
defined by the IEEE 802.15 standard.

44. What is IP address?


The internet address (IP address) is 32bits that uniquely and universally defines a host or
router on the internet. The portion of the IP address that identifies the network is called netid.
The portion of the IP address that identifies the host or router on the network is called hostid.

45. What do you mean by subnetting?


Subnetting divides one large network into several smaller ones. It adds an intermediate level
of hierarchy in IP addressing.

46. What are the advantages of fiber optics cable ?


The advantages of fiber optics cable over twisted pair cable are Noise resistance-As they use
light so external noise is not a factor. Less signal attenuation-fiber optics transmission distance
is significantly greater than that of other guided media.Higher bandwidth-It can support
higher bandwidth.

47. What are the disadvantages of fiber optics cable?


The disadvantages of fiber optics cable over twisted pair cable are Cost-It is expensive
Installation/maintenance-Any roughness or cracking defuses light and alters the signal
Fragility-It is more fragile.

48. What is a Firewall?


It is an electronic downbridge which is used to enhance the security of a network. It’s
configuration has two components.i)Two routers ii)Application gateway. The packets
traveling through the LAN are inspected here and packets meeting certain criteria are
forwarded and others are dropped.

49. What is a Repeater?


A receiver receives a signal before it becomes too weak or corrupted,regenerates the original
bit pattern,and puts the refreshed copy back onto the link.It operates on phycal layer of OSI
model.

50. What is a Bridge?


They divide large network into smaller components.They can relay frames between two
originally separated LANs.They provide security through partitioning traffic.They operate on
phycal and data link layer of OSI model.

Department of Computer Science and Engineering Page 92


Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

51. What is a Router?


Ans: Router relay packets among multiple interconnected networks.They receive packet from
one connected network and pass it to another network.They have access to network layer
addresses and certain software that enables them to determine which path is best for
transmission among several paths.They operate on phycal,data link and network layer of OSI
model.

52. What is a Gateway ?


It is a protocol converter.A gateway can accept a packet formatted for one protocol and
convert it to a packet formatted for another protocol.It operates on all the seven layers of OSI
model.

53. What do you mean by protocol stack ?


The list of protocols used by certain system ,one protocol per layer is called protocol stack.

54. What do you mean by peer ?


Entities comprising the corresponding layers on different machines are called peers.It may
be
• hardware device.
• processes
• human beingpeers communicate by using protocol.

55. What do you mean by broadcasting ?


Broadcast system allow addressing a packet to all destination by using a special code in
address field.when packet is transmitted it is received and processed by every machine on the
network.

56. What are the advantages of broadcast network.


• a single communication channel is shared by all computers.
• packets are transmitted and received by all the computer.
• address field is attached to whom it is intended.
• multicasting is used in network.
57. What do you mean by point to point network?
Point to point network consist of many connections between individual pair of machines.large
networks are point to point.Routing algorithm plays an important in point to point network.It
uses stored ad forwordtechnique.It is a packet switching network.

58. What are the design issue of layers ?


The design issue of layer are
• Addressing technique.ie source and destination address
• Types of communication
• Error control
• Order of message.
• Speed matching
• Multiplexing and demultiplexing.

Department of Computer Science and Engineering Page 93


Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

59. What are the protocols in application layer ?


The protocols defined in application layer are
• TELNET
• FTP
• SMTP
• DNS

60. What are the protocols in transport layer ?


The protocols defined in transport layer are
i. TCP
ii. UDP

61. Define TCP ?


It is connection oriented protocol.It consist byte streams oeiginating on one machine to be
delivered without error on any other machine in the network.while transmitting it fragments
the stream to discrete messages and passes to internerlayer.At the destination it reassembles
the messages into output stream.

62. Define UDP ?


It is unreliable connectionless protocol.It is used for one-shot,client-server type,requesr-reply
queries and applications in which prompt delivery is required than accuracy.

63. Define IP ?
Internetwork protocol (IP) is the transmission mechanism used by TCP/IP protocol.It is an
unreliable and connectionless datagram protocol.It provides no error checking and tracking.

64. What do you mean by client server model ?


In client server model ,the client runs a program to request a service and the server runs a
program to provide the service.These two programs communicate with each other. One server
program can provide services to many client programs.

65. What are the information that a PC attached to a TCP/IP internet must
possesses ?
Each computer attached to TCP/IP must possesses the following information
• Its IP addesss
• Its subnet mask
• The IP addesss of the router.
• The Ip address of the name server.

66. What is domain name system(DNS)?


Domain Name System (DNS )is a client server application that identifies each host on the
internet with a unique user friendly name.

Department of Computer Science and Engineering Page 94


Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

67. What is TELNET ?


TELNET is a client –server application that allows a user to log on to a remote machine,giving
the user access to the remote system. TELNET is an abbreviation of terminal Network.

68. What do you mean by local login and remote login ?


When a user logs into a local time-sharing system ,it is called local login. When a user wants
to access an application program or utility located on a remote machine,he or she performs
remote login.

69. What is Network Virtual Terminal ?


A universal interface provided by TELNET is called Network Virtual Terminal(NVT)
character set.Via this interface TELNET translates characters (data or command) that come
from local terminal into NVT form and delivers them to the network.

70. What do you mean by Simple Mail Transfer Protocol ?


The TCP/IP protocol that supports electronic mail on the internet is called Simple Mail
Transfer Protocol.SMTP provides for mail exchange between users on the same or different
computer and supports Sending a single message to one or more recipient Sending message
that include text, voice,video,orgraphics.Sending message to users on network outside the
internet.

71. What is Hypertext Transfer Protocol(HTTP) ?


It is the main protocol used to access data on the World Wide Web .the protol transfers data
in the form of plain text,hypertext,audio,video,and so on. It is so called because its efficiency
allows its use in a hypertext environment where there are rapid jumps from one document to
another.

72. What is URL ?


It is a standard for specifying any kind of information on the World Wide Web.

73. What is World Wide Web ?


World Wide Web is a repository of information spread all over the world and linked
together.It is a unique combination of flexibility,portability,and user-friendly features .The
World Wide Web today is a distributed client-server service,in which a client using a browser
can access a service using a server.The service provided is distributed over many locations
called web sites.

74. What is HTML ?


Hypertext Markup Language (HTML) is a language for creating static web pages

75. What isFTP application layer protocols?


The File Transfer Protocol (FTP) is the standard mechanism provided by TCP / IP for copying
a file from one host to another. It uses the services offer by TCP and so is reliable and secure.
It establishes two connections (virtual circuits) between the hosts, one for data transfer and
another for control information.

Department of Computer Science and Engineering Page 95


Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

76. What is the difference between a hub and a switch?


A switch is effectively a higher-performance alternative to a hub. People tend to benefit from
a switch over a hub if their home network has four or more computers, or if they want to use
their home network for applications that generate significant amounts of network traffic, like
multiplayer games or heavy music file sharing. In most other cases, home net workers will
not notice an appreciable difference between a hub and switch (hubs do cost slightly less).
Technically speaking, hubs operate using a broadcast model and switches operate using a
virtual circuit model. When four computers are connected to a hub, for example, and two of
those computers communicate with each other, hubs simply pass through all network traffic
to each of the four computers.

Switches, on the other hand, are capable of determining the destination of each individual
traffic element (such as an Ethernet frame) and selectively forwarding data to the one
computer thatactually needs it. By generating less network traffic in delivering messages, a
switch performs better than a hub on busy networks.

77. What is a socket?


A socket is used to connect an application to a network protocol. A socket enables
communication between a client and a server. The communication is started when the client
is assigned a local port number, and binds a socket to it. The client writes on the socket and
gets information from server by reading it.

78 .Compare datagram and stream.


Stream can be considered as a pipe that allows full duplex connection. A datagram or a packet
on the other hand, has a source and a destination. There is no connection. Stream is like a
communication channel while datagram is completely self contained. Streams provide a
reliable and sequenced communication. Datagram’s on the other hand are unreliable and no
sequence maintained.

79. What is a stream socket?


A stream socket provides two way communications between a client and server. This
communication is reliable and sequenced. Stream sockets are above TCP to run across any
networks. They provide unduplicated flow of data and have well established mechanism for
creating and destroying connections and for detecting errors.

Department of Computer Science and Engineering Page 96


Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

80. Define Broadcast, Unicast and Multicast.

Unicast: A term used in communication to describe a piece of information to send from one
point to another. There are only sender and receiver. All LANs support unicast transfer mode
and most applications that employ TCP transport protocol uses unicast messaging.
Broadcast: A term used for describing communication that is sent a piece of information from
one point to all other points. There is one sender and multiple receivers. All LANs support
broadcast transmission.
Multicast: A term described in communicating a piece of information sent from one or more
points to a set of other points. The senders and receivers are one or more.

Department of Computer Science and Engineering Page 97


Toc H Institute of Science and Technology, Arakkunnam
CSL 332 Networking Lab, B. Tech CSE

REFERENCES

Reference Books:

1. W. Richard Stevens, Bill Fenner, Andy Rudoff, UNIX Network


Programming:Volume 1, The Sockets Networking API, 3rd Edition,
Pearson, 2015
2. Lisa Bock, Learn Wireshark: Confidently navigate the Wireshark interface and
solvereal-world networking problems, Packt Publishing, 2019
Teerawat Issariyakul, Ekram Hossain, Introduction to Network Simulator NS2,2ndEdition

Department of Computer Science and Engineering Page 98


Toc H Institute of Science and Technology, Arakkunnam

You might also like