Note that it is perfectly valid to omit the penultimate zero value octets. You can play around with this in the following one-liner:

% perl -MSocket -e 'print inet_aton shift' 65.0.0.65|hexdump 0000000 0041 4100 0000004 % perl -MSocket -e 'print inet_aton shift' 65.65|hexdump 0000000 0041 4100 0000004

That is, there exists a shorthand for x.0.0.y and x.y.0.z (but not x.0.y.z). To complete the picture, you can also do this for 0.0.0.x, but that's hardly ever useful.

Which is another reason why inet_aton is such a good idea.

<update> Re your 01.1.1.010 problem, there is an issue you should be aware of. A leading 0 in a string, signals octal (assuming you're trying to interpret the string as a number). Consider the following:

% perl -MSocket -le 'print inet_ntoa inet_aton shift' 01.1.1.10 1.1.1.10 % perl -MSocket -le 'print inet_ntoa inet_aton shift' 01.1.1.010 1.1.1.8

Note that I don't see the behaviour you describe, although I'd be loathe to consider this the work of an interfering shell. If this is really a problem, I'd be inclined to do a simple cleanup prior to calling inet_aton with something like (untested):

my $_IP = inet_aton( join '.', map { s/^0([1-9]\d*)$/$1/; $_ } # strip leading zeroes split( /\./, $original_ip) # of each octet );
</update>
print@_{sort keys %_},$/if%_=split//,'= & *a?b:e\f/h^h!j+n,o@o;r$s-t%t#u'

In reply to Re: IP Sanity Check by grinder
in thread IP Sanity Check by jupe

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.