From 318c83cb36cdd27aa8668ea6ecb3d2abca5612fc Mon Sep 17 00:00:00 2001 From: s-hadinger <49731213+s-hadinger@users.noreply.github.com> Date: Sun, 18 Dec 2022 14:28:05 +0100 Subject: [PATCH] Revert UDP begin() (#17431) --- lib/libesp32/berry_tasmota/src/be_udp_lib.cpp | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/lib/libesp32/berry_tasmota/src/be_udp_lib.cpp b/lib/libesp32/berry_tasmota/src/be_udp_lib.cpp index f6084b049..370993a8c 100644 --- a/lib/libesp32/berry_tasmota/src/be_udp_lib.cpp +++ b/lib/libesp32/berry_tasmota/src/be_udp_lib.cpp @@ -14,7 +14,6 @@ // extern int be_udp_begin_mcast(bvm *vm); #include -#include #include #include "be_mapping.h" @@ -22,6 +21,8 @@ extern void AddLog(uint32_t loglevel, PGM_P formatP, ...); enum LoggingLevels {LOG_LEVEL_NONE, LOG_LEVEL_ERROR, LOG_LEVEL_INFO, LOG_LEVEL_DEBUG, LOG_LEVEL_DEBUG_MORE}; +extern bool WifiHostByName(const char* aHostname, IPAddress & aResult); + extern "C" { // init() @@ -41,19 +42,17 @@ extern "C" { return be_call_c_func(vm, (void*) &be_udp_deinit_ntv, "=.p", ""); } - // udp.begin(address:string, port:int) -> bool - int32_t be_udp_begin_ntv(WiFiUDP *udp, int32_t port) { + // udp.begin(interface:string, port:int) -> bool + int32_t be_udp_begin_ntv(WiFiUDP *udp, const char *host, int32_t port) { IPAddress addr; - // AddLog(LOG_LEVEL_DEBUG, "BRY: udp.begin listening to '%s'", addr.toString().c_str()); + // if no host or host is "" then we defult to INADDR_ANY + if(host && (*host != 0) && !WifiHostByName(host, addr)){ + return 0; + } return udp->begin(addr, port); } int32_t be_udp_begin(struct bvm *vm) { - if (be_top(vm) >= 3 && be_isstring(vm, 2)) { - // legacy string parameter, now ignored - return be_call_c_func(vm, (void*) &be_udp_begin_ntv, "b", ".-i"); - } else { - return be_call_c_func(vm, (void*) &be_udp_begin_ntv, "b", ".i"); - } + return be_call_c_func(vm, (void*) &be_udp_begin_ntv, "b", ".si"); } // udp.stop() -> nil @@ -67,7 +66,7 @@ extern "C" { // udp.begin_multicast(address:string, port:int) -> nil int32_t be_udp_begin_mcast_ntv(WiFiUDP *udp, const char *host, int32_t port) { IPAddress addr; - if(!WiFiGenericClass::hostByName(host, addr)){ + if(!WifiHostByName(host, addr)){ return 0; } return udp->WiFiUDP::beginMulticast(addr, port); @@ -79,7 +78,7 @@ extern "C" { // udp.send(address:string, port:int, payload:bytes) -> bool int32_t be_udp_send_ntv(WiFiUDP *udp, const char *host, int32_t port, const uint8_t* buf, int32_t len) { IPAddress addr; - if (!WiFiGenericClass::hostByName(host, addr)){ + if (!WifiHostByName(host, addr)){ return 0; } // AddLog(LOG_LEVEL_DEBUG, "BRY: udp.begin got host '%s'", addr.toString().c_str());