@@ -76,25 +76,16 @@ bool MDNSResponder::_sendMDNSMessage(MDNSResponder::stcMDNSSendParameter& p_rSen
76
76
77
77
bool bResult = true ;
78
78
79
- if (p_rSendParameter.m_bResponse ) {
80
- if (p_rSendParameter.m_bUnicast ) { // Unicast response -> Send to querier
81
- DEBUG_EX_ERR (if (!m_pUDPContext->getRemoteAddress ()) { DEBUG_OUTPUT.printf_P (PSTR (" [MDNSResponder] _sendMDNSMessage: MISSING remote address for response!\n " )); });
82
- IPAddress ipRemote;
83
- ipRemote = m_pUDPContext->getRemoteAddress ();
84
- bResult = ((_prepareMDNSMessage (p_rSendParameter, _getResponseMulticastInterface (SOFTAP_MODE | STATION_MODE))) &&
85
- (m_pUDPContext->send (ipRemote, m_pUDPContext->getRemotePort ())));
86
- }
87
- else { // Multicast response -> Send via the same network interface, that received the query
88
- bResult = _sendMDNSMessage_Multicast (p_rSendParameter, (SOFTAP_MODE | STATION_MODE));
89
- }
79
+ if (p_rSendParameter.m_bResponse &&
80
+ p_rSendParameter.m_bUnicast ) { // Unicast response -> Send to querier
81
+ DEBUG_EX_ERR (if (!m_pUDPContext->getRemoteAddress ()) { DEBUG_OUTPUT.printf_P (PSTR (" [MDNSResponder] _sendMDNSMessage: MISSING remote address for response!\n " )); });
82
+ IPAddress ipRemote;
83
+ ipRemote = m_pUDPContext->getRemoteAddress ();
84
+ bResult = ((_prepareMDNSMessage (p_rSendParameter, _getResponseMulticastInterface ())) &&
85
+ (m_pUDPContext->send (ipRemote, m_pUDPContext->getRemotePort ())));
90
86
}
91
- else { // Multicast query -> Send by all available network interfaces
92
- const int caiWiFiOpModes[2 ] = { SOFTAP_MODE, STATION_MODE };
93
- for (int iInterfaceId=0 ; ((bResult) && (iInterfaceId<=1 )); ++iInterfaceId) {
94
- if (wifi_get_opmode () & caiWiFiOpModes[iInterfaceId]) {
95
- bResult = _sendMDNSMessage_Multicast (p_rSendParameter, caiWiFiOpModes[iInterfaceId]);
96
- }
97
- }
87
+ else { // Multicast response
88
+ bResult = _sendMDNSMessage_Multicast (p_rSendParameter);
98
89
}
99
90
100
91
// Finally clear service reply masks
@@ -112,12 +103,12 @@ bool MDNSResponder::_sendMDNSMessage(MDNSResponder::stcMDNSSendParameter& p_rSen
112
103
* Fills the UDP output buffer (via _prepareMDNSMessage) and sends the buffer
113
104
* via the selected WiFi interface (Station or AP)
114
105
*/
115
- bool MDNSResponder::_sendMDNSMessage_Multicast (MDNSResponder::stcMDNSSendParameter& p_rSendParameter,
116
- int p_iWiFiOpMode) {
106
+ bool MDNSResponder::_sendMDNSMessage_Multicast (MDNSResponder::stcMDNSSendParameter& p_rSendParameter) {
107
+
117
108
bool bResult = false ;
118
109
119
110
IPAddress fromIPAddress;
120
- fromIPAddress = _getResponseMulticastInterface (p_iWiFiOpMode );
111
+ fromIPAddress = _getResponseMulticastInterface ();
121
112
m_pUDPContext->setMulticastInterface (fromIPAddress);
122
113
123
114
#ifdef MDNS_IP4_SUPPORT
@@ -365,46 +356,6 @@ bool MDNSResponder::_sendMDNSQuery(const MDNSResponder::stcMDNS_RRDomain& p_Quer
365
356
return bResult;
366
357
}
367
358
368
- /*
369
- * MDNSResponder::_getResponseMulticastInterface
370
- *
371
- * Selects the appropriate interface for responses.
372
- * If AP mode is enabled and the remote contact is in the APs local net, then the
373
- * AP interface is used to send the response.
374
- * Otherwise the Station interface (if available) is used.
375
- *
376
- */
377
- IPAddress MDNSResponder::_getResponseMulticastInterface (int p_iWiFiOpModes) const {
378
-
379
- ip_info IPInfo_Local;
380
- bool bFoundMatch = false ;
381
-
382
- if ((p_iWiFiOpModes & SOFTAP_MODE) &&
383
- (wifi_get_opmode () & SOFTAP_MODE)) {
384
- // DEBUG_EX_INFO(DEBUG_OUTPUT.printf_P(PSTR("[MDNSResponder] _getResponseMulticastInterface: SOFTAP_MODE\n")););
385
- // Get remote IP address
386
- IPAddress IP_Remote;
387
- IP_Remote = m_pUDPContext->getRemoteAddress ();
388
- // Get local (AP) IP address
389
- wifi_get_ip_info (SOFTAP_IF, &IPInfo_Local);
390
-
391
- if ((IPInfo_Local.ip .addr ) && // Has local AP IP address AND
392
- (ip4_addr_netcmp (ip_2_ip4 ((const ip_addr_t *)IP_Remote), &IPInfo_Local.ip , &IPInfo_Local.netmask ))) { // Remote address is in the same subnet as the AP
393
- bFoundMatch = true ;
394
- }
395
- }
396
- if ((!bFoundMatch) &&
397
- (p_iWiFiOpModes & STATION_MODE) &&
398
- (wifi_get_opmode () & STATION_MODE)) {
399
- // DEBUG_EX_INFO(DEBUG_OUTPUT.printf_P(PSTR("[MDNSResponder] _getResponseMulticastInterface: STATION_MODE\n")););
400
- // Get local (STATION) IP address
401
- wifi_get_ip_info (STATION_IF, &IPInfo_Local);
402
- }
403
- // DEBUG_EX_INFO(DEBUG_OUTPUT.printf_P(PSTR("[MDNSResponder] _getResponseMulticastInterface(%i): %s\n"), p_iWiFiOpModes, IPAddress(IPInfo_Local.ip).toString().c_str()););
404
- return IPAddress (IPInfo_Local.ip );
405
- }
406
-
407
-
408
359
/* *
409
360
* HELPERS
410
361
*/
0 commit comments