Sie sind auf Seite 1von 30

Addressing

Addressing:
Introduction
IPv4 Addresses
Address Space
Notations
Classful Addressing
Introduction:
•IP Address is used to identify each devices connected on a
network
•A unique identifier
•A numerical label
Introduction

•Two Types –Physical and Logical


•Physical Addressing
- Generated by MAC sub-layer, so termed as MAC Address
- Denotes hardware address of Ethernet card
- Cannot be changed
- 48 bit long
Introduction
Logical Addressing
It is logical
Virtual address which is viewable by the user program
Changeable

 Two types – IPv4 and IPv6


 IPv4 is 32 bit long and IPv6 is 128 bit long
A logical network address that identifies a host in the network
IPV4
Internet Protocol version 4 (IPv4) is the fourth version of the
Internet Protocol (IP).
An IP address is 32-bit long.

Dotted decimal notation (137.207.192.3)

 Octet four hexadecimal numbers (89 CF C0 03)

 Binary notation (11000000101010000000101000000001)


IP usage:

•Used to connect to another computer


•Allows transfer of files and mails
•Used to communicate data
IPv4 ADDRESSES

 An IPv4 address is 32 bits long.

 The address space of IPv4 is 2


32
or 4,294,967,296

 IP address consist of 4 sections

 Each section is 8 bit long

 Each section range from 0 – 255.

 Example: 1.22.33.255
IPv4 ADDRESSES Validation

 1.22.33.255

 00000001000000010000000100000001

 01.22.33.236

 00000001 22.22.13

 -12.134.12.12
int main()

  system("c:\\windows\\system32\\ipconfig");

  return 0;

}
IPv4 ADDRESSES
• Addressing can be divided into classful and classless.
• In classful addressing, the address space is divided into five
classes 5 classes of IP address: A, B, C D, E
• Class A is reserved for governments
• Class B is reserved for medium companies
• Class C is reserved for small companies
• Class D is reserved for multicasting
• Class E is reserved future use
Finding the classes in binary and dotted-decimal notation
Finding the address class
Binary Notation

START

1 1 1 1
1 2 3 4

BIT? BIT? BIT? BIT?

0 0 0
0
Class E
Class A Class B Class C Class D
Netid and hostid
Class Byte 1 Byte 2 Byte 3 Byte 4

Class A Netid Hostid

Class B Netid Hostid

Class C Netid Hostid

Class D Multicast address

Class E Reserved for Future use

Each address in the block can be considered as a two-


level hierarchical structure: the leftmost n bits (prefix)
define the network; the rightmost 32 − n bits define the
host.
Communication categories:
• Unicast: one source to one destination(eg. A,B,C classes)
• Multicast: one source to a group of destination
• Reserved addresses: special purposes.
Classes and Blocks
• Class A is divided into 128 blocks having a different netid.
• First block covers addresses from 0.0.0.0 to 0.255.255.255(netid 0)
• Second block covers addresses from 1.0.0.0 to 1.255.255.255(netid 1)
• Last block covers addresses from 127.0.0.0 to 127.255.255.255(netid
127)
• Number of addresses in each block, 16777216. so many addresses are
wasted in this class.
• Class B
• First block covers addresses from 128.0.0.0 to
128.0.255.255(netid 128.0)
• Last block covers addresses from 191.255.0.0 to
191.255.255.255(netid 191.255)
• Number of addresses in each block, 65536. So many addresses are
wasted in this class.
• Class C
• Range 192 -223
• First block covers addresses from 192.0.0.0 to
223.255.255.255(netid 192.0.0)
• Class D
– Range 224 - 239
– used for multicasting
– not for commercial use
• Class E
– Range 240 - 255
– reserved for experimental use
– not for commercial use
Network address
• Given the address 23.54.22.213, find the network address.
• The class is A, which has only one byte of netid, therefore 23.0.0.0 is
the network address.
• Given the address 193.54.22.213, find the network address.
• The class is C, which has three bytes of netid, therefore the network
address is 193.54.22.0.
• If network address is given, find the class by using the first byte.
• Write a program to validate an IP address using C.
• The IPv4 addresses are represented in dot-decimal notation.
There are four decimal numbers (all are ranging from 0 to 255).
These four numbers are separated by three dots.
• An example of a valid IP is: 192.168.4.1
• To validate the IP address we should follow these steps
• Tokenizing a string denotes splitting a string with respect to a
delimiter.  Tokenize the string (IP address) using the dot “.”
delimiter.
• If the sub strings are containing any non-numeric character,
then return false
• If the number in each token is not in range 0 to 255, then return
false
• If there are exactly three dots and four parts then it is a valid IP
address
#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include <ctype.h>

int validate_number(char *str)

{    while (*str)

{       if(!isdigit(*str)){ //if the character is not a number, return          

false        

 return 0;       }       str++; //point to next character    }  

return 1;

}
int i, num, dots = 0;    

char *ptr;    

if (ip == NULL)      

return 0;      

ptr = strtok(ip, "."); //cut the string using dor delimiter      

if (ptr == NULL)          

return 0;    

while (ptr)

{       if (!validate_number(ptr))

//check whether the sub string is holding only number or not          

return 0;          

num = atoi(ptr); //convert substring to number        

 if (num >= 0 && num <= 255) {            

ptr = strtok(NULL, "."); //cut the next part of the string

if (ptr != NULL)                
return 1;

int main()

char ip1[ ] = "192.168.4.1";

char ip2[ ] = "172.16.253.1";

char ip3[ ] = "192.800.100.1";

char ip4[ ] = "125.512.100.abc";

validate_ip(ip1)? printf("Valid\n"): printf("Not valid\n");

validate_ip(ip2)? printf("Valid\n"): printf("Not valid\n");


Blocks and Hosts

•Each class is divided into blocks. The numbers of block in a class can be

calculated by the number of bits in the netid.

CLASS A

•Class A has 1 byte (8 bits) netid and from the binary notation we see that

Class A address starts with 0 so there are total 7 bits that can be changed out

7
of 8. Therefore total number of blocks in Class A = 2  = 128.

•There are 3 bytes (24 bits) for hostid in Class A so total number of host in
st
1  block of Class A has the netid 0

And the host id is between

0.0.0.0

0.255.255.255

nd
Similarly, 2  block of Class A has the netid 1

And the host id is between

1.0.0.0
Calculate Network address, Subnet mask, Hosts, Broadcast

address in a IP address.(171.12.23.34).

Network address 192.168.0.0

Subnet mask 255.255.255.0

Hosts 192.168.0.1 - 192.168.0.254

Das könnte Ihnen auch gefallen