@@ -63,9 +63,14 @@ class LwipIntfDev: public LwipIntf, public RawDev
6363 memset (&_netif, 0 , sizeof (_netif));
6464 }
6565
66+ // The argument order for ESP is not the same as for Arduino. However, there is compatibility code under the hood
67+ // to detect Arduino arg order, and handle it correctly.
6668 boolean config (const IPAddress& local_ip, const IPAddress& arg1, const IPAddress& arg2,
6769 const IPAddress& arg3 = IPADDR_NONE, const IPAddress& dns2 = IPADDR_NONE);
6870
71+ // two and one parameter version. 2nd parameter is DNS like in Arduino. IPv4 only
72+ boolean config (IPAddress local_ip, IPAddress dns = INADDR_ANY);
73+
6974 // default mac-address is inferred from esp8266's STA interface
7075 boolean begin (const uint8_t * macAddress = nullptr , const uint16_t mtu = DEFAULT_MTU);
7176 void end ();
@@ -209,6 +214,24 @@ boolean LwipIntfDev<RawDev>::config(const IPAddress& localIP, const IPAddress& g
209214 return true ;
210215}
211216
217+ template <class RawDev >
218+ boolean LwipIntfDev<RawDev>::config(IPAddress local_ip, IPAddress dns)
219+ {
220+ if (!local_ip.isSet ())
221+ return config (INADDR_ANY, INADDR_ANY, INADDR_ANY);
222+
223+ if (!local_ip.isV4 ())
224+ return false ;
225+
226+ IPAddress gw (local_ip);
227+ gw[3 ] = 1 ;
228+ if (!dns.isSet ())
229+ {
230+ dns = gw;
231+ }
232+ return config (local_ip, gw, IPAddress (255 , 255 , 255 , 0 ), dns);
233+ }
234+
212235template <class RawDev >
213236boolean LwipIntfDev<RawDev>::begin(const uint8_t * macAddress, const uint16_t mtu)
214237{
@@ -336,9 +359,6 @@ template<class RawDev>
336359void LwipIntfDev<RawDev>::end()
337360{
338361 netif_remove (&_netif);
339- ip_addr_copy (_netif.ip_addr , ip_addr_any); // to allow DHCP at next begin
340- ip_addr_copy (_netif.netmask , ip_addr_any);
341- ip_addr_copy (_netif.gw , ip_addr_any);
342362 _started = false ;
343363 RawDev::end ();
344364}
0 commit comments