From 4c0bbea95328b43f1b18cd687709ef72d998058b Mon Sep 17 00:00:00 2001 From: maidnl Date: Mon, 17 Jun 2024 10:05:00 +0200 Subject: [PATCH] properly initialized and checked Ethernet init callback --- libraries/Ethernet/src/Ethernet.cpp | 5 ++++- libraries/Ethernet/src/Ethernet.h | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/libraries/Ethernet/src/Ethernet.cpp b/libraries/Ethernet/src/Ethernet.cpp index 2e0f1a94f..ef07889c3 100644 --- a/libraries/Ethernet/src/Ethernet.cpp +++ b/libraries/Ethernet/src/Ethernet.cpp @@ -5,7 +5,10 @@ int arduino::EthernetClass::begin(uint8_t *mac, unsigned long timeout, unsigned long responseTimeout) { if (eth_if == nullptr) { //Q: What is the callback for? - _initializerCallback(); + //A: To call a specific function on your system before any initialization is performed + if(_initializerCallback != nullptr) { + _initializerCallback(); + } if (eth_if == nullptr) return 0; } eth_if->set_dhcp(true); diff --git a/libraries/Ethernet/src/Ethernet.h b/libraries/Ethernet/src/Ethernet.h index 2fc2ef240..f27a46fc0 100644 --- a/libraries/Ethernet/src/Ethernet.h +++ b/libraries/Ethernet/src/Ethernet.h @@ -121,7 +121,7 @@ class EthernetClass : public MbedSocketClass { volatile EthernetLinkStatus _currentNetworkStatus = Unknown; EthernetInterface net; EthernetInterface *eth_if = &net; - voidPrtFuncPtr _initializerCallback; + voidPrtFuncPtr _initializerCallback = nullptr; arduino::IPAddress ipAddressFromSocketAddress(SocketAddress socketAddress); };