From owner-freebsd-ports-bugs@FreeBSD.ORG Fri Jan 13 00:40:07 2006 Return-Path: X-Original-To: freebsd-ports-bugs@hub.freebsd.org Delivered-To: freebsd-ports-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 2CD1416A41F for ; Fri, 13 Jan 2006 00:40:07 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 8E69743D48 for ; Fri, 13 Jan 2006 00:40:06 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.4/8.13.4) with ESMTP id k0D0e6QM035415 for ; Fri, 13 Jan 2006 00:40:06 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.13.4/8.13.4/Submit) id k0D0e6Oc035412; Fri, 13 Jan 2006 00:40:06 GMT (envelope-from gnats) Resent-Date: Fri, 13 Jan 2006 00:40:06 GMT Resent-Message-Id: <200601130040.k0D0e6Oc035412@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-ports-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, "Ilya V. Guy" Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id F278A16A420 for ; Fri, 13 Jan 2006 00:34:58 +0000 (GMT) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (www.freebsd.org [216.136.204.117]) by mx1.FreeBSD.org (Postfix) with ESMTP id AE41743D46 for ; Fri, 13 Jan 2006 00:34:58 +0000 (GMT) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (localhost [127.0.0.1]) by www.freebsd.org (8.13.1/8.13.1) with ESMTP id k0D0YweV033247 for ; Fri, 13 Jan 2006 00:34:58 GMT (envelope-from nobody@www.freebsd.org) Received: (from nobody@localhost) by www.freebsd.org (8.13.1/8.13.1/Submit) id k0D0Ywqj033246; Fri, 13 Jan 2006 00:34:58 GMT (envelope-from nobody) Message-Id: <200601130034.k0D0Ywqj033246@www.freebsd.org> Date: Fri, 13 Jan 2006 00:34:58 GMT From: "Ilya V. Guy" To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-2.3 Cc: Subject: ports/91731: Patch to net/ipcalc, which adds an opportunity of a finding of the minimal greater network mask. X-BeenThere: freebsd-ports-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Ports bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 13 Jan 2006 00:40:07 -0000 >Number: 91731 >Category: ports >Synopsis: Patch to net/ipcalc, which adds an opportunity of a finding of the minimal greater network mask. >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-ports-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Fri Jan 13 00:40:05 GMT 2006 >Closed-Date: >Last-Modified: >Originator: Ilya V. Guy >Release: 5.3-RELEASE >Organization: ISP `Lis' >Environment: FreeBSD ilya.home.lisgroup.net 5.3-RELEASE FreeBSD 5.3-RELEASE #1: Sat Sep 24 21:35:13 EEST 2005 ilya@ilya.home.lisgroup.net:/usr/obj/usr/src/sys/Ilya i386 >Description: Patch to net/ipcalc (ipcalc-0.38), which adds an opportunity of a finding of the minimal greater network mask. Use: ipcalc 192.168.2.0 + 192.168.6.0 or ipcalc -a 192.168.2.0 192.168.6.0 or ipcalc -agg 192.168.2.0 192.168.6.0 Produce: aggregate 192.168.2.0 + 192.168.6.0 192.168.0.0/21 >How-To-Repeat: >Fix: --- ipcalc Fri Jan 13 00:58:01 2006 +++ ipcalc.new Fri Jan 13 02:25:25 2006 @@ -46,6 +46,7 @@ my $opt_print_only_class = 0; my $opt_split = 0; my $opt_deaggregate = 0; +my $opt_aggregate = 0; my $opt_version = 0; my $opt_help = 0; my @opt_split_sizes; @@ -137,8 +138,8 @@ $address = argton("192.168.1.1"); } - # if deaggregate get last address - if ($opt_deaggregate) { + # if aggregate or deaggregate get last address + if ($opt_deaggregate||$opt_aggregate) { if (defined $ARGV[1]) { $address2 = argton($ARGV[1],0); } @@ -157,6 +158,15 @@ exit; } + if ($opt_aggregate) { + if ($error) { + print "$error\n"; + } + print "aggregate ".ntoa($address) . " + " . ntoa($address2)."\n"; + aggregate($address,$address2); + exit; + } + # get netmasks if (defined $ARGV[1]) { $mask1 = argton($ARGV[1],1); @@ -208,6 +218,9 @@ if ($opt_deaggregate) { deaggregate(); } + if ($opt_aggregate) { + aggregate(); + } if ($opt_split) { split_network($network,$mask1,$mask2,@opt_split_sizes); exit; @@ -646,6 +659,28 @@ return 1 << $i; } +# Aggregate address range +# expects: range: (dotted quads)start (dotted quads)end + +sub aggregate +{ + my $base = shift; + my $end = shift; + my $step; + my $mask; + + $step=0; + while ( ($base != $end) ) + { + $mask = $thirtytwobits-((1<<$step)-1); + $base = $base & $mask; + $end = $end & $mask; + $step++; + } + my $broadcast = $base | ((~$mask) & $thirtytwobits); + deaggregate($base,$broadcast); +} + # Deaggregate address range # expects: range: (dotted quads)start (dotted quads)end @@ -735,6 +770,14 @@ elsif (/^\-$/) { $opt_deaggregate = 1; } + elsif (/^(.+)\+(.+)$/) { + push @arguments,$1; + push @arguments,$2; + $opt_aggregate = 1; + } + elsif (/^\+$/) { + $opt_aggregate = 1; + } else { push @arguments, $_; } @@ -743,6 +786,10 @@ @arguments = ($arguments[0],$arguments[2]); $opt_deaggregate = 1; } + if ($#arguments == 2 && $arguments[1] eq '+') { + @arguments = ($arguments[0],$arguments[2]); + $opt_aggregate = 1; + } # workaround for -h @@ -785,6 +832,9 @@ elsif ($opt eq 'r' || $opt eq 'range') { $opt_deaggregate = 1; } + elsif ($opt eq 'a' || $opt eq 'agg') { + $opt_aggregate = 1; + } elsif ($opt eq 's' || $opt eq 'split') { $opt_split = 1; while (defined $ARGV[0] && $ARGV[0] =~ /^\d+$/) { @@ -1043,6 +1093,7 @@ -s --split n1 n2 n3 Split into networks of size n1, n2, n3. -r --range Deaggregate address range. + -a --agg Aggregate address range. --help Longer help text. Examples: @@ -1054,6 +1105,8 @@ ipcalc - deaggregate address range + +ipcalc + aggregate address range ipcalc
/ --s a b c split network to subnets >Release-Note: >Audit-Trail: >Unformatted: