2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-10 09:16:53 +00:00

HttpUtils.pm: first step for INET6 support (Forum #75557)

git-svn-id: https://svn.fhem.de/fhem/trunk@14933 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig 2017-08-20 14:21:58 +00:00
parent 1229ecc96f
commit f15cd1aeb5
3 changed files with 20 additions and 4 deletions

View File

@ -354,7 +354,9 @@ DevIo_OpenDev($$$;$)
return undef; # no double callback: connect is running in bg now return undef; # no double callback: connect is running in bg now
} else { } else {
my $conn = IO::Socket::INET->new(PeerAddr => $dev, Timeout => $timeout); my $conn = $haveInet6 ?
IO::Socket::INET6->new(PeerAddr => $dev, Timeout => $timeout) :
IO::Socket::INET ->new(PeerAddr => $dev, Timeout => $timeout);
return "" if(!&$doTcpTail($conn)); # no callback: no doCb return "" if(!&$doTcpTail($conn)); # no callback: no doCb
} }

View File

@ -4,7 +4,6 @@ package main;
use strict; use strict;
use warnings; use warnings;
use IO::Socket::INET;
use MIME::Base64; use MIME::Base64;
use Digest::MD5 qw(md5_hex); use Digest::MD5 qw(md5_hex);
use vars qw($SSL_ERROR); use vars qw($SSL_ERROR);
@ -309,8 +308,10 @@ HttpUtils_Connect($)
} }
} else { } else {
$hash->{conn} = IO::Socket::INET->new( $hash->{conn} = $haveInet6 ?
PeerAddr=>"$host:$port", Timeout=>$hash->{timeout}); IO::Socket::INET6->new(PeerAddr=>"$host:$port",Timeout=>$hash->{timeout}):
IO::Socket::INET ->new(PeerAddr=>"$host:$port",Timeout=>$hash->{timeout});
return "$hash->{displayurl}: Can't connect(1) to $hash->{addr}: $@" return "$hash->{displayurl}: Can't connect(1) to $hash->{addr}: $@"
if(!$hash->{conn}); if(!$hash->{conn});
} }

View File

@ -34,6 +34,7 @@ use strict;
use warnings; use warnings;
use lib '.'; use lib '.';
use IO::Socket; use IO::Socket;
use IO::Socket::INET;
use Time::HiRes qw(gettimeofday); use Time::HiRes qw(gettimeofday);
use Scalar::Util qw(looks_like_number); use Scalar::Util qw(looks_like_number);
use POSIX; use POSIX;
@ -238,6 +239,7 @@ use vars qw(%value); # Current values, see commandref.html
use vars qw(@authenticate); # List of authentication devices use vars qw(@authenticate); # List of authentication devices
use vars qw(@authorize); # List of authorization devices use vars qw(@authorize); # List of authorization devices
use vars qw(@structChangeHist); # Contains the last 10 structural changes use vars qw(@structChangeHist); # Contains the last 10 structural changes
use vars qw($haveInet6); # Using INET6
$selectTimestamp = gettimeofday(); $selectTimestamp = gettimeofday();
$cvsid = '$Id$'; $cvsid = '$Id$';
@ -318,6 +320,7 @@ my @globalAttrList = qw(
uniqueID uniqueID
updateInBackground:1,0 updateInBackground:1,0
updateNoFileCheck:1,0 updateNoFileCheck:1,0
useInet6:1,0
version version
); );
use warnings 'qw'; use warnings 'qw';
@ -2556,6 +2559,7 @@ GlobalAttr($$$$)
my %noDel = ( modpath=>1, verbose=>1, logfile=>1 ); my %noDel = ( modpath=>1, verbose=>1, logfile=>1 );
return "The global attribute $name cannot be deleted" if($noDel{$name}); return "The global attribute $name cannot be deleted" if($noDel{$name});
$featurelevel = 5.8 if($name eq "featurelevel"); $featurelevel = 5.8 if($name eq "featurelevel");
$haveInet6 = 0 if($name eq "useInet6");
return undef; return undef;
} }
@ -2634,6 +2638,15 @@ GlobalAttr($$$$)
system("$^X $root/contrib/commandref_modular.pl $out"); system("$^X $root/contrib/commandref_modular.pl $out");
} }
} }
elsif($name eq "useInet6") {
if($val || !defined($val)) {
eval { require IO::Socket::INET6; };
return $@ if($@);
$haveInet6 = 1;
} else {
$haveInet6 = 0;
}
}
return undef; return undef;
} }