X-Git-Url: http://dxcluster.net/gitweb/gitweb.cgi?p=spider.git;a=blobdiff_plain;f=perl%2FDXUtil.pm;h=b60b0b0b1de4c444e301f86aa04404ed3d666b61;hp=d23c27cfa5e3d73e4d3c21fae04aef16d6d08a9e;hb=a13f69ce9f26ea2b95be1e6de1f14f50ab7065d8;hpb=dc9a699965ba5a2e347a72d4ba8b0612f8adc63e diff --git a/perl/DXUtil.pm b/perl/DXUtil.pm index d23c27cf..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 @@ -458,23 +466,23 @@ sub is_latlong sub is_ipaddr { $_[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 ($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; } @@ -646,3 +654,5 @@ sub is_numeric { return $_[0] =~ /^[\.\d]+$/; } + +1;