From f15cd1aeb50222a9b987674424fbc33e53cde4b8 Mon Sep 17 00:00:00 2001 From: rudolfkoenig <> Date: Sun, 20 Aug 2017 14:21:58 +0000 Subject: [PATCH] HttpUtils.pm: first step for INET6 support (Forum #75557) git-svn-id: https://svn.fhem.de/fhem/trunk@14933 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/DevIo.pm | 4 +++- fhem/FHEM/HttpUtils.pm | 7 ++++--- fhem/fhem.pl | 13 +++++++++++++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/fhem/FHEM/DevIo.pm b/fhem/FHEM/DevIo.pm index 26601303e..a0c8c7863 100644 --- a/fhem/FHEM/DevIo.pm +++ b/fhem/FHEM/DevIo.pm @@ -354,7 +354,9 @@ DevIo_OpenDev($$$;$) return undef; # no double callback: connect is running in bg now } 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 } diff --git a/fhem/FHEM/HttpUtils.pm b/fhem/FHEM/HttpUtils.pm index 69500d205..5f194ef60 100644 --- a/fhem/FHEM/HttpUtils.pm +++ b/fhem/FHEM/HttpUtils.pm @@ -4,7 +4,6 @@ package main; use strict; use warnings; -use IO::Socket::INET; use MIME::Base64; use Digest::MD5 qw(md5_hex); use vars qw($SSL_ERROR); @@ -309,8 +308,10 @@ HttpUtils_Connect($) } } else { - $hash->{conn} = IO::Socket::INET->new( - PeerAddr=>"$host:$port", Timeout=>$hash->{timeout}); + $hash->{conn} = $haveInet6 ? + 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}: $@" if(!$hash->{conn}); } diff --git a/fhem/fhem.pl b/fhem/fhem.pl index 004350615..7d6d47932 100755 --- a/fhem/fhem.pl +++ b/fhem/fhem.pl @@ -34,6 +34,7 @@ use strict; use warnings; use lib '.'; use IO::Socket; +use IO::Socket::INET; use Time::HiRes qw(gettimeofday); use Scalar::Util qw(looks_like_number); 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(@authorize); # List of authorization devices use vars qw(@structChangeHist); # Contains the last 10 structural changes +use vars qw($haveInet6); # Using INET6 $selectTimestamp = gettimeofday(); $cvsid = '$Id$'; @@ -318,6 +320,7 @@ my @globalAttrList = qw( uniqueID updateInBackground:1,0 updateNoFileCheck:1,0 + useInet6:1,0 version ); use warnings 'qw'; @@ -2556,6 +2559,7 @@ GlobalAttr($$$$) my %noDel = ( modpath=>1, verbose=>1, logfile=>1 ); return "The global attribute $name cannot be deleted" if($noDel{$name}); $featurelevel = 5.8 if($name eq "featurelevel"); + $haveInet6 = 0 if($name eq "useInet6"); return undef; } @@ -2634,6 +2638,15 @@ GlobalAttr($$$$) 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; }