1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-15 00:02:49 +03:00

Compressed dns (#3769)

* Add UdpContext seek and tell

* Add support for DNS compressed messages

* mDNS compressed pointer: Validate offset before jumping
This commit is contained in:
Jonatan Olofsson
2018-03-16 13:46:35 +01:00
committed by Develo
parent 836c7da8cc
commit 461c922586
3 changed files with 89 additions and 21 deletions

View File

@ -27,6 +27,7 @@ extern "C" {
void esp_yield();
void esp_schedule();
#include "lwip/init.h" // LWIP_VERSION_
#include <assert.h>
}
@ -143,6 +144,21 @@ public:
return _rx_buf->len - _rx_buf_offset;
}
size_t tell() const
{
return _rx_buf_offset;
}
void seek(const size_t pos)
{
assert(isValidOffset(pos));
_rx_buf_offset = pos;
}
bool isValidOffset(const size_t pos) const {
return (pos <= _rx_buf->len);
}
uint32_t getRemoteAddress()
{
if (!_rx_buf)
@ -203,7 +219,7 @@ public:
int read()
{
if (!_rx_buf || _rx_buf_offset == _rx_buf->len)
if (!_rx_buf || _rx_buf_offset >= _rx_buf->len)
return -1;
char c = reinterpret_cast<char*>(_rx_buf->payload)[_rx_buf_offset];
@ -361,6 +377,9 @@ private:
void _consume(size_t size)
{
_rx_buf_offset += size;
if (_rx_buf_offset > _rx_buf->len) {
_rx_buf_offset = _rx_buf->len;
}
}
void _recv(udp_pcb *upcb, pbuf *pb,