MDNS mdns_query_ptr don't give results
Posted: Fri Jan 03, 2025 6:27 pm
I have a network, with 2 or more devices. Each device has an unique hostname and devices needs to get other devices hostname.
Resolving the mdns host with the "mdns_query_a" method works if I enter the names precisely, but the devices do not know the names of the other hosts: they have to infer this from the services that are exposed.
Simplifying the code, these are the sources of the initializations:
Device1:
Device2:
Well, after the connection, each devices need to get the others connected devices hostnames.
Device1:
Device2:
Both the devices can print the query results:
Each devices get a result with many record (even if only one other device is on the same network), but the instance_name, and the hostname are ever empty string (not null, only empty) and addr is ever 0.
In menuconfig in each device those settings are enabled: Enable responding to IPv4 reverse queries, multiple instances under the same device, and Use predefined interface for Ethernet.
Where am I going wrong?
Resolving the mdns host with the "mdns_query_a" method works if I enter the names precisely, but the devices do not know the names of the other hosts: they have to infer this from the services that are exposed.
Simplifying the code, these are the sources of the initializations:
Device1:
Code: Select all
mdns_init();
mdns_hostname_set("Device1");
mdns_instance_name_set("Device1");
mdns_service_add("Dev1Service", "ServiceA", "_tcp", 60667, NULL, 0);
Code: Select all
mdns_init();
mdns_hostname_set("Device2");
mdns_instance_name_set("Device2");
mdns_service_add("Dev2Service", "ServiceB", "_tcp", 60668, NULL, 0);
Device1:
Code: Select all
mdns_result_t *results = NULL;
mdns_query_ptr("ServiceB", "_tcp", 60668, 100, &results);
Code: Select all
mdns_result_t *results = NULL;
mdns_query_ptr("ServiceA", "_tcp", 60667, 100, &results);
Code: Select all
void mdns_print_results(mdns_result_t * results) {
mdns_result_t * r = results;
mdns_ip_addr_t * a = NULL;
int i = 1, t;
while (r) {
if (r->instance_name) {
printf(" PTR : %s\n", r->instance_name);
}
if (r->hostname) {
printf(" SRV : %s.local:%u\n", r->hostname, r->port);
}
if (r->txt_count) {
printf(" TXT : [%u] ", r->txt_count);
for (t = 0; t<r->txt_count; t++) {
printf("%s=%s; ", r->txt[t].key, r->txt[t].value);
}
printf("\n");
}
a = r->addr;
while (a) {
if (a->addr.type==IPADDR_TYPE_V6) {
printf(" IPV6: " IPV6STR "\n", IPV62STR(a->addr.u_addr.ip6));
}
else {
printf(" IPV4 : " IPSTR "\n", IP2STR(&(a->addr.u_addr.ip4)));
}
a = a->next;
}
r = r->next;
}
}
In menuconfig in each device those settings are enabled: Enable responding to IPv4 reverse queries, multiple instances under the same device, and Use predefined interface for Ethernet.
Where am I going wrong?