1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-16 00:43:00 +03:00

LEA mDNS v2 (#7540)

* LEAmDNSv2
This commit is contained in:
Labor-Et-Ars
2020-09-25 11:12:39 +02:00
committed by GitHub
parent faf59f5190
commit a3281fe2f3
39 changed files with 12359 additions and 1846 deletions

View File

@ -32,6 +32,13 @@
struct ip_addr: ipv4_addr { };
#endif // !LWIP_IPV6
// to display a netif id with printf:
#define NETIFID_STR "%c%c%u"
#define NETIFID_VAL(netif) \
((netif)? (netif)->name[0]: '-'), \
((netif)? (netif)->name[1]: '-'), \
((netif)? netif_get_index(netif): 42)
// A class to make it easier to handle and pass around IP addresses
// IPv6 update:
// IPAddress is now a decorator class for lwIP's ip_addr_t

26
cores/esp8266/LwipIntf.h Normal file
View File

@ -0,0 +1,26 @@
#ifndef _LWIPINTF_H
#define _LWIPINTF_H
#include <lwip/netif.h>
#include <functional>
class LwipIntf
{
public:
using CBType = std::function <void(netif*)>;
static bool stateUpCB (LwipIntf::CBType&& cb);
private:
LwipIntf () { } // private, cannot be directly allocated
protected:
static bool stateChangeSysCB (LwipIntf::CBType&& cb);
};
#endif // _LWIPINTF_H

View File

@ -0,0 +1,42 @@
#include <LwipIntf.h>
#include <Schedule.h>
#include <debug.h>
#define NETIF_STATUS_CB_SIZE 3
static int netifStatusChangeListLength = 0;
LwipIntf::CBType netifStatusChangeList [NETIF_STATUS_CB_SIZE];
extern "C" void netif_status_changed (struct netif* netif)
{
// override the default empty weak function
for (int i = 0; i < netifStatusChangeListLength; i++)
netifStatusChangeList[i](netif);
}
bool LwipIntf::stateChangeSysCB (LwipIntf::CBType&& cb)
{
if (netifStatusChangeListLength >= NETIF_STATUS_CB_SIZE)
{
#if defined(DEBUG_ESP_CORE)
DEBUGV("NETIF_STATUS_CB_SIZE is too low\n");
#endif
return false;
}
netifStatusChangeList[netifStatusChangeListLength++] = cb;
return true;
}
bool LwipIntf::stateUpCB (LwipIntf::CBType&& cb)
{
return stateChangeSysCB([cb](netif* nif)
{
if (netif_is_up(nif))
schedule_function([cb, nif]()
{
cb(nif);
});
});
}

View File

@ -117,4 +117,36 @@ char * dtostrf(double number, signed char width, unsigned char prec, char *s) {
return s;
}
/*
strrstr (static)
Backwards search for p_pcPattern in p_pcString
Based on: https://stackoverflow.com/a/1634398/2778898
*/
const char* strrstr(const char*__restrict p_pcString,
const char*__restrict p_pcPattern)
{
const char* pcResult = 0;
size_t stStringLength = (p_pcString ? strlen(p_pcString) : 0);
size_t stPatternLength = (p_pcPattern ? strlen(p_pcPattern) : 0);
if ((stStringLength) &&
(stPatternLength) &&
(stPatternLength <= stStringLength))
{
// Pattern is shorter or has the same length than the string
for (const char* s = (p_pcString + stStringLength - stPatternLength); s >= p_pcString; --s)
{
if (0 == strncmp(s, p_pcPattern, stPatternLength))
{
pcResult = s;
break;
}
}
}
return pcResult;
}
};

View File

@ -44,6 +44,9 @@ char* dtostrf (double val, signed char width, unsigned char prec, char *s);
void reverse(char* begin, char* end);
const char* strrstr(const char*__restrict p_pcString,
const char*__restrict p_pcPattern);
#ifdef __cplusplus
} // extern "C"
#endif