Skip to content

Commit

Permalink
Merge pull request #19 from ajanhalt/master
Browse files Browse the repository at this point in the history
Fix for core 3.0.0+, buffer_pointer comparison fixes
  • Loading branch information
mrdunk authored Feb 2, 2022
2 parents b7c88fd + aa07568 commit bd3eb1b
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 5 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ void setup() {
}
}
Serial.println();
my_mdns.begin();
}
void loop() {
Expand Down
1 change: 1 addition & 0 deletions examples/mdns_test/mdns_test.ino
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ void setup()

Serial.println("Connected to wifi");

my_mdns.begin(); // call to startUdpMulticast

// Query for all host information for a paticular service. ("_mqtt" in this case.)
my_mdns.Clear();
Expand Down
2 changes: 2 additions & 0 deletions examples/simple/simple.ino
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ void setup() {
}
printWifiStatus();
Serial.println();

my_mdns.begin(); // call to startUdpMulticast
}

unsigned int last_packet_count = 0;
Expand Down
13 changes: 10 additions & 3 deletions mdns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ void MDns::startUdpMulticast(){
Udp.beginMulticast(WiFi.localIP(), IPAddress(224, 0, 0, 251), MDNS_TARGET_PORT);
}

void MDns::begin() {
#ifdef DEBUG_OUTPUT
Serial.println("Called begin");
#endif
this->startUdpMulticast();
}

bool MDns::loop() {
data_size = Udp.parsePacket();
if ( data_size > 12) {
Expand Down Expand Up @@ -83,7 +90,7 @@ bool MDns::loop() {
p_query_function_(&query);
}
}
if(buffer_pointer >= data_size){
if(buffer_pointer > data_size){
return false;
}
#ifdef DEBUG_OUTPUT
Expand All @@ -100,7 +107,7 @@ bool MDns::loop() {
p_answer_function_(&answer);
}
}
if(buffer_pointer >= data_size){
if(buffer_pointer > data_size){
return false;
}
#ifdef DEBUG_OUTPUT
Expand Down Expand Up @@ -358,7 +365,7 @@ void MDns::Parse_Query(Query& query) {
query.valid = false;
}

if (buffer_pointer >= data_size) {
if (buffer_pointer > data_size) {
// We've over-run the returned data.
// Something has gone wrong receiving or parsing the data.
#ifdef DEBUG_OUTPUT
Expand Down
5 changes: 3 additions & 2 deletions mdns.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ class MDns {
data_buffer(new byte[max_packet_size_]),
max_packet_size(max_packet_size_)
{
this->startUdpMulticast();
};

// Constructor can be passed the buffer to hold the mDNS data.
Expand All @@ -132,11 +131,13 @@ class MDns {
data_buffer(data_buffer_),
max_packet_size(max_packet_size_)
{
this->startUdpMulticast();
};

~MDns();

// added to call startUdpMulticast
void begin();

// Call this regularly to check for an incoming packet.
bool loop();
// Deprecated. Use loop() instead.
Expand Down

0 comments on commit bd3eb1b

Please sign in to comment.