Skip to content

Commit 5bd52d4

Browse files
authored
EthernetCompat - static IP auto gw,mask,dns as in Arduino libraries (#9024)
1 parent 0c599ee commit 5bd52d4

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

libraries/lwIP_Ethernet/src/EthernetCompat.h

+22-3
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,29 @@ class ArduinoEthernet: public LwipIntfDev<RawDev>
3838
// Arduino-Ethernet API compatibility, order can be either:
3939
// mac, ip, gateway, netmask, dns (esp8266 or natural order)
4040
// mac, ip, dns, gateway, netmask (Arduino legacy)
41-
boolean begin(const uint8_t* macAddress, const IPAddress& local_ip = IPADDR_NONE,
42-
const IPAddress& arg1 = IPADDR_NONE, const IPAddress& arg2 = IPADDR_NONE,
43-
const IPAddress& arg3 = IPADDR_NONE)
41+
boolean begin(const uint8_t* macAddress, IPAddress local_ip = IPADDR_NONE,
42+
IPAddress arg1 = IPADDR_NONE, IPAddress arg2 = IPADDR_NONE,
43+
IPAddress arg3 = IPADDR_NONE)
4444
{
45+
if (local_ip.isSet() && local_ip.isV4())
46+
{
47+
// setting auto values using arduino ordering of parameters
48+
if (arg1 == IPADDR_NONE) // else dns or gw
49+
{
50+
arg1 = local_ip;
51+
arg1[3] = 1;
52+
}
53+
if (arg2 == IPADDR_NONE) // else gw or mask
54+
{
55+
arg2 = local_ip;
56+
arg2[3] = 1;
57+
}
58+
// if arg2 is mask (esp ordering), let DNS IP unconfigured
59+
if (arg3 == IPADDR_NONE && arg2[0] != 255) // else mask or dns
60+
{
61+
arg3 = IPAddress(255, 255, 255, 0);
62+
}
63+
}
4564
SPI4EthInit(); // Arduino Ethernet self-initializes SPI
4665
bool ret = true;
4766
if (local_ip.isSet())

0 commit comments

Comments
 (0)