IPv4 address validation in Net::IP

J

Jigs

Hi All,

I was using the Net::IP module from CPAN and the function to validate
an IP address allows single numbers to be a valid address. Here is the
snippet from the function ip_is_ipv4:

# Single Numbers are considered to be IPv4
if ($ip =~ m/^(\d+)$/ and $1 < 256) { return 1 }

# Count quads
my $n = ($ip =~ tr/\./\./);

# IPv4 must have from 1 to 4 quads
unless ($n >= 0 and $n < 4) {
$ERROR = "Invalid IP address $ip";
$ERRNO = 105;
return 0;
}

Can someone please explain why single numbers are valis IP addresses?

Thank in advance ...
Jigs
 
J

Joe Smith

Jigs said:
Can someone please explain why single numbers are valis IP addresses?

IPv4 address are 32-bit numbers, which can be shown in several ways.
"127.1" is perfectly valid; it is the same as "127.0.0.1".

The following IP address are all the same:

1113982867 = 66.6686611 = 66.102.1939 = 66.102.7.147 = 0x42660793

If you don't believe me, try http://1113982867/search?q=IPv4

-Joe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top