Updated NPS Instructor Manual 2024 25
Updated NPS Instructor Manual 2024 25
Bengaluru -560059
(CS362IA)
VI Semester B.E
VI SEMESTER B.E
2025-2026
Dept. of CSE,RVCE 1
Network Programming and Security Instructor Manual - 2025
Vision
Mission
Dept. of CSE,RVCE 2
Network Programming and Security Instructor Manual - 2025
Schedule of Experiments
Write a program to encrypt and decrypt the data using RSA and Exchange
8 Week9
the key securely using Diffie-Hellman Key exchange protocol
PART-B
Dept. of CSE,RVCE 3
Network Programming and Security Instructor Manual - 2025
Dept. of CSE,RVCE 4
Network Programming and Security Instructor Manual - 2025
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 5
Network Programming and Security Instructor Manual - 2025
INDEX
PART B
Dept. of CSE,RVCE 6
Network Programming and Security Instructor Manual - 2025
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 7
Network Programming and Security Instructor Manual - 2025
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 8
Network Programming and Security Instructor Manual - 2025
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 9
Network Programming and Security Instructor Manual - 2025
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 10
Network Programming and Security Instructor Manual - 2025
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 11
Network Programming and Security Instructor Manual - 2025
Dept. of CSE,RVCE 12
Network Programming and Security Instructor Manual - 2025
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
Dept. of CSE,RVCE 13
Network Programming and Security Instructor Manual - 2025
must be made a new for every arriving data packet since the best route may have changed 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.
Dept. of CSE,RVCE 14
Network Programming and Security Instructor Manual - 2025
3. Internet checksum
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
Dept. of CSE,RVCE 15
Network Programming and Security Instructor Manual - 2025
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.
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
Dept. of CSE,RVCE 16
Network Programming and Security Instructor Manual - 2025
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 17
Network Programming and Security Instructor Manual - 2025
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 18
Network Programming and Security Instructor Manual - 2025
• 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
IP_MULTICAST_TTL yes yes
IP_MULTICAST_IF yes yes
Dept. of CSE,RVCE 19
Network Programming and Security Instructor Manual - 2025
IP_ADD_MEMBERSHIP yes no
IP_DROP_MEMBERSHIP yes no
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.
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
Dept. of CSE,RVCE 20
Network Programming and Security Instructor Manual - 2025
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
4. The private key is a pair of numbers (d, n) and the public key is also a pair of numbers (e, n)
Dept. of CSE,RVCE 21
Network Programming and Security Instructor Manual - 2025
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 22
Network Programming and Security Instructor Manual - 2025
Dept. of CSE,RVCE 23
Network Programming and Security Instructor Manual - 2025
}
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");
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);
}
Dept. of CSE,RVCE 24
Network Programming and Security Instructor Manual - 2025
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
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.
Dept. of CSE,RVCE 25
Network Programming and Security Instructor Manual - 2025
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(){
printf("Enter the no. of vertices : ");
scanf("%d",&n);
printf("Enter the adjacency matrix\n");
inti,j;
for(i=0;i<n;i++)
for(j=0;j<n;j++)
scanf("%d",&A[i][j]);
int source;
for(source=0;source<n;source++){
for(i=0;i<n;i++){
d[i] = 999;
Dept. of CSE,RVCE 26
Network Programming and Security Instructor Manual - 2025
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
Router 1
0 <- 1 Cost 1
1 Cost 0
2 <- 1 Cost 3
4 <- 1 Cost 9
Dept. of CSE,RVCE 27
Network Programming and Security Instructor Manual - 2025
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
Note- Use IP header fields obtained using wireshark packet analyzer tool
Dept. of CSE,RVCE 28
Network Programming and Security Instructor Manual - 2025
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");
}
OUTPUT
Values obtained from wireshark:
4500 003c 1c46 4000 4006 b1e6 ac10 0a63 ac10 0a0c
Dept. of CSE,RVCE 29
Network Programming and Security Instructor Manual - 2025
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
PROGRAM
#include <stdlib.h>
#include<stdio.h>
Dept. of CSE,RVCE 30
Network Programming and Security Instructor Manual - 2025
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");
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]);
Dept. of CSE,RVCE 31
Network Programming and Security Instructor Manual - 2025
}
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;
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;
Dept. of CSE,RVCE 32
Network Programming and Security Instructor Manual - 2025
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:
110
recieved word is error, position- 6th bit from right
Corrected codeword is
1 0 1 1 0 0 1
Dept. of CSE,RVCE 33
Network Programming and Security Instructor Manual - 2025
2. Initialize a sockaddr_in structure with the destination group IP address and port
number.
3. Set the IP_MULTICAST_LOOP socket option according to whether the sending
system should receive a copy of the multicast datagrams that are transmitted.
4. Set the IP_MULTICAST_IF socket option to define the local interface over which
you want to send the multicast datagrams.
5. Send the datagram.
PROGRAM
/*Listener*/
#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>
Dept. of CSE,RVCE 34
Network Programming and Security Instructor Manual - 2025
charmsgbuf[MSGBUFSIZE];
}
puts(msgbuf);
}
}
/*Sender*/
#include <sys/types.h>
#include <sys/socket.h>
Dept. of CSE,RVCE 35
Network Programming and Security Instructor Manual - 2025
#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
exam@dell:~$ ./sender // Starts sending messages
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
Dept. of CSE,RVCE 36
Network Programming and Security Instructor Manual - 2025
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>
Dept. of CSE,RVCE 37
Network Programming and Security Instructor Manual - 2025
//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);
}
/*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>
Dept. of CSE,RVCE 38
Network Programming and Security Instructor Manual - 2025
{
int n;
int bufsize = 10240;
char *buffer = malloc(bufsize);
//printf("inside the function");
while((n=recv(connfd, buffer, bufsize, 0))>0) {
fputs("client:",stdout);
fputs(buffer,stdout);
fputs("Me:",stdout);
if(fgets(buffer,bufsize,stdin)!=NULL)
{
send(connfd, buffer, sizeof(buffer), 0);
}
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);
int i = getpeername(connfd,(struct sockaddr *)&cli_address,&addrlen);
if((pid=fork())==0)
{
printf("inside child\n");
close(listenfd);
str_echo(connfd);
exit(0);
}
Dept. of CSE,RVCE 39
Network Programming and Security Instructor Manual - 2025
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);
str_cli(stdin,create_socket);
return close(create_socket);
}
/*server*/
#include<sys/types.h>
#include<sys/socket.h>
#include<netinet/in.h>
Dept. of CSE,RVCE 40
Network Programming and Security Instructor Manual - 2025
#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));
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);
Dept. of CSE,RVCE 41
Network Programming and Security Instructor Manual - 2025
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>
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);
Dept. of CSE,RVCE 42
Network Programming and Security Instructor Manual - 2025
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;
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 ;
}
Dept. of CSE,RVCE 43
Network Programming and Security Instructor Manual - 2025
/*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>
#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 ()
{
Dept. of CSE,RVCE 44
Network Programming and Security Instructor Manual - 2025
{
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 (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)
Generating Private Key
1. Compute z=(p-1)*(q-1)
2. Determine the private key d= (k*z+1)/e, for some integer k.
3. Private key is d.
Diffie Hallman algorithm
Dept. of CSE,RVCE 45
Network Programming and Security Instructor Manual - 2025
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;
}
int main()
{
longinti, len;
longint p, q, n, phi, e, d, cipher[50];
char text[50];
Dept. of CSE,RVCE 46
Network Programming and Security Instructor Manual - 2025
len = strlen(text);
do {
p = rand() % 30;
} while (!isprime(p));
do {
q = rand() % 30;
} while (!isprime(q));
n = p * q;
phi = (p - 1) * (q - 1);
do {
e = rand() % phi;
} while (gcd(phi, e) != 1);
do {
d = rand() % phi;
} while (((d * e) % phi) != 1);
cout<< "Two prime numbers (p and q) are: " << p << " and " << q <<endl;
cout<< "n(p * q) = " << p << " * " << q << " = " << p*q <<endl;
cout<< "(p - 1) * (q - 1) = "<< phi <<endl;
cout<< "Public key (n, e): (" << n << ", " << e << ")\n";
cout<< "Private key (n, d): (" << n << ", " << d << ")\n";
for (i = 0; i<len; i++)
cipher[i] = encrypt(text[i], n, e);
cout<< "Encrypted message: ";
for (i = 0; i<len; i++)
cout<< cipher[i];
for (i = 0; i<len; i++)
text[i] = decrypt(cipher[i], n, d);
cout<<endl;
cout<< "Decrypted message: ";
for (i = 0; i<len; i++)
cout<< text[i];
cout<<endl;
return 0;
}
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
Public key (n, e): (299, 103)
Private key (n, d): (299, 223)
Encrypted message: 11419683758318475
Decrypted message: rvcecse
Dept. of CSE,RVCE 47
Network Programming and Security Instructor Manual - 2025
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 48
Network Programming and Security Instructor Manual - 2025
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
PARTB Rubrics:
Marks Obtained:
Marks
Criteria Excellent Good Poor
Obtained
Selects the most Topic choice is
Topic choice is
NPS topic Choice suitable and latest NPS somewhat
incorrect or lacks
topic with proper appropriate but could
justification.
05 marks reasoning. be improved.
(0 - 1 M)
(5 M) (2 - 4 M)
Network concepts
Network and Uses optimal NPS with Uses inefficient or
used are appropriate
security concept clear reasoning for inappropriate
but may not be
used selection. concepts
optimal.
05 marks (5 M) (0 - 1 M)
(2 - 4 M)
Provides accurate
Methodology and
Methodology and methodology and Design is missing or
design has minor
design design with proper incorrect.
errors.
05 marks justification. (0 - 1 M)
(2 - 4 M)
(5 M)
Code is correct, Code is mostly Code is incorrect,
Implementation and optimized, and correct but may inefficient, or does
testing efficiently implements contain inefficiencies not execute
the topic or minor bugs. properly.
03 marks
(3 M) (1 – 2 M) (0 M)
Demonstration and Well presented with Moderately presented
Not satisfactory.
presentation emphasis on relevance. with justification.
(0 M)
(2 M) (1 M)
Dept. of CSE,RVCE 49
Network Programming and Security Instructor Manual - 2025
Marks
Criteria Excellent Good Poor
Obtained
02 marks
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?
Dept. of CSE,RVCE 50
Network Programming and Security Instructor Manual - 2025
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.
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.
Dept. of CSE,RVCE 51
Network Programming and Security Instructor Manual - 2025
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.
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.
Dept. of CSE,RVCE 52
Network Programming and Security Instructor Manual - 2025
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 53
Network Programming and Security Instructor Manual - 2025
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 54
Network Programming and Security Instructor Manual - 2025
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 55
Network Programming and Security Instructor Manual - 2025
29. In the hierarchical design of domain name space, the inverted tree structure can
have levels from level _________ to level ___________.
Dept. of CSE,RVCE 56