Open gigaj0ule opened 1 year ago
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...
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.
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
I rewrote the entire service browser and now it works
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
When I use one arduino to generate an MDNS service, and another arduino to listen to the service...
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?