Skip to content

Commit

Permalink
Fixing compiler warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrdunk committed Apr 16, 2017
1 parent 613b31f commit 0214e00
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 36 deletions.
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=esp8266_mdns
version=1.1.5
version=1.1.6
author=mrdunk
maintainer=mrdunk
sentence=mDNS queries and responses on esp8266.
Expand Down
32 changes: 17 additions & 15 deletions mdns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,17 +377,18 @@ void MDns::Parse_Answer(Answer& answer) {
buffer_pointer = nameFromDnsPointer(answer.name_buffer, 0, MAX_MDNS_NAME_LEN,
data_buffer, buffer_pointer);

answer.rrtype = (data_buffer[buffer_pointer++] << 8) + data_buffer[buffer_pointer++];
answer.rrtype = (data_buffer[buffer_pointer++] << 8);
answer.rrtype += data_buffer[buffer_pointer++];

byte rrclass_0 = data_buffer[buffer_pointer++];
byte rrclass_1 = data_buffer[buffer_pointer++];
answer.rrset = (0b10000000 & rrclass_0);
answer.rrclass = ((rrclass_0 & 0b01111111) << 8) + rrclass_1;

answer.rrttl = (data_buffer[buffer_pointer++] << 24) +
(data_buffer[buffer_pointer++] << 16) +
(data_buffer[buffer_pointer++] << 8) +
data_buffer[buffer_pointer++];
answer.rrttl = (data_buffer[buffer_pointer++] << 24);
answer.rrttl += (data_buffer[buffer_pointer++] << 16);
answer.rrttl += (data_buffer[buffer_pointer++] << 8);
answer.rrttl += data_buffer[buffer_pointer++];

if (buffer_pointer > data_size) {
// We've over-run the returned data.
Expand Down Expand Up @@ -440,18 +441,19 @@ void MDns::DisplayRawPacket() const {


void MDns::PopulateAnswerResult(Answer* answer) {
int rdlength = (data_buffer[buffer_pointer++] << 8) + data_buffer[buffer_pointer++];
int rdlength = (data_buffer[buffer_pointer++] << 8);
rdlength += data_buffer[buffer_pointer++];

switch (answer->rrtype) {
case MDNS_TYPE_A: // Returns a 32-bit IPv4 address
if (MAX_MDNS_NAME_LEN >= 16) {
sprintf(answer->rdata_buffer, "%u.%u.%u.%u",
data_buffer[buffer_pointer++], data_buffer[buffer_pointer++],
data_buffer[buffer_pointer++], data_buffer[buffer_pointer++]);
data_buffer[buffer_pointer], data_buffer[buffer_pointer +1],
data_buffer[buffer_pointer +2], data_buffer[buffer_pointer +3]);
} else {
sprintf(answer->rdata_buffer, "ipv4");
buffer_pointer += 4;
}
buffer_pointer += 4;
break;
case MDNS_TYPE_PTR: // Pointer to a canonical name.
buffer_pointer = nameFromDnsPointer(answer->rdata_buffer, 0, MAX_MDNS_NAME_LEN,
Expand Down Expand Up @@ -482,12 +484,12 @@ void MDns::PopulateAnswerResult(Answer* answer) {
break;
case MDNS_TYPE_SRV: // Server Selection.
{
const unsigned int priority = (data_buffer[buffer_pointer++] << 8) +
data_buffer[buffer_pointer++];
const unsigned int weight = (data_buffer[buffer_pointer++] << 8) +
data_buffer[buffer_pointer++];
const unsigned int port = (data_buffer[buffer_pointer++] << 8) +
data_buffer[buffer_pointer++];
unsigned int priority = (data_buffer[buffer_pointer++] << 8);
priority += data_buffer[buffer_pointer++];
unsigned int weight = (data_buffer[buffer_pointer++] << 8);
weight += data_buffer[buffer_pointer++];
unsigned int port = (data_buffer[buffer_pointer++] << 8);
port += data_buffer[buffer_pointer++];
sprintf(answer->rdata_buffer, "p=%u;w=%u;port=%u;host=", priority, weight, port);

buffer_pointer = nameFromDnsPointer(answer->rdata_buffer, strlen(answer->rdata_buffer),
Expand Down
40 changes: 20 additions & 20 deletions mdns.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ typedef struct Answer{
} Answer;

class MDns {
private:
public:
// Simple constructor does not fire any callbacks on incoming data.
// Default incoming data_buffer size is used.
Expand All @@ -77,9 +78,9 @@ class MDns {
// p_packet_function : Callback fires for every mDNS packet that arrives.
// p_query_function : Callback fires for every mDNS Query that arrives as part of a packet.
// p_answer_function : Callback fires for every mDNS Answer that arrives as part of a packet.
MDns(void(*p_packet_function)(const MDns*),
void(*p_query_function)(const Query*),
void(*p_answer_function)(const Answer*)) :
MDns(void (*p_packet_function)(const MDns*),
void (*p_query_function)(const Query*),
void (*p_answer_function)(const Answer*)) :
MDns(p_packet_function, p_query_function, p_answer_function, MAX_PACKET_SIZE) { }

// Constructor takes callbacks which fire when mDNS data arrives.
Expand All @@ -88,9 +89,9 @@ class MDns {
// p_query_function : Callback fires for every mDNS Query that arrives as part of a packet.
// p_answer_function : Callback fires for every mDNS Answer that arrives as part of a packet.
// max_packet_size_ : Set the data_buffer size allocated to store incoming packets.
MDns(void(*p_packet_function)(const MDns*),
void(*p_query_function)(const Query*),
void(*p_answer_function)(const Answer*),
MDns(void (*p_packet_function)(const MDns*),
void (*p_query_function)(const Query*),
void (*p_answer_function)(const Answer*),
int max_packet_size_) :
#ifdef DEBUG_STATISTICS
buffer_size_fail(0),
Expand All @@ -101,8 +102,8 @@ class MDns {
p_query_function_(p_query_function),
p_answer_function_(p_answer_function),
buffer_pointer(0),
max_packet_size(max_packet_size_),
data_buffer(new byte[max_packet_size_])
data_buffer(new byte[max_packet_size_]),
max_packet_size(max_packet_size_)
{ };

// Constructor can be passed the buffer to hold the mDNS data.
Expand All @@ -112,9 +113,9 @@ class MDns {
// p_query_function : Callback fires for every mDNS Query that arrives as part of a packet.
// p_answer_function : Callback fires for every mDNS Answer that arrives as part of a packet.
// max_packet_size_ : Set the data_buffer size allocated to store incoming packets.
MDns(void(*p_packet_function)(const MDns*),
void(*p_query_function)(const Query*),
void(*p_answer_function)(const Answer*),
MDns(void (*p_packet_function)(const MDns*),
void (*p_query_function)(const Query*),
void (*p_answer_function)(const Answer*),
byte* data_buffer_,
int max_packet_size_) :
#ifdef DEBUG_STATISTICS
Expand Down Expand Up @@ -179,26 +180,25 @@ class MDns {
bool init;

// Pointer to function that gets called for every incoming mDNS packet.
void(*p_packet_function_)(const MDns*);
void (*p_packet_function_)(const MDns*);

// Pointer to function that gets called for every incoming query.
void(*p_query_function_)(const Query*);
void (*p_query_function_)(const Query*);

// Pointer to function that gets called for every incoming answer.
void(*p_answer_function_)(const Answer*);

// Size of mDNS packet.
unsigned int data_size;
void (*p_answer_function_)(const Answer*);

// Position in data_buffer while processing packet.
unsigned int buffer_pointer;

// Buffer containing mDNS packet.
byte* data_buffer;

// Buffer size for incoming MDns packet.
unsigned int max_packet_size;

// Buffer containing mDNS packet.
//byte data_buffer[MAX_PACKET_SIZE];
byte* data_buffer;
// Size of mDNS packet.
unsigned int data_size;

// Query or Answer
bool type;
Expand Down

0 comments on commit 0214e00

Please sign in to comment.