Skip to content

Commit

Permalink
EthernetCompat - static IP auto gw,mask,dns as in Arduino libraries
Browse files Browse the repository at this point in the history
  • Loading branch information
JAndrassy committed Nov 10, 2023
1 parent 31c1592 commit 9f632bb
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions libraries/lwIP_Ethernet/src/EthernetCompat.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,29 @@ class ArduinoEthernet: public LwipIntfDev<RawDev>
// Arduino-Ethernet API compatibility, order can be either:
// mac, ip, gateway, netmask, dns (esp8266 or natural order)
// mac, ip, dns, gateway, netmask (Arduino legacy)
boolean begin(const uint8_t* macAddress, const IPAddress& local_ip = IPADDR_NONE,
const IPAddress& arg1 = IPADDR_NONE, const IPAddress& arg2 = IPADDR_NONE,
const IPAddress& arg3 = IPADDR_NONE)
boolean begin(const uint8_t* macAddress, IPAddress local_ip = INADDR_NONE,
IPAddress arg1 = IPADDR_NONE, IPAddress arg2 = IPADDR_NONE,
IPAddress arg3 = IPADDR_NONE)
{
if (local_ip.isSet() && local_ip.isV4())
{
// setting auto values using arduino ordering of parameters
if (arg1 == INADDR_NONE) // else dns or gw
{
arg1 = local_ip;
arg1[3] = 1;
}
if (arg2 == INADDR_NONE) // else gw or mask
{
arg2 = local_ip;
arg2[3] = 1;
}
// if arg2 is mask (esp ordering), let DNS IP unconfigured
if (arg3 == INADDR_NONE && arg2[0] != 255) // else mask or dns
{
arg3 = IPAddress(255, 255, 255, 0);
}
}
SPI4EthInit(); // Arduino Ethernet self-initializes SPI
bool ret = true;
if (local_ip.isSet())
Expand Down

0 comments on commit 9f632bb

Please sign in to comment.