NetAddr...::UtilPP(3)

πŸ¦‹ NAME πŸ¦‹

ok so bestie, you're on the NetAddr...::UtilPP(3) page β€” User Contributed Perl Documentation, periodt. The actual NAME is NetAddr::IP::UtilPP -- pure Perl functions for NetAddr::IP::Util. πŸ’…


✨ SYNOPSIS ✨

here's the summoning circle, no cap:

  use NetAddr::IP::UtilPP qw(
        hasbits
        shiftleft
        addconst
        add128
        sub128
        notcontiguous
        ipv4to6
        mask4to6
        ipanyto6
        maskanyto6
        ipv6to4
        bin2bcd
        bcd2bin
  );

  use NetAddr::IP::UtilPP qw(:all)

  $rv = hasbits($bits128);
  $bitsX2 = shiftleft($bits128,$n);
  $carry = addconst($ipv6naddr,$signed_32con);
  ($carry,$ipv6naddr)=addconst($ipv6naddr,$signed_32con);
  $carry = add128($ipv6naddr1,$ipv6naddr2);
  ($carry,$ipv6naddr)=add128($ipv6naddr1,$ipv6naddr2);
  $carry = sub128($ipv6naddr1,$ipv6naddr2);
  ($spurious,$cidr) = notcontiguous($mask128);
  ($carry,$ipv6naddr)=sub128($ipv6naddr1,$ipv6naddr2);
  $ipv6naddr = ipv4to6($netaddr);
  $ipv6naddr = mask4to6($netaddr);
  $ipv6naddr = ipanyto6($netaddr);
  $ipv6naddr = maskanyto6($netaddr);
  $netaddr = ipv6to4($pv6naddr);
  $bcdtext = bin2bcd($bits128);
  $bits128 = bcd2bin($bcdtxt);

🌸 DESCRIPTION 🌸

NetAddr::IP::UtilPP is giving pure Perl functions for NetAddr::IP::Util. obsessed. πŸ’–

  • $rv = hasbits($bits128); β€” this returns true if there are one's present in the 128 bit string, and false if all the bits are zero.

like:

  i.e.  if (hasbits($bits128)) {
          &do_something;
        }

  or    if (hasbits($bits128 & $mask128) {
          &do_something;
        }

This allows the implementation of logical functions of the form of:

        if ($bits128 & $mask128) {
            ...
  • input: 128 bit IPv6 string
  • returns: true if any bits are present
  • $bitsXn = shiftleft($bits128,$n); β€” shift the bits, bestie.
    • input: 128 bit string variable, number of shifts [optional]
    • returns: bits X n shifts
NOTE: input bits are returned if $n is not specified
  • addconst($ipv6naddr,$signed_32con); β€” add a signed constant to a 128 bit string variable. iconic math moment.
    • input: 128 bit IPv6 string, signed 32 bit integer
    • returns: scalar carry; array (carry, result)
  • add128($ipv6naddr1,$ipv6naddr2); β€” add two 128 bit string variables together. cute.
    • input: 128 bit string var1, 128 bit string var2
    • returns: scalar carry; array (carry, result)
  • sub128($ipv6naddr1,$ipv6naddr2); β€” subtract two 128 bit string variables.
    • input: 128 bit string var1, 128 bit string var2
    • returns: scalar carry; array (carry, result)
Note: The carry from this operation is the result of adding the one's complement of ARG2 +1 to the ARG1. It is logically NOT borrow.
        i.e.    if ARG1 >= ARG2 then carry = 1
        or      if ARG1  < ARG2 then carry = 0
  • ($spurious,$cidr) = notcontiguous($mask128); β€” this function counts the bit positions remaining in the mask when the rightmost '0's are removed. vibe check on your netmask.
    • input: 128 bit netmask
    • returns: true if there are spurious zero bits remaining in the mask, false if the mask is contiguous one's, 128 bit cidr
  • $ipv6naddr = ipv4to6($netaddr); β€” convert an ipv4 network address into an ipv6 network address. glow-up protocol.
    • input: 32 bit network address
    • returns: 128 bit network address
  • $ipv6naddr = mask4to6($netaddr); β€” convert an ipv4 netowrk address into an ipv6 network mask.
    • input: 32 bit network/mask address
    • returns: 128 bit network/mask address
NOTE: returns the high 96 bits as one's
  • $ipv6naddr = ipanyto6($netaddr); β€” similar to ipv4to6 except that this function takes either an IPv4 or IPv6 input and always returns a 128 bit IPv6 network address. versatile queen.
    • input: 32 or 128 bit network address
    • returns: 128 bit network address
  • $ipv6naddr = maskanyto6($netaddr); β€” similar to mask4to6 except that this function takes either an IPv4 or IPv6 netmask and always returns a 128 bit IPv6 netmask.
    • input: 32 or 128 bit network mask
    • returns: 128 bit network mask
  • $netaddr = ipv6to4($pv6naddr); β€” truncate the upper 96 bits of a 128 bit address and return the lower 32 bits. Returns an IPv4 address as returned by inet_aton. ok downgrade era but make it cute.
    • input: 128 bit network address
    • returns: 32 bit inet_aton network address
  • $bcdtext = bin2bcd($bits128); β€” convert a 128 bit binary string into binary coded decimal text digits.
    • input: 128 bit string variable
    • returns: string of bcd text digits
  • $bits128 = bcd2bin($bcdtxt); β€” convert a bcd text string to 128 bit string variable.
    • input: string of bcd text digits
    • returns: 128 bit string variable

πŸŽ€ EXPORT_OK πŸŽ€

these are the exportable symbols, no cap:

hasbits
shiftleft
addconst
add128
sub128
notcontiguous
ipv4to6
mask4to6
ipanyto6
maskanyto6
ipv6to4
bin2bcd
bcd2bin
comp128
bin2bcdn
bcdn2txt
bcdn2bin
simple_pack
threads

πŸ‘‘ AUTHOR πŸ‘‘

Michael Robinton <michael@bizsystems.com>


Copyright 2003 - 2012, Michael Robinton <michael@bizsystems.com>

All rights reserved.

This program is free software; you can redistribute it and/or modify it under the terms of either:

  • a) the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version, or
  • b) the "Artistic License" which comes with this distribution.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See either the GNU General Public License or the Artistic License for more details.

You should have received a copy of the Artistic License with this distribution, in the file named "Artistic". If not, I'll be glad to provide one.

You should also have received a copy of the GNU General Public License along with this program in the file named "Copying". If not, write to the

        Free Software Foundation, Inc.,
        51 Franklin Street, Fifth Floor
        Boston, MA 02110-1301 USA

or visit their web page on the internet at:

        http://www.gnu.org/copyleft/gpl.html.

🌈 AUTHOR (again, because iconic) 🌈

Michael Robinton <michael@bizsystems.com>


ok bye bestie πŸ’– this page is from source/version perl v5.42.0, dated 2016-05-28, for NetAddr...::UtilPP(3) β€” mwah. 🫢✨

πŸ“¦ where this page comes from