Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Service Discovery returns garbage data #20

Open
gigaj0ule opened this issue Feb 23, 2023 · 4 comments
Open

Service Discovery returns garbage data #20

gigaj0ule opened this issue Feb 23, 2023 · 4 comments
Labels
type: imperfection Perceived defect in any part of project

Comments

@gigaj0ule
Copy link

gigaj0ule commented Feb 23, 2023

When I use one arduino to generate an MDNS service, and another arduino to listen to the service...

  1. The service name is OK
  2. The IP address is OK, but sometimes, it's 0.0.0.0?
  3. The port is not the same port advertised by the arduino? Sometimes it is a random number.
  4. The text content is arbitrary garbage

It seems like adding the service record is OK, as on my host computer, I don't have issues reading the text data,

...but the service discovery on arduino is very broken?

@gigaj0ule
Copy link
Author

ah, the randomness was because our arrays were never initialized

         uint8_t* ptrNames[MDNS_MAX_SERVICES_PER_PACKET] ;
         uint16_t ptrOffsets[MDNS_MAX_SERVICES_PER_PACKET];
         uint16_t ptrPorts[MDNS_MAX_SERVICES_PER_PACKET];

changing them to

         uint8_t* ptrNames[MDNS_MAX_SERVICES_PER_PACKET] = {0};
         uint16_t ptrOffsets[MDNS_MAX_SERVICES_PER_PACKET] = {0};
         uint16_t ptrPorts[MDNS_MAX_SERVICES_PER_PACKET] = {0};

gives me port "0" instead of randomness, so indeed the packet parsing code is broken somewhere...

@per1234 per1234 added the type: imperfection Perceived defect in any part of project label Feb 23, 2023
@gigaj0ule
Copy link
Author

I think I found the source of the bug now.

There is simply no code at all that populates ptrPorts or servTxt until we get to the "additional records" part of the packet.

But, port and text are not "additional records". They are "query answers".

This is a pretty big control flow problem and I am not sure how to fix it yet since the code is so hard to understand still.

@gigaj0ule
Copy link
Author

gigaj0ule commented Feb 23, 2023

After spending 12 hours digging into the code, I don't think there is any way for an arduino to ask for TXT query.

I was watching the raw packet data coming in through the UDP buffer and nothing seemed to me like a txt response.

--wait--, I just saw the strings.

i'll try writing a packet filter to capture it

@gigaj0ule
Copy link
Author

gigaj0ule commented Feb 24, 2023

I rewrote the entire service browser and now it works

image

Basically i made a whole bunch of packet filters that search for strings just like wireshark.

I also got rid of dynamic memory allocation, as it was too complex for me to follow

There are a lot of changes so I should make a fork maybe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: imperfection Perceived defect in any part of project
Projects
None yet
Development

No branches or pull requests

2 participants