From b4b48bd6e14b5f5d4a27993c6330f9cf217fd86e Mon Sep 17 00:00:00 2001 From: choenig <> Date: Sun, 11 Jul 2021 12:24:22 +0000 Subject: [PATCH] 10_WS980: v1.5.0 - fix fhem-crash when autodiscovery fails git-svn-id: https://svn.fhem.de/fhem/trunk@24727 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/CHANGED | 1 + fhem/FHEM/10_WS980.pm | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/fhem/CHANGED b/fhem/CHANGED index 5a03f1f46..e79ca90c2 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -1,5 +1,6 @@ # Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # Do not insert empty lines here, update check depends on it. + - bugfix: 10_WS980: v.1.5.0 fix fhem-crash when autodiscovery fails - change: 10_WS980: allow to ignore invalid values - feature: 49_SSCam: new value 8.2.8-xxxx for attr simu_SVSversion - bugfix: 76_SMAInverter:fix ETOTAL/LOADTOTAL bug diff --git a/fhem/FHEM/10_WS980.pm b/fhem/FHEM/10_WS980.pm index 07a6b5749..16ce495d7 100644 --- a/fhem/FHEM/10_WS980.pm +++ b/fhem/FHEM/10_WS980.pm @@ -33,7 +33,7 @@ use warnings; use IO::Socket::INET; use POSIX qw(strftime); -my $version = "1.4.0"; +my $version = "1.5.0"; #------------------------------------------------------------------------------------------------------ # global constants @@ -451,10 +451,18 @@ sub WS980_autodiscoverIP($) WS980_Log($hash, 4, "received raw reply: " . WS980_hexDump($rawbuf)); my ($typeStr, $buf) = WS980_handleReply($hash, $rawbuf); - my ($ip1, $ip2, $ip3, $ip4, $port, $stationName) = unpack("x[6]CCCCnC/A", $buf); - WS980_Log($hash, 2, "reply: $ip1, $ip2, $ip3, $ip4, $port, $stationName"); - return (sprintf("%d.%d.%d.%d", $ip1, $ip2, $ip3, $ip4), $port); + if (defined($buf)) { + my ($ip1, $ip2, $ip3, $ip4, $port, $stationName) = unpack("x[6]CCCCnC/A", $buf); + WS980_Log($hash, 2, "autodiscovery-reply: $ip1, $ip2, $ip3, $ip4, $port, $stationName"); + + return (sprintf("%d.%d.%d.%d", $ip1, $ip2, $ip3, $ip4), $port); + } + else + { + WS980_Log($hash, 1, "autodiscovery failed: looks like the reply could not be decoded"); + return (undef,undef); + } }