Advanced Computer Networks Practical File
Advanced Computer Networks Practical File
Advanced Computer Networks Practical File
COMPUTER
NETWORKS
PRACTICAL FILE
BY NEHA ROY
ROLL NO-057
INDEX
DAT TOPIC SIGN
E
IPv4 uses 32-bit (four-byte) addresses, which limits the address space to
4,294,967,296 (232) possible unique addresses. However, some are reserved for
special purposes such as private networks (~18 million addresses) or multicast
addresses (~16 million addresses). This reduces the number of addresses that can
potentially be allocated for routing on the public Internet. As addresses are being
incrementally delegated to end users, an IPv4 address shortage has been developing,
however network addressing architecture redesign via classful network design,
Classless Inter-Domain Routing, and network address translation (NAT) has
significantly delayed the inevitable exhaustion.
This limitation has stimulated the development of IPv6, which is currently in the early
stages of deployment, and is the only long-term solution.
IPv6 has a vastly larger address space than IPv4. This results from the use of a 128-bit
address, whereas IPv4 uses only 32 bits. The new address space thus supports 2128
(about 3.4×1038) addresses. This expansion provides flexibility in allocating addresses
and routing traffic and eliminates the primary need for network address translation
(NAT), which gained widespread deployment as an effort to alleviate IPv4 address
exhaustion.
IPv6 also implements new features that simplify aspects of address assignment
(stateless address auto configuration) and network renumbering (prefix and router
announcements) when changing Internet connectivity providers. The IPv6 subnet size
has been standardized by fixing the size of the host identifier portion of an address to
64 bits to facilitate an automatic mechanism for forming the host identifier from Link
Layer media addressing information (MAC address).
Network security is integrated into the design of the IPv6 architecture. Internet Protocol
Security (IP sec) was originally developed for IPv6, but found widespread optional
deployment first in IPv4 (into which it was back-engineered). The IPv6 specifications
mandate IP sec implementation as a fundamental interoperability requirement
The fixed header makes up the first 40 octets (320 bits) of an IPv6 data packet. The
format of the fixed header is presented in the table below. The octet (byte) offsets are in
hexadecimal (base 16) and the bit offsets are in decimal (base 10).
Octe
t
0 1 2 3
Offs
et
Bit
Offse 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
t
8 64
C 96
Source Address
10 128
14 160
18 192
1C 224
Destination Address
20 256
24 288
The protocol field of IPv4 is replaced with a next header field. This field usually
specifies the transport layer protocol used by a packet's payload. In the presence of
options, however, the next header field specifies the presence of one or more out of six
extension headers, which then follow the IPv6 header in distinct order; the payload's
protocol itself is specified in the next header field of the last extension header.
2. To determine the class of IP address from the input
binary notation.
Classful Addressing
Computers communicating using Internet Protocol (IP)
send datagrams. IP datagram contain a source IP address, and a destination IP
address. However, an IP datagram does not contain any network subnet mask
information, thus it is difficult to know which groups of computers (hosts) formed
a network.
Source Address
The IP address of the host that sent the datagram (sender).
Destination Address
The IP address of the host the datagram is being sent to (receiver).
CLASSES
The different classes of IP addresses (Class A, Class B, Class C, Class D & Class E)
were created to allow for carving up the entire set of all IP addresses into chunks of
different sizes that would 'fit' the number of hosts on the network for which
the IP address space was being supplied.
A a.b.c.d a b.c.d
C a.b.c.d a.b.c D
Class A: Class A addresses are specified to networks with large number of total hosts.
Class A allows for 126 networks by using the first octet for the network ID. The first bit
in this octet, is always set and fixed to zero. And next seven bits in the octet is all set to
one, which then complete network ID. The 24 bits in the remaining octets represent the
hosts ID, allowing 126 networks and approximately 17 million hosts per network. Class
A network number values begin at 1 and end at 127.
Class B: Class B addresses are specified to medium to large sized of networks. Class
B allows for 16,384 networks by using the first two octets for the network ID. The two
bits in the first octet are always set and fixed to 1 0. The remaining 6 bits, together with
the next octet, complete network ID. The 16 bits in the third and fourth octet represent
host ID, allowing for approximately 65,000 hosts per network. Class B network number
values begin at 128 and end at 191.
Class C: Class C addresses are used in small local area networks (LANs). Class C
allows for approximately 2 million networks by using the first three octets for the
network ID. In class C address three bits are always set and fixed to 1 1 0. And in the
first three octets 21 bits complete the total network ID. The 8 bits of the last octet
represent the host ID allowing for 254 hosts per one network. Class C network number
values begin at 192 and end at 223.
Class D and E: Classes D and E are not allocated to hosts. Class D addresses are
used for multicasting, and class E addresses are not available for general use: they are
reserved for future purposes
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<iostream.h>
#include<string.h>
#include<process.h>
void main()
{
char add[50];
clrscr();
cout<<"\n Enter IP address in binary notation:\n";
gets(add);
00000001000010110000101111101111
1. Physical Address :
2. Logical Address
The hosts and routers are recognized at the network level by their logical addresses. A
logical address is an internetwork address. Its jurisdiction is universal. It is unique
universally. It is called a logical address because it is usually implemented in software.
Every protocol that deals with interconnecting networks requires logical addresses .
The logical addresses in the TCP/IP protocol suite are called IP addresses and are 32
bits long.
3. Port Address
Today computers are devices that can run multiple processes at the same time. The
end objective of Internet communication is a process communicating with another
process. For processes to occur simultaneously, we need a method to label different
processes. In TCP/IP architecture , the label assigned to a process is called a port
address. A port address in TCP/IP is 16 bits long
Delivery of a packet to a host or a router requires two levels of addressing : logical and
physical . We need to be able to map a logical address to its corresponding physical
address and vice versa. These can be done using either static mapping or dynamic
mapping.
Static mapping means creating a table that associates a logical address with a
physical address. This table is stored in each machine on the network. Each machine
that knows the IP address of another machine but not its physical address can look it
up in the table. But it has some limitations
In dynamic mapping each time a machine knows one of the two addresses , it can use
a protocol to find the other one. Two protocols have been designed to perform dynamic
mapping: address resolution protocol ( ARP – maps logical address to physical address
) and reverse address resolution protocol ( RARP – maps physical address to logical
address ).
ARP
1. The machine gets its physical address (by reading its NIC) which is unique
locally.
2. A RARP request is created and broadcast on the local network.
3. This packet is received by every host (or router) on the physical network but only
RARP server will answer it.
4. The server sends a RARP reply packet that includes the IP address of the
requestor.
#include<conio.h>
#include<iostream.h>
#include<stdio.h>
#include<string.h>
#include<ctype.h>
struct arp
{
char ip[40];
char nic[10];
char type;
arp * next;
}*first,*cur;
void init();
void find();
int valid(char ip[35]);
void main()
{
clrscr();
first=cur=NULL;
init();
find();
getch();
}
void init()
{
temp->next=NULL;
if(first==NULL)
{
first=temp;
cur=temp;
}
else
{
cur->next=temp;
cur=temp;
}
}
cout<<"\nwant to enter more?";
cin>>rep;
}while(rep=='y'||rep=='Y');
}
void find()
{
arp *temp,*ptr;
char ip[40],rep='y',nic[10];
int flag,val=1;
do{
flag=1;
ptr=first;
cout<<"\nenter ip address to find:";
gets(ip);
val=valid(ip);
if(val==1)
cout<<"\ninvalid ip address";
else
{
while(ptr!=NULL)
{
if(strcmp(ptr->ip,ip)==0)
{
cout<<"\nphysical address of entered ip is:"<<ptr->nic;
flag=0;
break;
}
ptr=ptr->next;
}
if (flag!=0)
{
cout<<"\nrecord does not exist.enter physical address:";
gets(nic);
temp=new arp;
strcpy(temp->ip,ip);
strcpy(temp->nic,nic);
temp->type='p';
temp->next=NULL;
cur->next=temp;
cur=cur->next;
}
}
cout<<"\nwant to enter more?";
cin>>rep;
}while(rep=='y'||rep=='Y');
}
enter ip address:10101010.01010101.10101010.01010101
In link state routing.four sets of actions are recquired to ensure that each node has the
routing table showing the least cost node to every other node.
1.creation of the states of links by each node, called the link state packet.
}
print();
}
int smallest()
{
int temp=tem[1],z=1;
for(i=1;i<=n;i++)
{
if(tem[i]<temp)
{temp=tem[i];
z=i;
}
}
return(z);
}
void print()
{ cout<<"\nthe routing table for node"<<y<<":\n";
cout<<"To\tCost\tNext\n";
for(j=1;j<=n;j++)
{
cout<<j<<"\t"<<per[j]<<"\t"<<next[j]<<"\n";
}
}
OUTPUT
enter the no. of nodes 3
1-2:4
1-3:3
2-1:2
2-3:5
3-1:1
3-2:3
13
To Cost Next
1 2 0
2 0 0
3 5 0
Client-server describes the relationship between two computer programs in which one
program, the client program, makes a service request to another, the server program.
Standard networked functions such as email exchange, web access and database
access, are based on the client-server model. For example, a web browser is a client
program at the user computer that may access information at any web server in the
world. To check your bank account from your computer, a web browser client program
in your computer forwards your request to a web server program at the bank. That
program may in turn forward the request to its own database client program that sends
a request to a database server at another bank computer to retrieve your account
balance. The balance is returned to the bank database client, which in turn serves it
back to the web browser client in your personal computer, which displays the
information for you.
The client-server model has become one of the central ideas of network computing.
Many business applications being written today use the client-server model. So do the
Internet's main application protocols, such as HTTP, SMTP, Telnet, DNS. In marketing,
the term has been used to distinguish distributed computing by smaller dispersed
computers from the "monolithic" centralized computing of mainframe computers. But
this distinction has largely disappeared as mainframes and their applications have also
turned to the client-server model and become part of network computing.
Each instance of the client software can send data requests to one or more connected
servers. In turn, the servers can accept these requests, process them, and return the
requested information to the client. Although this concept can be applied for a variety of
reasons to many different kinds of applications, the architecture remains fundamentally
the same.
The most basic type of client-server architecture employs only two types of hosts:
clients and servers. This type of architecture is sometimes referred to as two-tier. It
allows devices to share files and resources. The two tier architecture means that the
client acts as one tier and application in combination with server acts as another tier.
Specific types of clients include web browsers, email clients, and online chat clients.
Specific types of servers include web servers, ftp servers, application servers, database
servers, name servers, mail servers, file servers, print servers, and terminal servers.
Most web services are also types of servers.
//package ServerClient;
import java.net.*;
public class Main {
int pos = 0;
while(true) {
int c = System.in.read();
switch (c) {
case -1:
System.out.println("Server Quits....");
return;
case '\r':
break;
case '\n':
ds.send(new
DatagramPacket(buffer,pos,InetAddress.getLocalHost(),clientPort));
pos = 0;
break;
default:
buffer[pos++] = (byte) c;
while(true) {
DatagramPacket p = new DatagramPacket(buffer,buffer.length);
ds.receive(p);
System.out.println(new String(p.getData(),0,p.getLength()));
if(args.length == 1) {
TheServer();
else {
TheClient();
The main classical cipher types are transposition ciphers, which rearrange the order of
letters in a message (e.g., 'hello world' becomes 'ehlol owrdl' in a trivially simple
rearrangement scheme), and substitution ciphers, which systematically replace letters
or groups of letters with other letters or groups of letters (e.g., 'fly at once' becomes
'gmz bu podf' by replacing each letter with the one following it in the Latin alphabet).
Simple versions of either offered little confidentiality from enterprising opponents, and
still don't. An early substitution cipher was the Caesar cipher, in which each letter in the
plaintext was replaced by a letter some fixed number of positions further down the
alphabet. It was named after Julius Caesar who is reported to have used it, with a shift
of 3, to communicate with his generals during his military campaigns, just like EXCESS-
3 code in boolean algebra.
Symmetric-key cryptography
Symmetric-key cryptography refers to encryption methods in which both the sender and
receiver share the same key (or, less commonly, in which their keys are different, but
related in an easily computable way). This was the only kind of encryption publicly
known until June 1976.
The modern study of symmetric-key ciphers relates mainly to the study of block ciphers
and stream ciphers and to their applications. A block cipher is, in a sense, a modern
embodiment of Alberti's polyalphabetic cipher: block ciphers take as input a block of
plaintext and a key, and output a block of ciphertext of the same size. Since messages
are almost always longer than a single block, some method of knitting together
successive blocks is required. Several have been developed, some with better security
in one aspect or another than others. They are the modes of operation and must be
carefully considered when using a block cipher in a cryptosystem.
The Data Encryption Standard (DES) and the Advanced Encryption Standard
(AES) are block cipher designs which have been designated cryptography standards
by the US government (though DES's designation was finally withdrawn after the AES
was adopted). Despite its deprecation as an official standard, DES (especially its still-
approved and much more secure triple-DES variant) remains quite popular; it is used
across a wide range of applications, from ATM encryption to e-mail privacy and secure
remote access. Many other block ciphers have been designed and released, with
considerable variation in quality. Many have been thoroughly broken.
Public-key cryptography
Symmetric-key cryptosystems use the same key for encryption and decryption of a
message, though a message or group of messages may have a different key than
others. A significant disadvantage of symmetric ciphers is the key management
necessary to use them securely. Each distinct pair of communicating parties must,
ideally, share a different key, and perhaps each ciphertext exchanged as well. The
number of keys required increases as the square of the number of network members,
which very quickly requires complex key management schemes to keep them all
straight and secret. The difficulty of securely establishing a secret key between two
communicating parties, when a secure channel doesn't already exist between them,
also presents a chicken-and-egg problem which is a considerable practical obstacle for
cryptography users in the real world.
In a groundbreaking 1976 paper, Whitfield Diffie and Martin Hellman proposed the
notion of public-key (also, more generally, called asymmetric key) cryptography in
which two different but mathematically related keys are used — a public key and a
private key. A public key system is so constructed that calculation of one key (the
'private key') is computationally infeasible from the other (the 'public key'), even though
they are necessarily related. Instead, both keys are generated secretly, as an
interrelated pair.
In public-key cryptosystems, the public key may be freely distributed, while its paired
private key must remain secret. The public key is typically used for encryption, while the
private or secret key is used for decryption.
Public-key algorithms are most often based on the computational complexity of "hard"
problems, often from number theory. For example, the hardness of RSA is related to
the integer factorization problem. More recently, elliptic curve cryptography has
developed in which security is based on number theoretic problems involving elliptic
curves. Because of the difficulty of the underlying problems, most public-key algorithms
involve operations such as modular multiplication and exponentiation, which are much
more computationally expensive than the techniques used in most block ciphers,
especially with typical key sizes. As a result, public-key cryptosystems are commonly
hybrid cryptosystems, in which a fast high-quality symmetric-key encryption algorithm is
used for the message itself, while the relevant symmetric key is sent with the message,
but encrypted using a public-key algorithm. Similarly, hybrid signature schemes are
often used, in which a cryptographic hash function is computed, and only the resulting
hash is digitally signed.
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
void main()
{
char inputstr1[10],inputstr2[10], encrptstr[10],outptstr[10];
int i, ch;
cout<<"What do u want to do?"<<endl;
cout<<"1) Encryption"<<endl;
cout<<"2) Decryption"<<endl;
cin>>ch;
if(ch==1)
{
cout<<"Enter string to be encrypted(0-9 only)";
gets(inputstr);
else if (ch==2)
{
cout<<"Enter string to be decrypted(a to j only)";
gets(inputstr2);
1. Encryption.
2. Decryption
1. Encryption.
2. Decryption
The Data Link Layer is the protocol layer which transfers data between adjacent
network nodes in a wide area network or between nodes on the same local area
network segment. The Data Link Layer provides the functional and procedural means
to transfer data between network entities and might provide the means to detect and
possibly correct errors that may occur in the Physical Layer. Examples of data link
protocols are Ethernet for local area networks (multi-node), the Point-to-Point Protocol
(PPP), HDLC and ADCCP for point-to-point (dual-node) connections.
The Data Link Layer is concerned with local delivery of frames between devices on the
same LAN. Data Link frames, as these protocol data units are called, do not cross the
boundaries of a local network. Inter-network routing and global addressing are higher
layer functions, allowing Data Link protocols to focus on local delivery, addressing, and
media arbitration. In this way, the Data Link layer is analogous to a neighborhood traffic
cop; it endeavors to arbitrate between parties contending for access to a medium.
When devices attempt to use a medium simultaneously, frame collisions occur. Data
Link protocols specify how devices detect and recover from such collisions, but it does
not prevent them from happening.
The data link thus provides data transfer across the physical link. That transfer can be
reliable or unreliable; many data link protocols do not have acknowledgments of
successful frame reception and acceptance, and some data link protocols might not
even have any form of checksum to check for transmission errors. In those cases,
higher-level protocols must provide flow control, error checking, and acknowledgments
and retransmission.
Within the semantics of the OSI network architecture, the Data Link Layer protocols
respond to service requests from the Network Layer and they perform their function by
issuing service requests to the Physical Layer.
#include<stdio.h>
#include<conio.h>
void main()
{
char st[100];
int arr[25][8];
int i=0,n=0,m=0,j;
clrscr();
printf("\n\n Enter the message to be sent (string of bits not more than 12
bytes):\n\n ");
gets(st);
printf("\n\n\n The following packets (with header and trailer) will be sent:\n\n");
while(st[i]!='\0')
{
arr[m][n++]='1'; arr[m][n++]='0';
for(j=i;j<i+4 && st[j]!='\0';j++)
arr[m][n++]=st[j];
arr[m][n++]='1';
arr[m++][n]='\0';
n=0;
i=j;
}
for(i=0;i<m;i++)
{
printf("\n Packet %d : ",i+1);
for(j=0;arr[i][j]!='\0';j++)
printf("%c",arr[i][j]);
}
getch();
}
OUTPUT
Enter the message to be sent(string of bits not more than 12 bytes):
11111111111
Packet1 :1011111
Packet1 :1011111
Packet1 :101111