Skip to content

Commit 9fa25ef

Browse files
gjc13suren-gabrielyan-espressif
authored andcommitted
mdns: fix wrong service hostname after mangling
* Original commit: espressif/esp-idf@439b31d
1 parent 121b525 commit 9fa25ef

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

components/mdns/mdns.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ static void _mdns_search_result_add_txt(mdns_search_once_t * search, mdns_txt_it
4747
static mdns_result_t * _mdns_search_result_add_ptr(mdns_search_once_t * search, const char * instance, mdns_if_t tcpip_if, mdns_ip_protocol_t ip_protocol);
4848
static bool _mdns_append_host_list_in_services(mdns_out_answer_t ** destination, mdns_srv_item_t * services[], size_t services_len, bool flush, bool bye);
4949
static bool _mdns_append_host_list(mdns_out_answer_t ** destination, bool flush, bool bye);
50+
static void _mdns_remap_self_service_hostname(const char *old_hostname, const char *new_hostname);
5051

5152
/*
5253
* @brief Internal collection of mdns supported interfaces
@@ -3227,8 +3228,10 @@ void mdns_parse_packet(mdns_rx_packet_t * packet)
32273228
} else {
32283229
char * new_host = _mdns_mangle_name((char *)_mdns_server->hostname);
32293230
if (new_host) {
3231+
_mdns_remap_self_service_hostname(_mdns_server->hostname, new_host);
32303232
free((char *)_mdns_server->hostname);
32313233
_mdns_server->hostname = new_host;
3234+
_mdns_self_host.hostname = new_host;
32323235
}
32333236
_mdns_restart_all_pcbs();
32343237
}
@@ -3333,8 +3336,10 @@ void mdns_parse_packet(mdns_rx_packet_t * packet)
33333336
_mdns_server->interfaces[packet->tcpip_if].pcbs[packet->ip_protocol].failed_probes++;
33343337
char * new_host = _mdns_mangle_name((char *)_mdns_server->hostname);
33353338
if (new_host) {
3339+
_mdns_remap_self_service_hostname(_mdns_server->hostname, new_host);
33363340
free((char *)_mdns_server->hostname);
33373341
_mdns_server->hostname = new_host;
3342+
_mdns_self_host.hostname = new_host;
33383343
}
33393344
_mdns_restart_all_pcbs();
33403345
}
@@ -3381,8 +3386,10 @@ void mdns_parse_packet(mdns_rx_packet_t * packet)
33813386
_mdns_server->interfaces[packet->tcpip_if].pcbs[packet->ip_protocol].failed_probes++;
33823387
char * new_host = _mdns_mangle_name((char *)_mdns_server->hostname);
33833388
if (new_host) {
3389+
_mdns_remap_self_service_hostname(_mdns_server->hostname, new_host);
33843390
free((char *)_mdns_server->hostname);
33853391
_mdns_server->hostname = new_host;
3392+
_mdns_self_host.hostname = new_host;
33863393
}
33873394
_mdns_restart_all_pcbs();
33883395
}
@@ -4087,6 +4094,19 @@ static void _mdns_tx_handle_packet(mdns_tx_packet_t * p)
40874094
}
40884095
}
40894096

4097+
static void _mdns_remap_self_service_hostname(const char * old_hostname, const char * new_hostname)
4098+
{
4099+
mdns_srv_item_t * service = _mdns_server->services;
4100+
4101+
while (service) {
4102+
if (strcmp(service->service->hostname, old_hostname) == 0) {
4103+
free((char *)service->service->hostname);
4104+
service->service->hostname = strdup(new_hostname);
4105+
}
4106+
service = service->next;
4107+
}
4108+
}
4109+
40904110
/**
40914111
* @brief Free action data
40924112
*/
@@ -4154,6 +4174,7 @@ static void _mdns_execute_action(mdns_action_t * action)
41544174
break;
41554175
case ACTION_HOSTNAME_SET:
41564176
_mdns_send_bye_all_pcbs_no_instance(true);
4177+
_mdns_remap_self_service_hostname(_mdns_server->hostname, action->data.hostname_set.hostname);
41574178
free((char*)_mdns_server->hostname);
41584179
_mdns_server->hostname = action->data.hostname_set.hostname;
41594180
_mdns_self_host.hostname = action->data.hostname_set.hostname;

0 commit comments

Comments
 (0)