From: Philip Prindeville Date: Sun, 19 Apr 2020 23:17:14 +0000 (+0200) Subject: geoip: simplify unpacking start/end tuples from database X-Git-Tag: v3.10~9 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=74fcd4a2ae13961608ae112cc2ee607f0c5ec1c4;p=thirdparty%2Fxtables-addons.git geoip: simplify unpacking start/end tuples from database Use unpack() to separate start/end instead of substr(). Signed-off-by: Philip Prindeville --- diff --git a/geoip/xt_geoip_fetch b/geoip/xt_geoip_fetch index 4a35760..0624519 100755 --- a/geoip/xt_geoip_fetch +++ b/geoip/xt_geoip_fetch @@ -53,8 +53,9 @@ foreach my $cc (@ARGV) { binmode($fh); while (($bytes = read($fh, $buffer, AF_INET_SIZE * 2)) == AF_INET_SIZE * 2) { - my $start = inet_ntop(AF_INET, substr($buffer, 0, AF_INET_SIZE)); - my $end = inet_ntop(AF_INET, substr($buffer, AF_INET_SIZE)); + my ($start, $end) = unpack('a4a4', $buffer); + $start = inet_ntop(AF_INET, $start); + $end = inet_ntop(AF_INET, $end); print $start, '-', $end, "\n"; } close($fh); @@ -75,8 +76,9 @@ foreach my $cc (@ARGV) { binmode($fh); while (($bytes = read($fh, $buffer, AF_INET6_SIZE * 2)) == AF_INET6_SIZE * 2) { - my $start = inet_ntop(AF_INET6, substr($buffer, 0, AF_INET6_SIZE)); - my $end = inet_ntop(AF_INET6, substr($buffer, AF_INET6_SIZE)); + my ($start, $end) = unpack('a16a16', $buffer); + $start = inet_ntop(AF_INET6, $start); + $end = inet_ntop(AF_INET6, $end); print $start, '-', $end, "\n"; } close($fh);