Skip to content

Commit af1f39e

Browse files
authored
Merge pull request #355 from wqx6/mdns_service_limit
fix(mdns): remove the range of MDNS_MAX_SERVICES and fix some issues of str-functions
2 parents b8f3423 + 3dadce2 commit af1f39e

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

components/mdns/Kconfig

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,11 @@ menu "mDNS"
1010

1111
config MDNS_MAX_SERVICES
1212
int "Max number of services"
13-
range 1 64
1413
default 10
1514
help
1615
Services take up a certain amount of memory, and allowing fewer
1716
services to be open at the same time conserves memory. Specify
18-
the maximum amount of services here. The valid value is from 1
19-
to 64.
17+
the maximum amount of services here.
2018

2119
config MDNS_TASK_PRIORITY
2220
int "mDNS task priority"

components/mdns/mdns.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5597,9 +5597,14 @@ esp_err_t mdns_hostname_set(const char *hostname)
55975597

55985598
esp_err_t mdns_hostname_get(char *hostname)
55995599
{
5600-
if (!_mdns_server || !hostname) {
5600+
if (!hostname) {
56015601
return ESP_ERR_INVALID_ARG;
56025602
}
5603+
5604+
if (!_mdns_server || !_mdns_server->hostname) {
5605+
return ESP_ERR_INVALID_STATE;
5606+
}
5607+
56035608
MDNS_SERVICE_LOCK();
56045609
strncpy(hostname, _mdns_server->hostname, strnlen(_mdns_server->hostname, MDNS_NAME_BUF_LEN));
56055610
MDNS_SERVICE_UNLOCK();
@@ -5902,10 +5907,14 @@ static mdns_result_t *_mdns_lookup_service(const char *instance, const char *ser
59025907
item->esp_netif = NULL;
59035908
item->ttl = _str_null_or_empty(instance) ? MDNS_ANSWER_PTR_TTL : MDNS_ANSWER_SRV_TTL;
59045909
item->ip_protocol = MDNS_IP_PROTOCOL_MAX;
5905-
item->instance_name = strndup(srv->instance, MDNS_NAME_BUF_LEN - 1);
5906-
if (!item->instance_name) {
5907-
HOOK_MALLOC_FAILED;
5908-
goto handle_error;
5910+
if (srv->instance) {
5911+
item->instance_name = strndup(srv->instance, MDNS_NAME_BUF_LEN - 1);
5912+
if (!item->instance_name) {
5913+
HOOK_MALLOC_FAILED;
5914+
goto handle_error;
5915+
}
5916+
} else {
5917+
item->instance_name = NULL;
59095918
}
59105919
item->service_type = strndup(srv->service, MDNS_NAME_BUF_LEN - 1);
59115920
if (!item->service_type) {

0 commit comments

Comments
 (0)