From bd61f70e7fee2f54c0b76f6a829c50997b18ec8d Mon Sep 17 00:00:00 2001 From: Juraj Andrassy Date: Fri, 22 Dec 2023 10:38:23 +0100 Subject: [PATCH] Ethernet.begin - fix parameters ordering --- libraries/Ethernet/src/Ethernet.cpp | 21 ++++++++++++--------- libraries/Ethernet/src/EthernetC33.h | 6 +++--- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/libraries/Ethernet/src/Ethernet.cpp b/libraries/Ethernet/src/Ethernet.cpp index 3151cdcc4..8f0b789c9 100644 --- a/libraries/Ethernet/src/Ethernet.cpp +++ b/libraries/Ethernet/src/Ethernet.cpp @@ -28,29 +28,32 @@ int CEthernet::begin(unsigned long timeout, unsigned long responseTimeout) { /* -------------------------------------------------------------------------- */ int CEthernet::begin(IPAddress local_ip) { /* -------------------------------------------------------------------------- */ - IPAddress subnet(255, 255, 255, 0); - return begin(local_ip, subnet); + // Assume the DNS server will be the machine on the same network as the local IP + // but with last octet being '1' + IPAddress dns_server = local_ip; + dns_server[3] = 1; + return begin(local_ip, dns_server); } /* -------------------------------------------------------------------------- */ -int CEthernet::begin(IPAddress local_ip, IPAddress subnet) { +int CEthernet::begin(IPAddress local_ip, IPAddress dns_server) { /* -------------------------------------------------------------------------- */ // Assume the gateway will be the machine on the same network as the local IP // but with last octet being '1' IPAddress gateway = local_ip; gateway[3] = 1; - return begin(local_ip, subnet, gateway); + return begin(local_ip, dns_server, gateway); } /* -------------------------------------------------------------------------- */ -int CEthernet::begin(IPAddress local_ip, IPAddress subnet, IPAddress gateway) { +int CEthernet::begin(IPAddress local_ip, IPAddress dns_server, IPAddress gateway) { /* -------------------------------------------------------------------------- */ - // Assume the DNS server will be the same machine than gateway - return begin(local_ip, subnet, gateway, gateway); + IPAddress subnet(255, 255, 255, 0); + return begin(local_ip, dns_server, gateway, subnet); } /* -------------------------------------------------------------------------- */ -int CEthernet::begin(IPAddress local_ip, IPAddress subnet, IPAddress gateway, IPAddress dns_server) { +int CEthernet::begin(IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet) { /* -------------------------------------------------------------------------- */ ni = CLwipIf::getInstance().get(NI_ETHERNET, local_ip, gateway, subnet); @@ -109,7 +112,7 @@ int CEthernet::begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_ser int CEthernet::begin(uint8_t *mac, IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet, unsigned long timeout, unsigned long responseTimeout) { /* -------------------------------------------------------------------------- */ CLwipIf::getInstance().setMacAddress(NI_ETHERNET, mac_address); - return begin(local_ip, subnet, gateway, dns_server); + return begin(local_ip, dns_server, gateway, subnet); } /* -------------------------------------------------------------------------- */ diff --git a/libraries/Ethernet/src/EthernetC33.h b/libraries/Ethernet/src/EthernetC33.h index 23f8202d1..97fa54511 100644 --- a/libraries/Ethernet/src/EthernetC33.h +++ b/libraries/Ethernet/src/EthernetC33.h @@ -41,9 +41,9 @@ class CEthernet { int begin(unsigned long timeout = 60000, unsigned long responseTimeout = 4000); EthernetLinkStatus linkStatus(); int begin(IPAddress local_ip); - int begin(IPAddress local_ip, IPAddress subnet); - int begin(IPAddress local_ip, IPAddress subnet, IPAddress gateway); - int begin(IPAddress local_ip, IPAddress subnet, IPAddress gateway, IPAddress dns_server); + int begin(IPAddress local_ip, IPAddress dns_server); + int begin(IPAddress local_ip, IPAddress dns_server, IPAddress gateway); + int begin(IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet); // Initialise the Ethernet shield to use the provided MAC address and gain the rest of the // configuration through DHCP. // Returns 0 if the DHCP configuration failed, and 1 if it succeeded