Author image Karl Gaissmaier
and 1 contributors


Net::IPAM::Util - A selection of general utility subroutines for Net::IPAM


  use Net::IPAM::Util qw(incr_n inet_ntop_pp inet_pton_pp);

  $n = incr_n("\x0a\x00\x00\x01");                                 #
  $n = incr_n( pack( 'n8', 0x2001, 0xdb8, 0, 0, 0, 0, 0, 1 ) );    # 2001:db8::2

  $n = inet_pton_pp( AF_INET6, '2001:db8::fe1' );
  say inet_ntop_pp( AF_INET, "\x0a\x00\x00\x01" );                 #


$address_plusplus = incr_n( $address )

Increment a packed IPv4 or IPv6 address in network byte order. Returns undef on overflow.

This increment function is needed in Net::IPAM::IP and Net::IPAM::Block for transparent handling of IPv4 and IPv6 addresses and blocks.

This is the only math operation needed for iterating over blocks, splitting blocks to CIDRs or aggregate IPs and blocks to CIDRs.

No need for Math::BigInt, this pure perl algorithm works for all uint_n in network byte order, where n is a multiple of 32: uint_32, uint_64, uint_96, uint_128, ...

$string = inet_ntop_pp( $family, $address )

A pure perl implementation for (buggy) Socket::inet_ntop.

Takes an address family (AF_INET or AF_INET6) and a packed binary address structure and translates it into a human-readable textual representation of the address.

$address = inet_pton_pp( $family, $string )

A pure perl implementation for (buggy) Socket::inet_pton.

Takes an address family (AF_INET or AF_INET6) and a string containing a textual representation of an address in that family and translates that to an packed binary address structure.


Karl Gaissmaier, <karl.gaissmaier(at)>


Please report any bugs or feature requests to bug-net-ipam-util at, or through the web interface at I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.


You can find documentation for this module with the perldoc command.

    perldoc Net::IPAM::Util

You can also look for information at:

  • on github



Net::IPAM::IP Net::IPAM::Block Net::IPAM::Tree


This software is copyright (c) 2020 by Karl Gaissmaier.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.