mirror of
https://github.com/esp8266/Arduino.git
synced 2025-07-27 18:02:17 +03:00
MDNS: fix random crash on startup (#6261)
* mDNS debug option + AP address is used by default when STA is also present * mDNS: store network interface, checking it is up * igmp: force on selected interface (avoid crash *sometimes*) * fix for all lwip2 ipv4 ipv6 & lwip1 * mdns: IPAddress is not needed to reference associated interface * mdns: debug: fix print warnings * emulation: add ets_strncpy * emulation: truly emulate AddrList (remove fake one)
This commit is contained in:
committed by
Earle F. Philhower, III
parent
273f4000f0
commit
5ca0bde200
@ -1,118 +0,0 @@
|
||||
|
||||
// TODO
|
||||
// mock AddrList with POSIX mock API
|
||||
// later: real AddrList will work with lwIP API
|
||||
|
||||
// mock is IPv4 only
|
||||
|
||||
#ifndef __ADDRLISTX_H
|
||||
#define __ADDRLISTX_H
|
||||
|
||||
#include <ESP8266WiFi.h>
|
||||
|
||||
namespace esp8266
|
||||
{
|
||||
|
||||
namespace AddressListImplementation
|
||||
{
|
||||
|
||||
|
||||
struct netifWrapper
|
||||
{
|
||||
netifWrapper (bool netif) : _netif(netif) {}
|
||||
netifWrapper (const netifWrapper& o) : _netif(o._netif) {}
|
||||
|
||||
netifWrapper& operator= (const netifWrapper& o)
|
||||
{
|
||||
_netif = o._netif;
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool equal(const netifWrapper& o)
|
||||
{
|
||||
return _netif == o._netif;
|
||||
}
|
||||
|
||||
// address properties
|
||||
IPAddress addr () const { return WiFi.localIP(); }
|
||||
bool isLegacy () const { return true; }
|
||||
bool isLocal () const { return false; }
|
||||
bool isV4 () const { return addr().isV4(); }
|
||||
bool isV6 () const { return !addr().isV4(); }
|
||||
String toString() const { return addr().toString(); }
|
||||
|
||||
// related to legacy address (_num=0, ipv4)
|
||||
IPAddress ipv4 () const { ip_info info; wifi_get_ip_info(0, &info); return info.ip; }
|
||||
IPAddress netmask () const { ip_info info; wifi_get_ip_info(0, &info); return info.netmask; }
|
||||
IPAddress gw () const { ip_info info; wifi_get_ip_info(0, &info); return info.gw; }
|
||||
|
||||
// common to all addresses of this interface
|
||||
String ifname () const { return "st"; }
|
||||
const char* ifhostname () const { return wifi_station_get_hostname(); }
|
||||
String ifmac () const { uint8_t mac[20]; WiFi.macAddress(mac); return String((char*)mac); }
|
||||
int ifnumber () const { return 0; }
|
||||
bool ifUp () const { return true; }
|
||||
|
||||
bool _netif;
|
||||
};
|
||||
|
||||
|
||||
class AddressListIterator
|
||||
{
|
||||
public:
|
||||
AddressListIterator (const netifWrapper& o) : netIf(o) {}
|
||||
AddressListIterator (bool netif) : netIf(netif)
|
||||
{
|
||||
// This constructor is called with lwIP's global netif_list, or
|
||||
// nullptr. operator++() is designed to loop through _configured_
|
||||
// addresses. That's why netIf's _num is initialized to -1 to allow
|
||||
// returning the first usable address to AddressList::begin().
|
||||
(void)operator++();
|
||||
}
|
||||
|
||||
const netifWrapper& operator* () const { return netIf; }
|
||||
const netifWrapper* operator-> () const { return &netIf; }
|
||||
|
||||
bool operator== (AddressListIterator& o) { return netIf.equal(*o); }
|
||||
bool operator!= (AddressListIterator& o) { return !netIf.equal(*o); }
|
||||
|
||||
AddressListIterator& operator= (const AddressListIterator& o) { netIf = o.netIf; return *this; }
|
||||
|
||||
AddressListIterator operator++ (int)
|
||||
{
|
||||
AddressListIterator ret = *this;
|
||||
(void)operator++();
|
||||
return ret;
|
||||
}
|
||||
|
||||
AddressListIterator& operator++ ()
|
||||
{
|
||||
netIf._netif = !netIf._netif;
|
||||
return *this;
|
||||
}
|
||||
|
||||
netifWrapper netIf;
|
||||
};
|
||||
|
||||
|
||||
class AddressList
|
||||
{
|
||||
public:
|
||||
using const_iterator = const AddressListIterator;
|
||||
|
||||
const_iterator begin () const { return const_iterator(true); }
|
||||
const_iterator end () const { return const_iterator(false); }
|
||||
|
||||
};
|
||||
|
||||
inline AddressList::const_iterator begin (const AddressList& a) { return a.begin(); }
|
||||
inline AddressList::const_iterator end (const AddressList& a) { return a.end(); }
|
||||
|
||||
|
||||
} // AddressListImplementation
|
||||
|
||||
} // esp8266
|
||||
|
||||
extern esp8266::AddressListImplementation::AddressList addrList;
|
||||
|
||||
#endif
|
@ -41,6 +41,7 @@ uint32_t lwip_ntohl (uint32_t netlong) { return ntohl(netlong); }
|
||||
uint16_t lwip_ntohs (uint16_t netshort) { return ntohs(netshort); }
|
||||
|
||||
char* ets_strcpy (char* d, const char* s) { return strcpy(d, s); }
|
||||
char* ets_strncpy (char* d, const char* s, size_t n) { return strncpy(d, s, n); }
|
||||
size_t ets_strlen (const char* s) { return strlen(s); }
|
||||
|
||||
int ets_printf (const char* fmt, ...)
|
||||
|
@ -1,10 +1,15 @@
|
||||
|
||||
#include <AddrList.h>
|
||||
#include <lwip/netif.h>
|
||||
|
||||
esp8266::AddressListImplementation::AddressList addrList;
|
||||
|
||||
extern "C"
|
||||
{
|
||||
|
||||
netif* netif_list = nullptr;
|
||||
extern netif netif0;
|
||||
|
||||
netif* netif_list = &netif0;
|
||||
|
||||
err_t dhcp_renew(struct netif *netif)
|
||||
{
|
||||
|
@ -44,6 +44,7 @@ extern "C"
|
||||
{
|
||||
|
||||
#include <user_interface.h>
|
||||
#include <lwip/netif.h>
|
||||
|
||||
uint8 wifi_get_opmode(void)
|
||||
{
|
||||
@ -115,6 +116,8 @@ void wifi_fpm_set_sleep_type (sleep_type_t type)
|
||||
|
||||
uint32_t global_ipv4_netfmt = 0; // global binding
|
||||
|
||||
netif netif0;
|
||||
|
||||
bool wifi_get_ip_info (uint8 if_index, struct ip_info *info)
|
||||
{
|
||||
struct ifaddrs * ifAddrStruct = NULL, * ifa = NULL;
|
||||
@ -165,6 +168,12 @@ bool wifi_get_ip_info (uint8 if_index, struct ip_info *info)
|
||||
info->ip.addr = ipv4;
|
||||
info->netmask.addr = mask;
|
||||
info->gw.addr = ipv4;
|
||||
|
||||
netif0.ip_addr.addr = ipv4;
|
||||
netif0.netmask.addr = mask;
|
||||
netif0.gw.addr = ipv4;
|
||||
netif0.flags = NETIF_FLAG_IGMP | NETIF_FLAG_UP | NETIF_FLAG_LINK_UP;
|
||||
netif0.next = nullptr;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
Reference in New Issue
Block a user