Skip to content

Commit 3c6b481

Browse files
committed
mDNS: store network interface, checking it is up
1 parent 155431b commit 3c6b481

File tree

4 files changed

+11
-6
lines changed

4 files changed

+11
-6
lines changed

cores/esp8266/AddrList.h

+1
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ struct netifWrapper
128128
const char* ifmac () const { return (const char*)_netif->hwaddr; }
129129
int ifnumber () const { return _netif->num; }
130130
bool ifUp () const { return !!(_netif->flags & NETIF_FLAG_UP); }
131+
const netif* interface () const { return _netif; }
131132

132133
const ip_addr_t* ipFromNetifNum () const
133134
{

libraries/ESP8266mDNS/src/LEAmDNS.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ MDNSResponder::MDNSResponder(void)
5959
m_pServiceQueries(0),
6060
m_fnServiceTxtCallback(0),
6161
#ifdef ENABLE_ESP_MDNS_RESPONDER_PASSIV_MODE
62-
m_bPassivModeEnabled(true) {
62+
m_bPassivModeEnabled(true),
6363
#else
64-
m_bPassivModeEnabled(false) {
64+
m_bPassivModeEnabled(false),
6565
#endif
66-
66+
m_netif(nullptr) {
6767
}
6868

6969
/*

libraries/ESP8266mDNS/src/LEAmDNS.h

+1
Original file line numberDiff line numberDiff line change
@@ -1149,6 +1149,7 @@ class MDNSResponder {
11491149
bool m_bPassivModeEnabled;
11501150
stcProbeInformation m_HostProbeInformation;
11511151
IPAddress m_IPAddress;
1152+
const netif* m_netif; // network interface associated to m_IPAddress
11521153

11531154
/** CONTROL **/
11541155
/* MAINTENANCE */

libraries/ESP8266mDNS/src/LEAmDNS_Control.cpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
*
2323
*/
2424

25-
#include <arch/cc.h>
2625
#include <sys/time.h>
2726
#include <IPAddress.h>
2827
#include <AddrList.h>
@@ -79,8 +78,10 @@ bool MDNSResponder::_process(bool p_bUserContext) {
7978
}
8079
}
8180
else {
82-
bResult = _updateProbeStatus() && // Probing
83-
_checkServiceQueryCache(); // Service query cache check
81+
bResult = (m_netif != nullptr) &&
82+
(m_netif->flags & NETIF_FLAG_UP) && // network interface is up and running
83+
_updateProbeStatus() && // Probing
84+
_checkServiceQueryCache(); // Service query cache check
8485
}
8586
return bResult;
8687
}
@@ -122,10 +123,12 @@ bool MDNSResponder::_restart(void) {
122123

123124
// check existence of this IP address in the interface list
124125
bool found = false;
126+
m_netif = nullptr;
125127
for (auto a: addrList)
126128
if (m_IPAddress == a.addr()) {
127129
if (a.ifUp()) {
128130
found = true;
131+
m_netif = a.interface();
129132
break;
130133
}
131134
DEBUG_EX_INFO(DEBUG_OUTPUT.printf_P(PSTR("[MDNSResponder] found interface for IP '%s' but it is not UP\n"), m_IPAddress.toString().c_str()););

0 commit comments

Comments
 (0)