mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-19 23:22:16 +03:00
Add _buffer initialization and some sanity check
This seems fix the Exception (28)/ (9) that occur on Captive portal with Soft AP
This commit is contained in:
parent
a9f9f6d53f
commit
64754524ec
@ -13,6 +13,7 @@ bool DNSServer::start(const uint16_t &port, const String &domainName,
|
||||
const IPAddress &resolvedIP)
|
||||
{
|
||||
_port = port;
|
||||
_buffer = NULL;
|
||||
_domainName = domainName;
|
||||
_resolvedIP[0] = resolvedIP[0];
|
||||
_resolvedIP[1] = resolvedIP[1];
|
||||
@ -35,6 +36,8 @@ void DNSServer::setTTL(const uint32_t &ttl)
|
||||
void DNSServer::stop()
|
||||
{
|
||||
_udp.stop();
|
||||
free(_buffer);
|
||||
_buffer = NULL;
|
||||
}
|
||||
|
||||
void DNSServer::downcaseAndRemoveWwwPrefix(String &domainName)
|
||||
@ -48,7 +51,9 @@ void DNSServer::processNextRequest()
|
||||
_currentPacketSize = _udp.parsePacket();
|
||||
if (_currentPacketSize)
|
||||
{
|
||||
if (_buffer != NULL) free(_buffer);
|
||||
_buffer = (unsigned char*)malloc(_currentPacketSize * sizeof(char));
|
||||
if (_buffer == NULL) return;
|
||||
_udp.read(_buffer, _currentPacketSize);
|
||||
_dnsHeader = (DNSHeader*) _buffer;
|
||||
|
||||
@ -66,6 +71,7 @@ void DNSServer::processNextRequest()
|
||||
}
|
||||
|
||||
free(_buffer);
|
||||
_buffer = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
@ -80,6 +86,7 @@ bool DNSServer::requestIncludesOnlyOneQuestion()
|
||||
String DNSServer::getDomainNameWithoutWwwPrefix()
|
||||
{
|
||||
String parsedDomainName = "";
|
||||
if (_buffer == NULL) return parsedDomainName;
|
||||
unsigned char *start = _buffer + 12;
|
||||
if (*start == 0)
|
||||
{
|
||||
@ -109,6 +116,7 @@ String DNSServer::getDomainNameWithoutWwwPrefix()
|
||||
|
||||
void DNSServer::replyWithIP()
|
||||
{
|
||||
if (_buffer == NULL) return;
|
||||
_dnsHeader->QR = DNS_QR_RESPONSE;
|
||||
_dnsHeader->ANCount = _dnsHeader->QDCount;
|
||||
_dnsHeader->QDCount = _dnsHeader->QDCount;
|
||||
@ -152,6 +160,7 @@ void DNSServer::replyWithIP()
|
||||
|
||||
void DNSServer::replyWithCustomCode()
|
||||
{
|
||||
if (_buffer == NULL) return;
|
||||
_dnsHeader->QR = DNS_QR_RESPONSE;
|
||||
_dnsHeader->RCode = (unsigned char)_errorReplyCode;
|
||||
_dnsHeader->QDCount = 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user