From 4d547c2bfc9895d61467d011904e3c1b2f2446bc Mon Sep 17 00:00:00 2001 From: Jan Engelhardt Date: Fri, 17 Dec 2010 22:47:01 +0100 Subject: [PATCH] geoip: remove -b option, always build both endianesses --- geoip/xt_geoip_build | 30 ++++++++++++++++++++++++------ geoip/xt_geoip_build.1 | 11 ++--------- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/geoip/xt_geoip_build b/geoip/xt_geoip_build index 7699219..4ba5404 100755 --- a/geoip/xt_geoip_build +++ b/geoip/xt_geoip_build @@ -12,19 +12,24 @@ use strict; my %country; my $csv = Text::CSV_XS->new({binary => 0, eol => $/}); # or Text::CSV -my $mode = "VV"; my $target_dir = "."; &Getopt::Long::Configure(qw(bundling)); &GetOptions( "D=s" => \$target_dir, - "b" => sub { $mode = "NN"; }, ); if (!-d $target_dir) { print STDERR "Target directory $target_dir does not exist.\n"; exit 1; } +foreach (qw(LE BE)) { + my $dir = "$target_dir/$_"; + if (!-e $dir && !mkdir($dir)) { + print STDERR "Could not mkdir $dir: $!\n"; + exit 1; + } +} while (my $row = $csv->getline(*ARGV)) { if (!defined($country{$row->[4]})) { @@ -40,13 +45,26 @@ while (my $row = $csv->getline(*ARGV)) { print STDERR "\r\e[2K$. entries total\n"; foreach my $iso_code (sort keys %country) { + my($file, $fh_le, $fh_be); + printf "%5u ranges for %s %s\n", scalar(@{$country{$iso_code}{pool}}), $iso_code, $country{$iso_code}{name}; - open(my $fh, "> $target_dir/".uc($iso_code).".iv0"); - foreach my $range (@{$country{$iso_code}{pool}}) { - print $fh pack($mode, $range->[0], $range->[1]); + $file = "$target_dir/LE/".uc($iso_code).".iv0"; + if (!open($fh_le, "> $file")) { + print STDERR "Error opening $file: $!\n"; + exit 1; } - close $fh; + $file = "$target_dir/BE/".uc($iso_code).".iv0"; + if (!open($fh_be, "> $file")) { + print STDERR "Error opening $file: $!\n"; + exit 1; + } + foreach my $range (@{$country{$iso_code}{pool}}) { + print $fh_le pack("VV", $range->[0], $range->[1]); + print $fh_be pack("NN", $range->[0], $range->[1]); + } + close $fh_le; + close $fh_be; } diff --git a/geoip/xt_geoip_build.1 b/geoip/xt_geoip_build.1 index a61f92b..3118787 100644 --- a/geoip/xt_geoip_build.1 +++ b/geoip/xt_geoip_build.1 @@ -4,7 +4,7 @@ xt_geoip_build \(em convert GeoIP.csv to packed format for xt_geoip .SH Syntax .PP -\fI/usr/libexec/xt_geoip/\fP\fBxt_geoip_build\fP [\fB\-b\fP] [\fB\-D\fP +\fI/usr/libexec/xt_geoip/\fP\fBxt_geoip_build\fP [\fB\-D\fP \fItarget_dir\fP] [\fIfile\fP...] .SH Description .PP @@ -23,20 +23,13 @@ xtables-addons package and this is outside $PATH (on purpose), invoking the script requires it to be called with a path. .PP Options .TP -\fB\-b\fP -The packed database files (file extension .iv0) are normally produced in -little-endian format. Use \fB\-b\fP to produce big-endian instead, as is needed -on some CPU families such as MIPS, PPC and SPARC. -.TP \fB\-D\fP \fItarget_dir\fP Specify a target directory into which the files are to be put. .SH Application .PP Shell commands to build the databases and put them to where they are expected: .PP -xt_geoip_build -D /usr/share/xt_geoip/LE -.PP -xt_geoip_build -bD /usr/share/xt_geoip/BE +xt_geoip_build -D /usr/share/xt_geoip .SH See also .PP xt_geoip_dl(1)