Skip to content

Commit

Permalink
fix split_network
Browse files Browse the repository at this point in the history
  • Loading branch information
kjo committed Jun 20, 2021
1 parent 45098e7 commit fa763e8
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 23 deletions.
8 changes: 5 additions & 3 deletions changelog
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ rework getclass
- add table tag at the end of supernets adds </table> tag at the end of supernet output when in html mode
Add manpage of Nick Clifford
Applied patch of Victor Engmark:
Description: fixes overzealous input checking
Netmask /0 is perfectly fine, with this patch it's possible to use it.

Description: fixes overzealous input checking
Netmask /0 is perfectly fine, with this patch it's possible to use it.
0.51 2021-06-20 bugifx: split_network results were wrong since introduction of bignum. log function replaced
with loop.
Thanks to Christian Ebnöter for finding thix bug
5 changes: 3 additions & 2 deletions contributors
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
Thanks for your ideas and help to make this tool more useful:

Bartosz Fenski
Christan Ebnöther
Denis A. Hainsworth
Edward
Foxfair Hu
Frank Quotschalla
Hermann J. Beckers
Igor Zozulya
Kevin Ivory
Lars Mueller
Lutz Pressler
Nick Clifford
Oliver Seufer
Scott Davis
Steve Kent
Sven Anderson
Torgen Foertsch
Tim Brown
Edward
Nick Clifford
Victor Engmark
19 changes: 14 additions & 5 deletions ipcalc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


# IPv4 Calculator
# Copyright (C) Krischan Jodies 2000 - 2004
# Copyright (C) Krischan Jodies 2000 - 2021
# krischan()jodies.de, http://jodies.de/ipcalc
#
# This program is free software; you can redistribute it and/or modify
Expand All @@ -22,7 +22,7 @@
use strict;
use bignum;

my $version = '0.5';
my $version = '0.51';

my @class = qw (0 8 16 24 4 5 5);

Expand Down Expand Up @@ -639,15 +639,14 @@ sub split_network
my $needed_size;
foreach (@sizes) {
$needed_size = round2powerof2($_+2);
# printf "%3d -> %3d -> %3d\n",$_,$_+2,$needed_size;
push @network , $needed_size .":".$i++;
$needed_addresses += $needed_size;
}
@network = sort { ($b =~ /(.+):/)[0] <=> ($a =~ /(.+):/)[0] } @network;
foreach (@network) {
my ($size,$nr) = split ":",$_;
$net[$nr]= $network;
$mask[$nr]= (32-log($size)/log(2));
$mask[$nr]= size2bitcountmask($size);
$network += $size;
}
$i = -1;
Expand All @@ -660,7 +659,7 @@ sub split_network
printnet($net[$i],bitcountmaskton($mask[$i]),$mask2);
}

my $used_mask = 32-log(round2powerof2($needed_addresses))/log(2);
my $used_mask = size2bitcountmask($needed_addresses);
if ($used_mask < ntobitcountmask($mask1)) {
print "Network is too small\n";
}
Expand All @@ -679,6 +678,16 @@ sub round2powerof2 {
return 1 << $i;
}

sub size2bitcountmask
{
my $size = shift;
my $i = 0;
while ($size > ( 1 << $i)) {
$i++;
}
return 32-$i;
}

# Deaggregate address range
# expects: range: (dotted quads)start (dotted quads)end

Expand Down
28 changes: 15 additions & 13 deletions ipcalc.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# CGI Wrapper for IPv4 Calculator
#
# Copyright (C) Krischan Jodies 2000 - 2005
# Copyright (C) Krischan Jodies 2000 - 2021
# krischan()jodies.de, http://jodies.de/ipcalc
#
# Copyright (C) for the graphics ipcalc.gif and ipcalculator.png
Expand Down Expand Up @@ -255,22 +255,24 @@ creating HTML and still works happily in /usr/local/bin/ :-)</p>
<pre>
Bartosz Fenski
Denis A. Hainsworth
Christan Ebnoether
Denis A. Hainsworth
Edward
Foxfair Hu
Frank Quotschalla
Hermann J. Beckers
Igor Zozulya
Kevin Ivory
Frank Quotschalla
Hermann J. Beckers
Igor Zozulya
Kevin Ivory
Lars Mueller
Lutz Pressler
Lutz Pressler
Nick Clifford
Oliver Seufer
Scott Davis
Steve Kent
Sven Anderson
Scott Davis
Steve Kent
Sven Anderson
Torgen Foertsch
Tim Brown
Victor Engmark
</pre>
</td>
</tr>
Expand Down Expand Up @@ -345,7 +347,7 @@ print <<"EOF";
Have a look in the archives for the <b>new version 0.38</b>, with the capability to deaggregate network ranges<br>
<a href="ipcalc-faq/win32.html">How to run this under windows</a><br>
Debian users can apt-get install ipcalc<br>
2000-2004 <a href="mailto:$MAIL_ADDRESS">Krischan Jodies</a>
2000-2021 <a href="mailto:$MAIL_ADDRESS">Krischan Jodies</a>
</td></tr></table>
</center>
Expand Down

0 comments on commit fa763e8

Please sign in to comment.