X-Git-Url: http://dxcluster.org/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FDXUtil.pm;h=b60b0b0b1de4c444e301f86aa04404ed3d666b61;hb=refs%2Fheads%2Fmojo;hp=286f544b1bc017c00d612df26a927f893a85338b;hpb=19241b6f37923a92a56bf7890a5126f30f9b9d05;p=spider.git diff --git a/perl/DXUtil.pm b/perl/DXUtil.pm index 286f544b..b60b0b0b 100644 --- a/perl/DXUtil.pm +++ b/perl/DXUtil.pm @@ -15,8 +15,6 @@ use File::Copy; use Data::Dumper; use Time::HiRes qw(gettimeofday tv_interval); use Text::Wrap; -use Socket qw(AF_INET6 AF_INET inet_pton); - use strict; use vars qw(@month %patmap $pi $d2r $r2d @ISA @EXPORT); @@ -46,14 +44,24 @@ $pi = 3.141592653589; $d2r = ($pi/180); $r2d = (180/$pi); -our $ptonok; -BEGIN { - $ptonok = !defined inet_pton(AF_INET, '016.17.184.1') - && !defined inet_pton(AF_INET6, '2067::1:') - # Some old versions of Socket are hopelessly broken - && length(inet_pton(AF_INET, '1.1.1.1')) == 4; -} +# BEGIN { +# our $enable_ptonok = 0; +# our $ptonok; + + +# if ($enable_ptonok && !$main::is_win) { +# eval {require Socket; Socket->import(qw(AF_INET6 AF_INET inet_pton)); }; +# unless ($@) { +# $ptonok = !defined inet_pton(AF_INET, '016.17.184.1') +# && !defined inet_pton(AF_INET6, '2067::1:') +# # Some old versions of Socket are hopelessly broken +# && length(inet_pton(AF_INET, '1.1.1.1')) == 4; +# } +# } +# } + + # a full time for logging and other purposes sub atime @@ -457,23 +465,24 @@ sub is_latlong # is it an ip address? sub is_ipaddr { - if ($ptonok) { - if ($_[0] =~ /:/) { - if (inet_pton(AF_INET6, $_[0])) { - return ($_[0] =~ /([:0-9a-f]+)/); - } - } else { - if (inet_pton(AF_INET, $_[0])) { - return ($_[0] =~ /([\.\d]+)/); - } - } - } else { + $_[0] =~ s|/\d+$||; + # if ($ptonok) { + # if ($_[0] =~ /:/) { + # if (inet_pton(AF_INET6, $_[0])) { + # return ($_[0] =~ /([:0-9a-f]+)/); + # } + # } else { + # if (inet_pton(AF_INET, $_[0])) { + # return ($_[0] =~ /([\.\d]+)/); + # } + # } + # } else { if ($_[0] =~ /:/) { - return ($_[0] =~ /^(:?:?(?:[0-9a-f]{1,4}\:)?(?:\:[0-9a-f]{1,4}(?:\:\:)?){1,8})$/i); + return ($_[0] =~ /^((?:\:?\:?[0-9a-f]{0,4}){1,8}\:?\:?)$/i); } else { return ($_[0] =~ /^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/); } - } +# } return undef; } @@ -645,3 +654,5 @@ sub is_numeric { return $_[0] =~ /^[\.\d]+$/; } + +1;