in reply to INET_NTOA Equivalent

In case you dont want to load a module for this purpose, here is some code you can use (For IPv4):
sub to_dotquad { # Given a binary int IP, returns dotted-quad (Reverse of ip2num) my $bin = shift; my $result = ''; # Empty string for (24,16,8,0){ $result .= ($bin >> $_ & 255) . '.'; } chop $result; # Delete extra trailing dot return $result; }

Offense, like beauty, is in the eye of the beholder, and a fantasy.
By guaranteeing freedom of expression, the First Amendment also guarntees offense.

Replies are listed 'Best First'.
Re^2: INET_NTOA Equivalent
by atcroft (Abbot) on Apr 15, 2004 at 02:53 UTC

    Here's one more potential way to do it, without loading additional modules. Assuming the IPv4 address is in $address (and of a form matching m/((\d{1,3}\.){3}(\d{1,3}))/ ), then:

    $ip_as_long = unpack("N", pack("C4", split(/\D/, $address, 4))); $ip_as_string = join('.', unpack("C4", pack("N", $ip_as_long)));

    Hope that helps...