Unix Network Programming
Unix Network Programming
PROGRAMMING
Lecture – IP Addressing
2
Notation
• Three common notations to show an IPv4 address:
• Displayed as 32 bits
• Each number is in
between 0 and 255
• Written in decimal form with a decimal point(dot)
separating the bytes.
4
Classful Addressing
• IPv4 was designed with a fixed length prefix.
• To accommodate both small and large networks, three fixed
length prefixes were designed instead of one
– i.e. n=8, n=16 and n=24
• The whole address space was divided into 5 classes
– Class A,B,C,D and E
• This scheme is referred to as classful addressing
Occupation of the address space in classful addressing:
5
Classes of IP addresses
0.0.0.0 – 127.255.255.255
128.0.0.0 – 191.255.255.255
192.0.0.0 – 223.255.255.255
224.0.0.0 – 239.255.255.255
240.0.0.0 – 255.255.255.255
• Class A
– First octet defines the prefix/netid and first bit is fixed
– Max. no of network possible: 27-2=126
– All zero and all one values can not be used
– 24 bits are used for hostid
– Max no of hosts 224-2=16,777,214 per network can be connected to a class A
network 6
Classful Addressing cont…
• Class B
– First two octet define the prefix and two left bits are fixed :
214-2=16,382 networks
– 216-2=65,534 hosts/network
Class C: First three octet defines prefix and
three bits fixed
221-2=2,097,151 networks
28-2=254 hosts/network
Class D: No prefix and suffix
First four bits are fixed, remaining 24 bits define
multicast addresses?
Class E: No use 7
Address Depletion
• Inefficient use of address space leads to waste of limited IP
address space.
Example:
• Class A can be assigned to only 128 organizations in the world.
– Each organization need to have one single network(seen by
the rest of the world), with 16,777,216 nodes
– As there are only few such large organizations, most of the
addresses were wasted (unused).
• Many of the addresses remains unused in Class B addresses
designed for midsize organizations.
• The number of addresses in Class C was small
– companies were not comfortable using a block
• Class E addresses were almost never used, wasting the whole
class
8
Strategies to alleviate address depletion:
Subnetting:
• Divide a large block into smaller ones
– class A or class B block can be divided into several subnets
• Each subnet has a larger prefix length than the original
network.
• Most organizations do not want to divide the blocks and
provide some addresses to small organizations.
Supernetting:
• Combine several class C blocks into a large block to be
attractive to the organizations, that needs more than 256
addresses available in a class C block.
• Makes routing of packets more difficult
9
Advantage of Classful Addressing
• The class of the address can be easily found
from a given address.
• Since the prefix length for each class is fixed,
the prefix length can be found out
immediately.
• i.e. no extra information is needed to extract
the prefix and the suffix
10
Classless Addressing
• The class privilege was removed from the distribution to
compensate for the address depletion.
• The whole address space is divided into variable length
blocks.
• The prefix in an address defines the block(network); the suffix
defines the nodes(devices).
• Restriction: the number of addresses in a block needs to be a
power of 2.
Variable-length blocks in classless addressing:
11
Classless Addressing cont…
• The size of the network is inversely proportional to the length
of the prefix.
– i.e. Small prefix means a larger network; Large prefix means
a smaller network
• The idea of classless addressing can be easily applied to
classful addressing
– An address in class A can be thought of as a classless
address in which the prefix length is 8
– An address in class B can be thought of as a classless
address in which the prefix length is 16, and so on
– i.e. classful addressing is a special case of classless addressing
12
Issues in classless addressing
• Prefix length: Slash Notation
– How to find the prefix length if an address is
given?
• Extracting information from an address
• Address Mask
• Network address
• Block allocation
– how are the blocks allocated?
• Address Aggregation
• Special Addresses 13
Prefix Length: Slash Notation
• The length of the prefix is need to be specified
separately.
– i.e. the prefix length, n is added to the address, separated by
a slash.
• This notation is formally referred to as Classless
InterDomain Routing (CIDR).
14
Extracting information from an address
• Given any address in the block, three piece of
information about the block to which the address
belongs:
– The number of addresses
– Range of addresses
• The first address in the block
• Last address
16
Example-1
17
Example-1
1.The number of addresses in the network is:
232− n= 25 = 32 addresses. (as n=27 here)
2. The first address can be found by keeping the first 27 bits and
changing the rest of the bits to 0s.
The last address can be found by keeping the first 27 bits and
changing the rest of the bits to 1s.
18
•
Address Mask
Another way to find the first and last addresses in the block.
• Address mask is a 32-bit number,
– n leftmost bits are set to 1s and rest (32-n) are set to 0s
• The mask can be used by the computer program to extract information in a
block using 3 bitwise operations
1. The number of addresses in the block N = NOT(Mask)+1
2. The first address in the block= (any address) AND (Mask)
3. The last address in the block= (any add.) OR [(NOT(Mask))]
19
Example 2: Add: 167.199.170.80, Mask: 255.255.255.224
1. Number of Addresses = NOT(255.255.255.224) + 1
0.0.0.31 + 1 = 32
2. First Address = 167.199.170.80 AND 255.255.255.224
167.199.170.64
3. Last Address = 167.199.170.80 OR (NOT(255.255.255.224))
167.199.170.80 OR 0.0.0.31 = 167.199.170.95
20
End of Lecture
Thank You
21