NPS Instructor Manual
NPS Instructor Manual
V SEMESTER B.E
2020-2021
Dept. of CSE,RVCE 1
Network Programming and Security Lab Record -2020
Vision
Mission
Dept. of CSE,RVCE 2
Network Programming and Security Lab Record -2020
PROGRAM OUTCOMES:
Dept. of CSE,RVCE 3
Network Programming and Security Lab Record -2020
Course Outcomes: After completing the course, the students will be able to
1. Explore the functionalities of Socket APIs and a variety of network concepts.
3. Design and demonstrate client/server programs on Unix platforms to create robust real-
world sockets-based applications.
4. Apply appropriate cryptographic algorithms to ensure security of information through
wired and wireless medium.
CO-PO Mapping
CO/PO PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12
CO1 M M - - L L - M L L - -
CO2 M M - - M L L M L L - -
CO3 M M H H H M M H H M - L
CO4 M M H H H H H H H M - L
Course - PO Mapping
PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12
Course M M M M M M M M M M - L
CO –PSO Mapping
CO/PSO PSO1 PSO2
CO1 - M
CO2 L M
CO3 M H
CO4 M H
Dept. of CSE,RVCE 4
Network Programming and Security Lab Record -2020
Course Content
Course Code: 16CS63
Course Code: 18CS35
Hrs/WeekL-T-P: 4-0-1 CIE: 100+50 marks
Teaching Hours:39L + 35P SEE: 100+50 marks
UNIT-I Hours
1 Network layer - 1 07 Hrs
Network layer design issues, Store and Forward packet Switching,
ServicesProvided to the Transport Layer, Implementation of Connectionless
Service, Implementation of Connection-Oriented Service, Comparison of
Virtual Circuit and Datagram Subnets;
Routing algorithms:Shortest Path Routing, Flooding, Distance Vector
Routing,Link state Routing, Hierarchical Routing, Broadcast Routing,
Multicast Routing;
Congestion Control Algorithms: General Principles of Congestion
Control,Congestion Prevention Policies, Congestion Control in Virtual-
Circuit Subnets,Congestion Control in Datagram Subnets, Load Shedding,
Jitter Control;Quality Of Service: Requirements, Techniques for Achieving
Good Quality ofService; Integrated Services, Differentiated Services, RSVP
UNIT-II
2 Network layer - 2 : Internetworking: How networks differ, How networks 07Hrs
can be connected, Connectionless Internetworking, Tunnelling, Internetwork
Routing, Fragmentation,The Network Layer in the Internet : The IP Protocol,
IP Addresses, Internet Control Protocols, IPv6.
UNIT-III
3 Transport Layer :The Transport Service: Services provided to the Upper 08 Hrs
Layers, Transport Service Primitives; Elements of Transport Protocols:
Addressing, Connection Establishment, Connection Release, Flow Control
and Buffering;
The Internet Transport Protocols(UDP): Introduction to UDP; The Internet
Transport Protocols(TCP): Introduction to TCP, The TCP Service Model,
The TCP Protocol, The TCP Segment Header, TCP Connection
Establishment, TCP Connection Release, TCP Transmission Policy, TCP
Congestion Control.
Dept. of CSE,RVCE 5
Network Programming and Security Lab Record -2020
UNIT-IV
4 Application Layer – 1: Principles of Network Applications, The Web and 07 Hrs
HTTP, File Transfer: FTP, Electronic Mail in Internet, DNS- The Internet’s
Directory Service, Socket Programming: Creating Network Applications,
Network Management: SNMP
UNIT-V
5 Security in Network: What Is Network Security? Principles of 07 Hrs
Cryptography, Message Integrity and Digital Signatures, End-Point
Authentication, Securing EMail, Network-Layer Security.
Introduction to Working of SDN: Fundamental Characteristics of SDN,
SDN Operation, SDN Applications.
REFERENCE BOOKS:
W. Richard Stevens, Bill Fenner, Andrew M. Rudoff, UNIX Network Programming – The
sockets networking API, Vol.I , Third edition, PHI. ISBN-13: 978-0131411555 ISBN-10:
9780131411555.
William Stallings, "Cryptography and Network Security", 6th Edition, ISBN-13: 978-0-
13-335469-0.
Comer, Stevens, Internetworking with TCP/IP, Vol. III, Second Edition, PHI, ISBN-13:
978-0132609692 ISBN-10: 013260969X.
Richard M Reese, Learning Network Programming with Java, First Published: December
2015, Packet Publishing Ltd., ISBN-13: 978-0123742551, ISBN-10: 0123742552.
Dept. of CSE,RVCE 6
Network Programming and Security Lab Record -2020
List of Experiments
Ex.
Part A- Experiments
No.
3. Setup an IEEE 802.11 network with at least two access points. Apply the CBR,
VBR applications between devices belonging to same access points and different
access points. Provide roaming of any device. Vary the number of access points
and devices. Find out the delay in MAC layer, packet drop probability.
4. Case Study on Configuring Routers using CISCO-Packet tracer.
Note: The simulation experiments must be carried out using Qualnet and Cisco
packet tracer
Dept. of CSE,RVCE 7
Network Programming and Security Lab Record -2020
Instructions
Lab includes two parts of experiments Part A and Part B. Students need to follow the instructions
listed below:
PartA - Programs
1. The experiments shall be conducted using C / C++/java on Linux Operating
System. The output for client and server should be shown in different machines.
2. The student should execute the programs only in the lab machines and get the output verified
by the staff.
3. No Laptop can be used to show the output.
4. 50% of the marks will be reduced for late submission of record.
Part B- Simulation
Experiments are supposed to be carried out using Qualnet.
Dept. of CSE,RVCE 8
Network Programming and Security Lab Record -2020
Sl. Measuring
Criteria Excellent Good Poor
No methods
Student exhibits Student has sufficient
Student does not have a
thorough understanding of
Understanding clear understanding of
understanding of requirements and
of problem requirements and is
requirements and applies suitable
1 statement. Observations unable to apply suitable
applies suitable algorithm for the
algorithm for the
algorithm for the problem.
(CO1) problem.
problem.
(0 M)
(2 M) (<2 M and >=1 M)
Student demonstrates Student demonstrates
Student has not
the execution of the the execution of the
executed the program.
program with program without
optimized code and optimization of the
Execution
shows performance code and shows
2 Observations
efficiency. performance
(CO4)
Appropriate efficiency with only
validations with all test few test cases.
cases are handled.
(0 M)
(2 M) (1 M)
Documentation with Documentation with Documentation with no
appropriate comments only few comments comments and no
Results and
and output is covered and only few output output cases is covered
Documentation
3 Observations in data sheets and cases is covered in in data sheets and
manual. data sheets and manual.
(CO2)
manual.
(2 M) (1 M) (0 M)
Rubrics for Viva Voce (Max: 4 marks)
Explains thoroughly Adequately explains Unable to explain the
Conceptual the algorithm and the the algorithms and algorithm and data
Understanding data structure used data structures with structure.
1 Viva Voce
along with related related concepts
(CO1) concepts.
(2 M) (1 M) (0 M)
Insightful explanation Sufficiently explains Unable to explain the
Use of
of appropriate design the use of design techniques for
appropriate
techniques for the appropriate design the given problem.
Design
2 Viva Voce given problem to techniques for the
Techniques
derive solution. given problem to
derive solution.
(CO4)
(1 M) (0.5 M) (0 M)
Communicates the Sufficiently
Communication Unable to communicate
concept used in communicates the
of Concepts the concepts used in
3 Viva Voce problem solving well. concepts used in
problem.
problem solving.
(CO3) (0 M)
(1 M) (0.5 M)
Dept. of CSE,RVCE 9
Network Programming and Security Lab Record -2020
INDEX
PART B
Dept. of CSE,RVCE 10
Network Programming and Security Lab Record -2020
Schedule of Experiments
1 Setup a simple PPP network with 3 nodes n1, n2 and n3. Week9
LAB INTERNALS
RECORD Max – 40
TEST Max - 10
TOTAL Max – 50
Dept. of CSE,RVCE 11
Network Programming and Security Lab Record -2020
1.2 Applications
A Unix Socket is used in a client-server application framework. A server is a process that performs
some functions on request from a client. Most of the application-level protocols like FTP, SMTP,
and POP3 make use of sockets to establish connection between client and server and then for
exchanging data.
1.3 Types of socket
There are two types of Internet sockets available to users, Stream socket and Datagram socket.
1. Stream Socket(SOCK_STREAM)
A stream socket uses the Transmission Control Protocol (TCP) for sending messages. TCP provides
an ordered and reliable connection between two hosts. This means that for every message sent, TCP
guarantees that the message will arrive at the host in the correct order. This is achieved at the
transport layer so that the application need not bother about it. Stream sockets are also called as
connection oriented sockets.
2. Datagram Socket(SOCK_DGRAM)
A datagram socket uses the User Datagram Protocol (UDP) for sending messages. UDP is a much
simpler protocol as it does not provide any of the delivery guarantees that TCP does. Messages,
called datagrams, can be sent to another host without requiring any prior communication or a
connection having been established. As such, using UDP can lead to lost messages or messages
being received out of order. It is assumed that the application can tolerate an occasional lost message
or that the application will handle the issue of retransmission. Datagram sockets are also called as
connectionless sockets
1.4 Addressing
Every host on the internet is identified by its address called as Internet Protocol (IP) Address and the
process within the host is identified by the port numbers.
1.4.1 IP Address
An IP version 4 (IPV4) address is of 32 bits interpreted as four octets. IP version 6 (IPV6) is the
recent version of IP protocol and the address is of 128 bits and represented as 8 hextets.
Dept. of CSE,RVCE 12
Network Programming and Security Lab Record -2020
1.5 Structures
The structsockaddr holds the socket address information for many types of sockets defined in the
header file <sys/socket.h>. The members of this structures are described below
structsockaddr
{
unsigned short sa_family; // address family, AF_xxx
charsa_data[14]; // 14 bytes of protocol address
};
sa_family can be a variety of things, AF_INET (IPv4) or AF_INET6 (IPv6). sa_data contains a
destination address and port number for the socket.
Usually to deal with structsockaddr, programmers created a parallel structure: structsockaddr_in
(“in” for “Internet”) to be used with IPv4.A pointer to a structsockaddr_in can be cast to a pointer to
a structsockaddr and vice-versa.
The structure sockaddr_in is described below:
structsockaddr_in
{ shortintsin_family; // Address family, AF_INET
unsigned short intsin_port; // Port number
structin_addrsin_addr; // Internet address
unsigned char sin_zero[8]; // Same size as structsockaddr
};
Dept. of CSE,RVCE 13
Network Programming and Security Lab Record -2020
This structure makes it easy to reference elements of the socket address. Note that sin_zero (which is
included to pad the structure to the length of a structsockaddr) should be set to all zeros with the
function memset().sin_family corresponds to sa_family in a structsockaddr and should be set to
“AF_INET”. The sin_port must be in Network Byte Order.
The structure in_addr is used to refer four byte IP address in Network Byte Order.
structin_addr {
uint32_t s_addr; // 32-bit int (4 bytes)
};
1.7 Essential system calls for Inter Process communication using sockets
In any process communication, one process acts as a client and other as the server. This section
discusses about the system calls used by the client and servers to establish the connection and to
transfer the data.
Dept. of CSE,RVCE 14
Network Programming and Security Lab Record -2020
Description
• domain is PF_INET or PF_INET6,
• type is SOCK_STREAM or SOCK_DGRAM,
• Protocol can be set to 0 to choose the proper protocol for the given type.
Return Value
This system call returns a socket descriptor(sockfd)
2. Connect( )- To establish the connection to server’s socket.
Synopsis
#include<sys/types.h>
#include<sys/socket.h>
int connect(intsockfd, structsockaddr *serv_addr, intaddrlen);
Description
• sockfd is socket descriptor, as returned by the socket() call,
• serv_addr is a structsockaddr containing the destination port and IP address,
• addrlen is the length in bytes of the server address structure.
Return Value
The system call returns -1 on error and 0 on success.
3. send() and recv()
These two functions are for communicating over stream sockets or connected sockets. For
unconnected datagram sockets, sendto() and recvfrom() are used.
Send()
Synopsis
#include<sys/types.h>
#include<sys/socket.h>
int send(intsockfd, const void *msg, intlen, int flags);
Description
• sockfd is the socket descriptor on which data has to be sent (whether it's the one returned by
socket() or the one got with accept().)
• msg is a pointer to the data that has to be sent,
• len is the length of that data in bytes and
Flag is set to 0.
Return value
The system call returns number of bytes actually sent out.
Dept. of CSE,RVCE 15
Network Programming and Security Lab Record -2020
Recv()
Synopsis
#include<sys/types.h>
#include<sys/socket.h>
intrecv(intsockfd, void *buf, intlen, int flags);
Description
• sockfd is the socket descriptor to read the data from.
• Buf is the buffer to read the information into,
• len is the length of the buffer and
• Flag is set to 0.
Return value
The system call returns number of bytes actually read into the buffer, or -1 on error.
Dept. of CSE,RVCE 16
Network Programming and Security Lab Record -2020
Dept. of CSE,RVCE 17
Network Programming and Security Lab Record -2020
TCP Server
socket()
TCP Client
bind()
socket() listen()
accept()
connectionestblishment
data request
new socket
write()
read()
process request
\
data reply
write()
read()
shutdown( )
2 Distance vector
Routing algorithm is a part of network layer software which is responsible for deciding which output
line an incoming packet should be transmitted on. If the subnet uses datagram internally, this
decision must be made a new for every arriving data packet since the best route may have changed
Dept. of CSE,RVCE 18
Network Programming and Security Lab Record -2020
since last time. If the subnet uses virtual circuits internally, routing decisions are made only when a
new established route is being set up. The latter case is sometimes called session routing, because a
route remains in force for an entire user session.
Routing algorithms can be grouped into two major classes: adaptive and non adaptive. Non adaptive
algorithms do not base their routing decisions on measurement or estimates of current traffic and
topology. Instead, the choice of route to use to get from I to J (for all I and J) is compute in advance,
offline, and downloaded to the routers when the network ids booted. This procedure is sometime
called static routing.
Adaptive algorithms, in contrast, change their routing decisions to reflect changes in the topology,
and usually the traffic as well. Adaptive algorithms differ in where they get information (e.g.,
locally, from adjacent routers, or from all routers), when they change the routes (e.g., every Tsec,
when the load changes, or when the topology changes), and what metric is used for optimization
(e.g., distance, number of hops, or estimated transit time).
Two algorithms in particular, distance vector routing and link state routing are the most popular.
Distance vector routing algorithms operate by having each router maintain a table (i.e.,vector) giving
the best known distance to each destination and which line to get there. These tables are updated by
exchanging information with the neighbours.
The distance vector routing algorithm is sometimes called by other names, including the distributed
Bellman-Ford routing algorithm and the Ford-Fulkerson algorithm, after the researchers who
developed it (Bellman, 1957; and Ford and Fulkerson, 1962). It was the original ARPANET routing
algorithm and was also used in the Internet under the RIP and in early versions of DECnet and
Novell’s IPX. AppleTalk and Cisco routers use improved distance vector protocols.
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 out going line touse for
that destination, and an estimate of the time or distance to that destination. The metric used might be
number of hops, time delay in milliseconds, total number of packets queued along the path, or
something similar.
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. If the
metric is delay, the router can measure it directly with special ECHO packets has the receiver just
time stamps and sends back as fast as possible.
3. Internet checksum
Dept. of CSE,RVCE 19
Network Programming and Security Lab Record -2020
A checksum is a count of the number of bits in a transmission unit that is included with the unit so
that the receiver can check to see whether the same number of bits arrived.
The checksum is used in the Internet by several protocols although not at the data link layer.
Sender side:
3. All words including the checksum are added using one’s complement addition.
Receiver side:
4. Hamming code
Hamming code is a set of error-correction codes that are used to detect and correct the errors that
occurs during data transmission.
4.1 Redundant bits
Redundant bits are extra binary bits that are generated and added to the information-carrying bits of
data transfer to ensure that no bits were lost during the data transfer.
Dept. of CSE,RVCE 20
Network Programming and Security Lab Record -2020
The number of redundant bits can be calculated using the formula: 2r>= m+r+1, where r represents
redundant bits, m represents data bits. For example if m=4 then according to formula the number of
redundant bits to be added to data bits is 3.
4.2 Structure of encoder and decoder for hamming code
In the encoding process the data bits are appended with the redundant bits(ro,r1 and r2). The value
of redundant bits are determined and transmitted. At the receiver side the codeword is passes
through the checker to determine the syndrome bits(s0,s1 and s2). If the bits are zero it indicates
there is no error in the received codeword, otherwise the binary value of the syndrome bits
represents the position of error in the codeword.
4.3 Determining the redundant bits
To establish the relationship between the redundant bits and the data bits, the position of the
redundant bits must be determined. The redundant bits are placed at the positions corresponding to
power of 2(20,21,22…). The value of these redundant bits is determined by performing addition
modulo 2 of various position bits.
Consider an example: m=4 (1011) hence r=3(r2, r1,r0). The resulting codeword is of 7 bits.
Bit Positions 7 6 5 4 3 2 1
Power of 2 positions 22 21 20
Positions of redundant bits r2 r1 r0
Position of data bits d3 d2 d1 d0
Dept. of CSE,RVCE 21
Network Programming and Security Lab Record -2020
Codeword d3 d2 d1 r2 d0 r1 r0
For example 1 0 1 r2 1 r1 r0
The value of r1 is determined by performing arithmetic addition of the bits whose binary
representation of the position has least significant bit 1(bits at position 3,5, and 7). Similarly r2 is
determined with bit position having 1 at second position from least significant bit(3,6,7) and r3 is
determined with numbers having bit position having 1 at third position from least significant
bit(5,6,7 )
Since the syndrome is 110, the error is in sixth bit is in error. If syndrome bits are 000 then the
codeword is error free.
Dept. of CSE,RVCE 22
Network Programming and Security Lab Record -2020
congestion to warn the source. In implicit algorithm, the source deduces the existence of congestion
by making local observation, such as the time needed for acknowledgment to come back.
The presence of congestion means that the load is (temporarily) greater than the resources (in part of
the system) can handle. For subnets that use virtual circuits internally, these methods can be used at
the network layer.
Another open loop method to help manage congestion is forcing the packet to be transmitted at a
more predictable rate. This approach to congestion management is widely used in ATM networks
and is called traffic shaping.
5.1 Leaky bucket algorithm.
Each host is connected to the network by an interface containing a leaky bucket, that is, a finite
internal queue. If a packet arrives at the queue when it is full, the packet is discarded. In other
words, if one or more process are already queued, the new packet is unceremoniously discarded.
This arrangement can be built into the hardware interface or simulate d by the host operating system.
In fact it is nothing other than a single server queuing system with constant service time.
The host is allowed to put one packet per clock tick onto the network. This mechanism turns an
uneven flow of packet from the user process inside the host into an even flow of packet onto the
network, smoothing out bursts and greatly reducing the chances of congestion.
The leaky-bucket implementation is used to control the rate at which traffic is sent to the network. A
leaky bucket provides a mechanism by which bursty traffic can be shaped to present a steady stream
of traffic to the network, as opposed to traffic with erratic bursts of low-volume and high-volume
flows.The algorithm can be conceptually understood as follows:
Dept. of CSE,RVCE 23
Network Programming and Security Lab Record -2020
• The first parameter, s, is the socket the system call applies to. For multicasting, it must be a
socket of the family AF_INET and its type may be either SOCK_DGRAM or SOCK_RAW.
The most common use is with SOCK_DGRAM sockets.
• The second one, level, identifies the layer that is to handle the option, message or query. So,
SOL_SOCKET is for the socket layer, IPPROTO_IP for the IP layer, etc... For multicast
programming, level will always be IPPROTO_IP.optname identifies the option we are
setting/getting. Its value (either supplied by the program or returned by the kernel) is optval.
The optnames involved in multicast programming are the following:
setsockopt() getsockopt()
IP_MULTICAST_LOOP yes yes
Dept. of CSE,RVCE 24
Network Programming and Security Lab Record -2020
IP_ADD_MEMBERSHIP.
It is necessary to tell the kernel which multicast groups the receivers are interested in. If no process
is interested in a group, packets destined to it that arrive to the host are discarded. In order to inform
the kernel of the interests and, thus, become a member of that group, it is required to fill a ip_mreq
structure which is passed later to the kernel in the optval field of the setsockopt() system call.
The ip_mreq structure (taken from /usr/include/linux/in.h) has the following members:
Notice that a host can join several groups to the same socket, not just one. The limit to this is
IP_MAX_MEMBERSHIPS and, as of version 2.0.33, it has the value of 20.
IP_DROP_MEMBERSHIP.
The process is quite similar to joining a group:
structip_mreqmreq;
setsockopt (socket, IPPROTO_IP, IP_DROP_MEMBERSHIP, &mreq, sizeof(mreq));
wheremreq is the same structure with the same data used when joining the group.
Dept. of CSE,RVCE 25
Network Programming and Security Lab Record -2020
If the imr_interface member is filled with INADDR_ANY, the first matching group is dropped.
When a socket is closed, all memberships associated with it are dropped by the kernel. The same
occurs if the process that opened the socket is killed. Both ADD_MEMBERSHIP and
DROP_MEMBERSHIP are nonblocking operations. They should return immediately indicating
either success or failure.
7. Encryption and Decryption
The message to be sent through an unreliable medium is known as plaintext. For security purpose it
is encrypted before sending over the medium. The encrypted message is known as ciphertext, which
is received at the other end of the medium and decrypted to get back the original plaintext message.
There are various cryptography algorithms and can be divided into two broad categorize -
Symmetric key cryptography and Public key cryptography. The following figure shows a simple
cryptography model
SENDER RECEIVER
ENCRYPTION DECRYPTION
ALGORITHM ALGORITHM
INTRUDER
7.2 RSA
The most popular public-key algorithm is the RSA (named after their inventors Rivest, Shamir and
Adleman)
Key features of the RSA algorithm are given below:
1. Public key algorithm that performs encryption as well as decryption based on number
theory
2. Variable key length; long for enhanced security and short for efficiency (typical 512 bytes)
3. Variable block size, smaller than the key length
Dept. of CSE,RVCE 26
Network Programming and Security Lab Record -2020
4. The private key is a pair of numbers (d, n) and the public key is also a pair of numbers (e,
n)
To preserve data confidentiality during transmission, secure file transfer protocols like FTPS,
HTTPS, and SFTP have to encrypt the data through what is known as symmetric encryption. This
kind of encryption requires the two communicating parties to have a shared key in order for them to
encrypt and decrypt messages. In the real world, the two communicating parties would likely be
geographically separated by long distances. The key can't just be sent through ordinary methods
because anyone who gets hold of it would then be able to decrypt all the files that the two parties
would be sending to one another. A key exchange method should be easy to use, secure, and highly
scalable.
Diffie-Hellman is a way of establishing a shared secret between two endpoints (parties). Consider
following example to understand the algorithm. Let Alice and Bob wants to communicate with each
other without John knowing their communication. To start, Alice and Bob decide publicly (John will
also get a copy) on two prime numbers, g and n. Generally g is a small prime number and n is quite
large, usually 2000 or more commonly 4000 bits long. So now Alice, Bob and John all know these
numbers.
Alice now decides secretly on another number, a. and Bob decides secretly on a number, b. Neither
Alice nor Bob send these numbers, they are kept to themselves. Alice performs a calculation, g^a
mod n, let this be A, since it comes from a. Bob then performs g^b mod n let this be B.
Alice sends Bob, A, and Bob sends Alice, B. Note John now has 4 numbers, A, B, g and n but
not a or b. Alice takes Bob’s B and performs B^a mod n. Similarly, Bob takes Alice’s A and
performs A^b mod n. This results in the same number i.e. B^a mod n = A^b mod n. They now have
a shared number. John can’t figure out what these numbers are from the numbers he’s got.
Dept. of CSE,RVCE 27
Network Programming and Security Lab Record -2020
Users can evaluate the basic behavior of a network, and test combinations of network features that
are likely to work. The software provides a comprehensive environment for designing protocols,
creating and animating network scenarios, and analyzing their performance.
QualNet Network Simulator includes a Suite of Tools:
• QualNet Architect- A graphical scenario design and visualization tool. In Design mode, the
user can set up terrain, network connections, subnets, mobility patterns of wireless users, and
other functional parameters of network nodes. The user can also create network models by
using intuitive, click and drag operations, he can also customize the protocol stack of any of
the nodes. The user can also specify the application layer traffic and services that run on the
network. In Visualize mode, he can perform in-depth visualization and analysis of a network
scenario designed in Design mode. As network simulations are running, users can watch
packets at various layers flow through the network and view dynamic graphs of critical
performance metrics. Real-time statistics are also an option, where user can view dynamic
graphs while a network simulation software is running.
• QualNet Analyzer — A statistical graphing tool that displays hundreds of metrics collected
during simulation of a network scenario. The user can choose to see pre-designed reports or
customize graphs with their own statistics. Multi-experiment reports are also available. All
statistics are exportable to spreadsheets in CSV format.
• QualNet Packet Tracer — A graphical tool that provides a visual representation of packet
trace files generated during the simulation of a network scenario. Trace files are text files in
XML format that contain information about packets as they move up and down the protocol
stack.
• QualNet File Editor — A text editing tool
• QualNet Command Line Interface — Command line access to the simulator
Dept. of CSE,RVCE 28
Network Programming and Security Lab Record -2020
Dept. of CSE,RVCE 29
Network Programming and Security Lab Record -2020
address.sin_family = AF_INET;
address.sin_addr.s_addr = INADDR_ANY;
address.sin_port = htons(15001);
if (bind(create_socket,(structsockaddr *)&address,sizeof(address)) == 0)
printf("Binding Socket\n");
listen(create_socket,3);
addrlen = sizeof(structsockaddr_in);
new_socket = accept(create_socket,(structsockaddr *)&address,&addrlen);
if (new_socket> 0)
{
printf("The Client %s is Connected...\n",
inet_ntoa(address.sin_addr) );
}
recv(new_socket,fname, 255,0);
printf("A request for filename %s Received..\n", fname);
if ((fd=open(fname, O_RDONLY))<0)
{perror("File Open Failed"); exit(0);}
while((cont=read(fd, buffer, bufsize))>0) {
send(new_socket,buffer,cont,0);
}
printf("Request Completed\n");
close(new_socket);
return close(create_socket);
}
/*Client*/
#include<sys/socket.h>
#include<sys/types.h>
#include<netinet/in.h>
#include<unistd.h>
#include<stdlib.h>
#include<stdio.h>
int main(intargc,char *argv[])
{
intcreate_socket;
intbufsize = 1024, cont;
char *buffer = malloc(bufsize);
charfname[256];
structsockaddr_in address;
if ((create_socket = socket(AF_INET,SOCK_STREAM,0)) > 0)
printf("The Socket was created\n");
Dept. of CSE,RVCE 30
Network Programming and Security Lab Record -2020
address.sin_family = AF_INET;
address.sin_port = htons(15001);
inet_pton(AF_INET,argv[1],&address.sin_addr);
if (connect(create_socket,(structsockaddr *) &address, sizeof(address)) == 0)
printf("The connection was accepted with the server %s...\n",argv[1]);
printf("Enter The Filename to Request : "); scanf("%s",fname);
send(create_socket, fname, sizeof(fname), 0);
printf("Request Accepted... Receiving File...\n\n");
printf("The contents of file are...\n\n");
while((cont=recv(create_socket, buffer, bufsize, 0))>0) {
write(1, buffer, cont);
}
printf("\nEOF\n");
return close(create_socket);
}
OUTPUT
SERVER
exam@dell:~$ gcc -o server server.c
exam@dell:~$ ./server
The socket was created
Binding Socket
The Client 127.0.0.1 is Connected...
A request for filename test.txt Received..
Request Completed
CLIENT
exam@dell:~$ gcc -o client client.c
exam@dell:~$ ./client 127.0.0.1
The Socket was created
The connection was accepted with the server 127.0.0.1...
Enter The Filename to Request : test.txt
Request Accepted... Receiving File...
The contents of file are...
hello
EOF
Dept. of CSE,RVCE 31
Network Programming and Security Lab Record -2020
Output: Shortest distance to all vertices from src. If there is a negative weight cycle, then shortest
distances are not calculated, negative weight cycle is reported.
1. Initializes distances from source to all vertices as infinite and distance to source itself as 0.
Create an array dist[] of size |V| with all values as infinite except dist[src] where src is source
vertex.
2. Ccalculate shortest distances. Do following |V|-1 times where |V| is the number of vertices in
given graph.
…..a) Do following for each edge u-v
………………If dist[v] >dist[u] + weight of edge uv, then update dist[v]
………………….dist[v] = dist[u] + weight of edge uv
3. This step reports if there is a negative weight cycle in graph.
Do following for each edge u-v
……If dist[v] >dist[u] + weight of edge uv, then “Graph contains negative weight cycle”
PROGRAM
#include<stdio.h>
int A[10][10], n, d[10], p[10];
voidBellmanFord(int s){
inti,u,v;
for(i=1;i<n;i++){
for(u=0;u<n;u++){
for(v=0;v<n;v++){
if(d[v] > d[u] + A[u][v]){
d[v] = d[u] + A[u][v];
p[v] = u;
}
}
}
}
for(u=0;u<n;u++){
for(v=0;v<n;v++){
if(d[v] > d[u] + A[u][v]){
printf("Negative Edge");
}
}
}
}
int main(){
Dept. of CSE,RVCE 32
Network Programming and Security Lab Record -2020
int source;
for(source=0;source<n;source++){
for(i=0;i<n;i++){
d[i] = 999;
p[i] = -1;
}
d[source] = 0;
BellmanFord(source);
printf("Router %d\n",source);
for(i=0;i<n;i++){
if(i != source){
j = i;
while(p[j] != -1){
printf("%d <- ",j);
j = p[j];
}
}
printf("%d\tCost %d\n\n",source,d[i]);
}
}
return 0;
}
OUTPUT
exam@dell:~$ gccdvr.c
exam@dell:~$ ./a.out
Enter the no. of vertices : 5
Enter the adjacency matrix
0 1 5 999 999
1 0 3 999 9
5 3 0 4 999
999 999 4 0 2
999 9 999 2 0
Router 0
0 Cost 0
1 <- 0 Cost 1
Dept. of CSE,RVCE 33
Network Programming and Security Lab Record -2020
Router 1
0 <- 1 Cost 1
1 Cost 0
2 <- 1 Cost 3
4 <- 1 Cost 9
Router 2
0 <- 1 <- 2 Cost 4
1 <- 2 Cost 3
2 Cost 0
3 <- 2 Cost 4
Router 3
0 <- 1 <- 2 <- 3 Cost 8
2 <- 3 Cost 4
3 Cost 0
4 <- 3 Cost 2
Router 4
0 <- 1 <- 4 Cost 10
1 <- 4 Cost 9
3 <- 4 Cost 2
4 Cost 0
Dept. of CSE,RVCE 34
Network Programming and Security Lab Record -2020
Note- Use IP header fields obtained using wireshark packet analyzer tool
PROGRAM
#include<stdio.h>
unsigned fields[10];
unsigned short checksum()
{
inti;
int sum=0;
printf("Enter IP header information in 16 bit words\n");
for(i=0;i<9;i++)
{
printf("Field %d\n",i+1);
scanf("%x",&fields[i]);
sum=sum+(unsigned short)fields[i];
while (sum>>16)
sum = (sum & 0xFFFF) + (sum >> 16);
}
sum=~sum;
return (unsigned short)sum;
}
int main()
{
unsigned short result1, result2;
//Sender
result1=checksum();
printf("\n COmputed Checksum at sender %x\n", result1);
//Receiver
result2=checksum();
printf("\n COmputed Checksum at receiver %x\n", result2);
if(result1==result2)
printf("No error");
else
printf("Error in data received");
Dept. of CSE,RVCE 35
Network Programming and Security Lab Record -2020
OUTPUT
Values obtained from wireshark:
4500 003c 1c46 4000 4006 b1e6 ac10 0a63 ac10 0a0c
exam@dell:~$ gccchecksum.c
exam@dell:~$ ./a.out
Enter IP header information in 16 bit words
Field 1 4500 Field 2 003c Field 3 1c46 Field 4 4000 Field 5 4006 Field 6
ac10 Field 7 0a63 Field 8 ac10 Field 9 0a0c
COmputed Checksum at sender b1e6
Enter IP header information in 16 bit words
Field 1 4500 Field 2 003c Field 3 1c46 Field 4 4000 Field 5 4006 Field 6
ac10 Field 7 0a63 Field 8 ac10 Field 9 0a0c
COmputed Checksum at receiver b1e6
No error
Dept. of CSE,RVCE 36
Network Programming and Security Lab Record -2020
PROGRAM
#include <stdlib.h>
#include<stdio.h>
int main()
{
int a[4],b[4],r[3],s[3],i,q[3],c[7];
printf("\nenter 4 bit data word:\n");
for(i=3;i>=0;i--)
{
scanf("%d",&a[i]);
}
r[0]=(a[3]+a[1]+a[0])%2;
r[1]=(a[0]+a[2]+a[3])%2;
r[2]=(a[1]+a[2]+a[3])%2;
for(i=7;i>0;i--)
scanf ("%d",&c[i]);
b[3]=c[7];b[2]=c[6];b[1]=c[5];b[0]=c[4];
r[2]=c[3];r[1]=c[2];r[0]=c[1];
for(i=2;i>=0;i--)
{
printf("%d",s[i]);
}
if((s[2]==0) && (s[1]==0) && (s[0]==0))
printf("\n RECIEVED WORD IS ERROR FREE\n");
Dept. of CSE,RVCE 37
Network Programming and Security Lab Record -2020
if((s[2]==1)&&(s[1]==1)&&(s[0]==1))
{
printf("\nError in received codeword, position- 7th bit from
right\n");
if(c[7]==0)
c[7]=1;
else
c[7]=0;
printf("\n Corrected codeword is\n");
for(i=7;i>0;i--)
printf("%d \t", c[i]);
}
if((s[2]==1)&&(s[1]==1)&&(s[0]==0))
{
printf("\nError in received codeword, Position- 6th bit from
right\n");
if(c[6]==0)
c[6]=1;
else
c[6]=0;
printf("\n Corrected codeword is\n");
for(i=7;i>0;i--)
printf("%d \t", c[i]);
}
if((s[2]==1)&&(s[1]==0)&&(s[0]==1))
{
printf("\nError in received codeword, Position- 5th bit from
right\n");
if(c[5]==0)
c[5]=1;
else
c[5]=0;
printf("\n Corrected codeword is\n");
for(i=7;i>0;i--)
printf("%d \t", c[i]);
}
if((s[2]==1)&&(s[1]==0)&&(s[0]==0))
{
printf("\nError in received codeword, Position- 4th bit from
right\n");
if(c[4]==0)
c[4]=1;
else
c[4]=0;
printf("\n Corrected codeword is\n");
for(i=7;i>0;i--)
printf("%d \t", c[i]);
}
if((s[2]==0)&&(s[1]==1)&&(s[0]==1))
{
printf("\nError in received codeword, Position- 3rd bit from
right\n");
if(c[3]==0)
c[3]=1;
Dept. of CSE,RVCE 38
Network Programming and Security Lab Record -2020
else
c[3]=0;
printf("\n Corrected codeword is\n");
for(i=7;i>0;i--)
printf("%d \t", c[i]);
}
if((s[2]==0)&&(s[1]==1)&&(s[0]==0))
{
printf("\nError in received codeword, Position- 2nd bit from
right\n");
if(c[2]==0)
c[2]=1;
else
c[2]=0;
printf("\n Corrected codeword is\n");
for(i=7;i>0;i--)
printf("%d \t", c[i]);
}
if((s[2]==0)&&(s[1]==0)&&(s[0]==1))
{
printf("\nError in received codeword, Position- 1st bit from
right\n");
if(c[1]==0)
c[1] =1;
else
c[1]=0;
printf("\n Corrected codeword is\n");
for(i=7;i>0;i--)
printf("%d \t", c[i]);
}
return(1);
}//End of Hamming code program*/
OUTPUT
RUN 1
exam@dell:~$ gcchamming.c
exam@dell:~$ ./a.out
enter 4 bit data word:
1 0 1 1
The 7bit hamming code word:
1 0 1 1 0 0 1
Enter the 7bit recievedcodeword:
1 0 1 1 0 0 1
syndrome is:
000
RECIEVED WORD IS ERROR FREE
RUN 2
exam@dell:~$ ./a.out
enter 4 bit data word:
1 0 1 1
the 7bit hamming code word:
1 0 1 1 0 0 1
enter the 7bit recievedcodeword: 1 1 1 1 0 0 1
syndrome is:
Dept. of CSE,RVCE 39
Network Programming and Security Lab Record -2020
110
recieved word is error, position- 6th bit from right
Corrected codeword is
1 0 1 1 0 0 1
PROGRAM
/*Listener*/
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <time.h>
#include <string.h>
Dept. of CSE,RVCE 40
Network Programming and Security Lab Record -2020
#include <stdio.h>
#include<stdlib.h>
Dept. of CSE,RVCE 41
Network Programming and Security Lab Record -2020
if ((nbytes=recvfrom(fd,msgbuf,MSGBUFSIZE,0,
(structsockaddr *) &addr,&addrlen)) < 0) {
perror("recvfrom");
}
puts(msgbuf);
}
}
/*Sender*/
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <time.h>
#include <string.h>
#include <stdio.h>
#include<stdlib.h>
Output
SENDER:
exam@dell:~$ gcc -o sender sender.c
Dept. of CSE,RVCE 42
Network Programming and Security Lab Record -2020
LISTENER1
exam@dell:~$ gcc -o listen listener.c
exam@dell:~$ ./listen // Listens to messages by joining multicast group
RVCE-CSE
RVCE-CSE
RVCE-CSE
RVCE-CSE
LISTENER2
exam@dell:~$ ./listen // Listens to messages by joining multicast group
RVCE-CSE
RVCE-CSE
RVCE-CSE
RVCE-CSE
Dept. of CSE,RVCE 43
Network Programming and Security Lab Record -2020
5. Write a program to implement concurrent chat server that allows current logged in users to
communicate one with other.
/*Client*/
#include<sys/socket.h>
#include<sys/types.h>
#include<netinet/in.h>
#include<unistd.h>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
//char fname[256];
struct sockaddr_in address;
if ((create_socket = socket(AF_INET,SOCK_STREAM,0)) > 0)
printf("The Socket was created\n");
address.sin_family = AF_INET;
address.sin_port = htons(16001);
inet_pton(AF_INET,argv[1],&address.sin_addr);
if (connect(create_socket,(struct sockaddr *) &address, sizeof(address))
== 0)
printf("The connection was accepted with the server
%s...\n",argv[1]);
else
printf("error in connect \n");
//printf("Enter The Filename to Request : "); scanf("%s",fname);
//send(create_socket, fname, sizeof(fname), 0);
//printf("Request Accepted... Receiving File...\n\n");
//printf("The contents of file are...\n\n");
str_cli(stdin,create_socket);
return close(create_socket);
}
Dept. of CSE,RVCE 44
Network Programming and Security Lab Record -2020
/*server*/
#include<sys/types.h>
#include<sys/socket.h>
#include<netinet/in.h>
#include<sys/stat.h>
#include<unistd.h>
#include<stdlib.h>
#include<stdio.h>
#include<fcntl.h>
#include <arpa/inet.h>
#include<string.h>
}
bzero(buffer,10240);
}}
int main()
{
int cont,listenfd,connfd,addrlen,addrlen2,fd,pid,addrlen3;
//char fname[256];
struct sockaddr_in address,cli_address;
if ((listenfd = socket(AF_INET,SOCK_STREAM,0)) > 0) //sockfd
printf("The socket was created\n");
address.sin_family = AF_INET;
address.sin_addr.s_addr = INADDR_ANY;
address.sin_port = htons(16001);
printf("The address before bind %s ...\n",inet_ntoa(address.sin_addr) );
if (bind(listenfd,(struct sockaddr *)&address,sizeof(address)) == 0)
printf("Binding Socket\n");
printf("The address after bind %s ...\n",inet_ntoa(address.sin_addr)
);
listen(listenfd,3);
printf("server is listening\n");
//server local address
getsockname(listenfd,(struct sockaddr *)&address,&addrlen3);
printf("The server's local address %s ...and port
%d\n",inet_ntoa(address.sin_addr),htons(address.sin_port));
for(;;){
addrlen = sizeof(struct sockaddr_in);
connfd = accept(listenfd,(struct sockaddr *)&cli_address,&addrlen);
//printf("The address %s ...\n",inet_ntoa(address.sin_addr) );
addrlen2 = sizeof(struct sockaddr_in);
Dept. of CSE,RVCE 45
Network Programming and Security Lab Record -2020
if((pid=fork())==0)
{
printf("inside child\n");
close(listenfd);
str_echo(connfd);
exit(0);
}
close(connfd);}
return 0 ;
}
6. a) Implementation of concurrent and iterative echo server using connection oriented socket
system calls
/*Client*/
#include<sys/socket.h>
#include<sys/types.h>
#include<netinet/in.h>
#include<unistd.h>
#include<stdlib.h>
#include<stdio.h>
while(fgets(buffer,bufsize,fp)!=NULL)
{
send(sockfd, buffer, sizeof(buffer), 0);
Dept. of CSE,RVCE 46
Network Programming and Security Lab Record -2020
str_cli(stdin,create_socket);
return close(create_socket);
}
/*server*/
#include<sys/types.h>
#include<sys/socket.h>
#include<netinet/in.h>
#include<sys/stat.h>
#include<unistd.h>
#include<stdlib.h>
#include<stdio.h>
#include<fcntl.h>
#include <arpa/inet.h>
}
int main()
{
int cont,listenfd,connfd,addrlen,addrlen2,fd,pid,addrlen3;
listen(listenfd,3);
printf("server is listening\n");
//server local address
getsockname(listenfd,(struct sockaddr *)&address,&addrlen3);
printf("The server's local address %s ...and port
%d\n",inet_ntoa(address.sin_addr),htons(address.sin_port));
Dept. of CSE,RVCE 47
Network Programming and Security Lab Record -2020
for(;;){
addrlen = sizeof(struct sockaddr_in);
connfd = accept(listenfd,(struct sockaddr *)&cli_address,&addrlen);
//printf("The address %s ...\n",inet_ntoa(address.sin_addr) );
addrlen2 = sizeof(struct sockaddr_in);
int i = getpeername(connfd,(struct sockaddr *)&cli_address,&addrlen);
str_echo(connfd);
exit(0);
}
close(connfd);}
return 0 ;
}
b) Implementation of concurrent and iterative echo server using connectionless socket system
calls
/*Client*/
#include<sys/socket.h>
#include<sys/types.h>
#include<netinet/in.h>
#include<unistd.h>
#include<stdlib.h>
#include<stdio.h>
#include<arpa/inet.h>
Dept. of CSE,RVCE 48
Network Programming and Security Lab Record -2020
printf("\nEOF\n");
}
int main(int argc,char *argv[])
{
int sockfd;
//char fname[256];
struct sockaddr_in serv_address;
if ((sockfd = socket(AF_INET,SOCK_DGRAM,0)) > 0)
printf("The Socket was created\n");
serv_address.sin_family = AF_INET;
serv_address.sin_port = htons(16001);
inet_pton(AF_INET,argv[1],&serv_address.sin_addr);
str_cli(stdin,sockfd,(struct sockaddr
*)&serv_address,sizeof(serv_address));
exit(0);
}
/*server*/
#include<sys/types.h>
#include<sys/socket.h>
#include<netinet/in.h>
#include<sys/stat.h>
#include<unistd.h>
#include<stdlib.h>
#include<stdio.h>
#include<fcntl.h>
#include <arpa/inet.h>
for(;;){
addrlen = clilen;
n=recvfrom(sockfd,buffer,bufsize,0,cli_address,&addrlen);
//printf("%s",buffer);
sendto(sockfd,buffer,n,0,cli_address,addrlen);}
//printf("%d n",n);
}
int main()
{
int sockfd;
struct sockaddr_in serv_address,cli_address;
serv_address.sin_family = AF_INET;
Dept. of CSE,RVCE 49
Network Programming and Security Lab Record -2020
serv_address.sin_addr.s_addr = INADDR_ANY;
serv_address.sin_port = htons(16001);
printf("The address before bind %s
...\n",inet_ntoa(serv_address.sin_addr) );
if (bind(sockfd,(struct sockaddr *)&serv_address,sizeof(serv_address))
== 0)
printf("Binding Socket\n");
str_echo(sockfd,(struct sockaddr *)&cli_address,sizeof(cli_address));
return 0 ;
}
/*server*/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<unistd.h>
#include<netinet/in.h>
#include<arpa/inet.h>
#include<sys/types.h>
#include<sys/socket.h>
#include<errno.h>
int main()
{
int sd,acpt,len,bytes,port;
char send[50],receiv[50];
struct sockaddr_in serv,cli;
if((sd=socket(AF_INET,SOCK_STREAM,0))<0)
{
printf("Error in socket\n");
exit(0);
}
bzero(&serv,sizeof(serv));
serv.sin_family=AF_INET;
serv.sin_port=htons(15002);
serv.sin_addr.s_addr=htonl(INADDR_ANY);
if(bind(sd,(struct sockaddr *)&serv,sizeof(serv))<0)
{ printf("Error in bind\n"); exit(0); }
if(listen(sd,3)<0)
{ printf("Error in listen\n"); exit(0); }
if((acpt=accept(sd,(struct sockaddr*)NULL,NULL))<0)
{ printf("\n\t Error in accept"); exit(0); }
while(1) { bytes=recv(acpt,receiv,50,0); receiv[bytes]='\0';
if(strcmp(receiv ,"end")==0)
{ close(acpt); close(sd); exit(0); }
else { printf("Command received : %s",receiv); system(receiv);
printf("\n"); } }
}
/*client*/
#include<stdio.h>
#include<stdlib.h>
Dept. of CSE,RVCE 50
Network Programming and Security Lab Record -2020
#include<string.h>
#include<unistd.h>
#include<netinet/in.h>
#include<arpa/inet.h>
#include<sys/types.h>
#include<sys/socket.h>
#include<errno.h>
int
main ()
{
serv.sin_family = AF_INET;
serv.sin_port = htons (15002);
serv.sin_addr.s_addr = htonl (INADDR_ANY);
if (connect (sd, (struct sockaddr *) &serv, sizeof (serv)) < 0)
{
printf ("Error in connection\n");
exit (0);
}
while (1)
{
printf ("Enter the command:");
gets (send1);
if (strcmp (send1, "end") != 0)
{
send (sd, send1, 50, 0);
}
else
{
send (sd, send1, 50, 0);
close (sd);
break;
}
}
}
8. a) Write a program to encrypt and decrypt the data using RSA and
b) Write a program to exchange the key securely using Diffie-Hellman Key exchange
protocol.
RSA Algorithm
Generating Public Key
1. Select two prime numbers p and q.
2. Compute n=p*q.
3. Choose e, such that it is an integer and not the factor of n.
4. Public key –(n,e)
Dept. of CSE,RVCE 51
Network Programming and Security Lab Record -2020
a) PROGRAM
#include <iostream>
#include <stdlib.h>
#include <math.h>
#include <string.h>
longintisprime(long int a)
{
inti;
for(i = 2; i< a; i++){
if((a % i) == 0)
return 0;
}
return 1;
}
Dept. of CSE,RVCE 52
Network Programming and Security Lab Record -2020
int main()
{
longinti, len;
longint p, q, n, phi, e, d, cipher[50];
char text[50];
OUTPUT
exam@dell:~$ g++ rsa.cpp
exam@dell:~$ ./a.out
Enter the text to be encrypted: rvcecse
Two prime numbers (p and q) are: 13 and 23
n(p * q) = 13 * 23 = 299
(p - 1) * (q - 1) = 264
Dept. of CSE,RVCE 53
Network Programming and Security Lab Record -2020
Dept. of CSE,RVCE 54
Network Programming and Security Lab Record -2020
b) PROGRAM
#include <stdio.h>
while (m > 0)
{
r = m % 2;
// fast exponention
if (r == 1)
y = (y*a) % n;
a = a*a % n;
m = m / 2;
}
return y;
}
// choose secret integer for Bob's Pivate Key (only known to Bob)
srand(time(0)) ;
b = rand(); // or use rand()
// Alice and Bob Exchanges their Public Key A & B with each other
Dept. of CSE,RVCE 55
Network Programming and Security Lab Record -2020
return 0;
}
OUTPUT
RUN-1
exam@dell:~$ ./a.out
Alice's Secret Key is 4
Bob's Secret Key is 4
RUN-2
exam@dell:~$ ./a.out
Alice's Secret Key is 11
Bob's Secret Key is 11
RUN-3
exam@dell:~$ ./a.out
Alice's Secret Key is 10
Bob's Secret Key is 10
1. Setup an IEEE 802.3 network with a) hub b) switch c) Hierarchy of switch. Apply the
FTP, Telnet applications between nodes. Vary the number of nodes. Vary the bandwidth,
queue size and observe the packet drop probability.
Solution
Dept. of CSE,RVCE 56
Network Programming and Security Lab Record -2020
Step 2: Choose the applications between the nodes- FTP and Telnet.
Step 4: Vary number of nodes, bandwidth of the link and queue size of the devices.
Dept. of CSE,RVCE 57
Network Programming and Security Lab Record -2020
2. Setup a wireless sensor networks with atleast two device co-coordinators and nodes.
Provide Constant Bit Rate (CBR), Variable Bit Rate (VBR) application between several
nodes. Increase the number of co-coordinators and nodes in the same area and observe the
performance at physical and MAC layers.
Solution:
Step 1: Set up the topology with wireless sensors with coordinators and nodes as shown in the figure
Dept. of CSE,RVCE 58
Network Programming and Security Lab Record -2020
Step 2: Choose the applications between the nodes- CBR and VBR.
Dept. of CSE,RVCE 59
Network Programming and Security Lab Record -2020
Dept. of CSE,RVCE 60
Network Programming and Security Lab Record -2020
3. Setup an IEEE 802.11 network with atleast two access points. Apply the CBR, VBRapplications
between devices belonging to same access points and different access points.Provide roaming of any
device. Vary the number of access points and devices. Find outthe delay in MAC layer, packet drop
probability.
Solution:
Step 1: Setup the network topology with two access points as shown in the figure.
Step 2:Apply the CBR, VBRapplications between devices belonging to same access points and
different access points.
Step 4: Apply mobility to any one device and set the trajectory.
Step 5: Vary the number of access points and devices. Find outthe delay in MAC layer, packet drop
probability.
Dept. of CSE,RVCE 61
Network Programming and Security Lab Record -2020
VIVA questions
DNS - Domain Name System. DNS is the Naming System for the resources over Internet; includes
Physical nodes and Applications. DNS –It is the easy way to locate to a resource easily over a
network and serves to be an essential component necessary for the working of Internet.
2. What is a Network?
A network means a set of devices that connected by physical media links. A network is recursively a
connection of more than two nodes by a physical link or two or more networks connected by one or
more nodes.
3. What is Bandwidth?
Each and Every Signal often has a limit of an upper range and lower range of frequency of signal it
can carry. So this range of limit of network between its upper frequency and lower frequency is
termed as Bandwidth.
At the basic level, a network includes two or more computers directly connected by some physical
medium such as co-axial cable or optical fiber. And that physical medium is called a Link.
DNS servers usually communicate with outside DNS servers of the local network. A forwarder is an
entry that is used when a DNS server receives DNS queries that it cant resolve locally. And then it
forwards those requests to external DNS servers for resolution
7. Define node?
A network consist of two or more computers which will be directly connected by some physical
medium such as coaxial cable or optical fiber. And that physical medium is called as Links and the
computer it connects is termed as Nodes.
A router or gateway is a node that is connected to two or more networks. In general it forwards
message from one network to another.
Dept. of CSE,RVCE 62
Network Programming and Security Lab Record -2020
If the physical links are limited to a pair of nodes then it is said to be point-point link.
A scope is a range, or pool of IP addresses that can be leased to DHCP clients on a given subnet.
An FQDN - fully qualified domain name contains both the hostname and a domain name. FQDN is
uniquely identifies a host within a DNS hierarchy.
12. What is MAC address? Does it have some link or something in common to Mac OS of
Apple?
MAC - Media Access Control. MAC is the address of the device identified at Media Access Control
Layer of Network Architecture. Similar to IP address MAC address is unique address, i.e., no two
device can have same MAC address. MAC address is stored at the ROM Read Only Memory of the
device.
MAC Address and Mac OS are two different things and it should not be confused with each other.
Mac OS is a POSIX standard Operating System Developed upon FreeBSD used by Apple devices.
What is POP3?
POP3 stands for Post Office Protocol Version3 (Current Version). POP is a protocol which
listens on port 110 and is responsible for accessing the mail service on a client machine.
POP3 works in two modes such as Delete Mode and Keep Mode.
1. a)Delete Mode: A mail is deleted from the mailbox after successful retrieval.
2. b)b) Keep Mode: The Mail remains Intact in the mailbox after successful retrieval.
3. How will check IP address on 98
Three ranges of IP addresses have been reserved for private address and they are not valid
for use on the Internet. If you want to access internet with these address you must have to use
proxy server or NAT server (on normal cases the role of proxy server is played by your
ISP.).If you do decide to implement a private IP address range, you can use IP addresses
from any of the following classes:
Class A: 10.0.0.0 10.255.255.255
Class B: 172.16.0.0 172.31.255.255
Class C: 192.168.0.0 192.168.255.255
A public IP address is an address leased from an ISP that allows or enables direct Internet
communication.
Dept. of CSE,RVCE 63
Network Programming and Security Lab Record -2020
Along any transmission path from a given source to a given destination, a group of virtual circuits
can be grouped together into what is called path.
Virtual channel is normally a connection from one source to one destination, although multicast
connections are also permitted. The other name for virtual channel is virtual circuit.
Routable protocols can work with a router and can be used to build large networks. Non-Routable
protocols are also there which is designed to work on small, local networks and cannot be used with
a router
What is the difference between TFTP and FTP application layer protocols?
The Trivial File Transfer Protocol (TFTP) allows a local host to obtain files from a remote host but
does not provide reliability or security. It uses the fundamental packet delivery services offered by
UDP.
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 offered 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.
What is the minimum and maximum length of the header in the TCP segment and IP
datagram?
The header should have a minimum length of 20 bytes and can have a maximum length of 60 bytes.
The address resolution protocol (ARP) is used to associate the 32 bit IP address with the 48 bit
physical address, used by a host or a router to find the physical address of another host on its
network by sending a ARP query packet that includes the IP address of the receiver.
The reverse address resolution protocol (RARP) allows a host to discover its Internet address when
it knows only its physical address.
Define about ICMP?
ICMP is Internet Control Message Protocol, a network layer protocol of the TCP/IP suite used by
hosts and gateways to send notification of datagram problems back to the sender. It uses the echo
test / reply to test whether a destination is reachable and responding. It also handles both control and
error messages.
Dept. of CSE,RVCE 64
Network Programming and Security Lab Record -2020
8. A set of LANs, interconnected through routers, use a common DHCP server on one
of the LANs. In this scenario, a __________________ agent is required on each of
the other LANs to access the DHCP server.
9. Write an IPv4 address using a combination of colons and the dotted decimal
number.
12. The ______________ extension header in IPv6 provides information about the
encrypted contents.
Dept. of CSE,RVCE 65
Network Programming and Security Lab Record -2020
15. The generic term used to refer to the end point “port” is ________________.
16. The initial connection protocol uses a special ___________ server that acts as
proxy for servers which are not heavily used.
19. Why is it necessary for a sender using TCP to buffer the TPDUs it transmits ?
20. Why is it necessary for a sender using TCP to buffer the TPDUs it transmits ?
21. In RPC, the client and server programs are bound with a library procedure called
_______.
22. In RPC, the process of the client packing the parameters into a message is known
as ______________.
23. The field ‘Payload type’ in the RTP header is used for
____________________________.
Dept. of CSE,RVCE 66
Network Programming and Security Lab Record -2020
29. In the hierarchical design of domain name space, the inverted tree structure can
have levels from level _________ to level ___________.
Dept. of CSE,RVCE 67