in reply to NetAddr::IP Automated Subnet Allocation

Like the documentation indicates says + and ++ will wrap around within the subnet, so new_netaddr won't hold what you want:

(127.0.0.255/24)++ -> (127.0.0.0/24) (127.0.0.255/24)+1 -> (127.0.0.0/24)

How about: (Tested)

my ($addr, $mask) = $net_broadcast->numeric(); my $new_netaddr = NetAddr::IP->new($addr+1, $mask);

I haven't looked at why you have /32's instead of /29's in your output.

Replies are listed 'Best First'.
Re^2: NetAddr::IP Automated Subnet Allocation
by amt (Monk) on Sep 03, 2004 at 15:00 UTC
    Your solution works, but I need to add 1 to the address of the broadcast address, so I can begin the next sub-network. Your solution returns the numberic() of the current address field, which is the base network address.
    amt
      Your solution returns the numberic() of the current address field, which is the base network address.

      Not so. Did you type in $net_addr where you should have typed $net_broadcast?

      use NetAddr::IP (); my $net_addr = NetAddr::IP->new('192.168.1.0/29'); my $net_broadcast = $net_addr->broadcast(); my $net_newaddr; { my ($addr, $mask) = $net_broadcast->numeric(); $net_newaddr = NetAddr::IP->new($addr+1, $mask); } print("$net_addr\n"); # prints 192.168.1.0/29 print("$net_broadcast\n"); # prints 192.168.1.7/29 print("$net_newaddr\n"); # prints 192.168.1.8/29