Monday, May 7, 2012

IPV4 address format validation

This is a usual practice to validate a IPV4 address format read from a configuration file before consuming it. For this one should know what are all the valid IPV4 address formats.

1. IPV4 address consists of 32bits , i.e  in human readable format it is four octets devided by period ( dot)
    A.B.C.D
 Here each octet takes value from 0-255 so the valid IPv4 adress ranges from 0.0.0.0 to 255.255.255.255

2. The following formats are also valid

i.   8
     This address is treated as 32 bit integer so it is equal to 0.0.0.8

ii.   1.8
     In this format first octet is treated as first 8 bits and last octet is treated 24 bits. It is equal to 1.0.0.8

iii.   1.2.8
     In this format first two octets are treated as first 16bits and last octet is treated as next 16 bits of ip address. It is equal to 1.2.0.8

So, to validate any IPV4 address, one should consider all of the above valid IPV4 address formats.
Pin It
Related Posts Plugin for WordPress, Blogger...