IPv4 address validation in Net::IP

Discussion in 'Perl Misc' started by Jigs, Nov 7, 2006.

  1. Jigs

    Jigs Guest

    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
     
    Jigs, Nov 7, 2006
    #1
    1. Advertising

  2. Jigs wrote:
    > Can someone please explain why single numbers are valis IP addresses?


    Have you tried Google? It's not a Perl question.

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
     
    Gunnar Hjalmarsson, Nov 7, 2006
    #2
    1. Advertising

  3. Jigs

    Joe Smith Guest

    Jigs wrote:

    > 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
     
    Joe Smith, Nov 9, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ben
    Replies:
    0
    Views:
    573
  2. Christian Reiser

    Schema for IPv4: valid or not?

    Christian Reiser, Aug 13, 2004, in forum: XML
    Replies:
    0
    Views:
    544
    Christian Reiser
    Aug 13, 2004
  3. qazmlp

    code for validating IPv4 address

    qazmlp, Jul 27, 2003, in forum: C Programming
    Replies:
    14
    Views:
    1,011
    Default User
    Jul 29, 2003
  4. tweak
    Replies:
    14
    Views:
    2,797
    Eric Sosman
    Jun 11, 2004
  5. xxyyzz
    Replies:
    3
    Views:
    1,854
Loading...

Share This Page