@@ -2993,6 +2993,27 @@ static void free_address_list(mdns_ip_addr_t *address_list)
2993
2993
}
2994
2994
}
2995
2995
2996
+
2997
+ static bool _mdns_delegate_hostname_set_address (const char * hostname , mdns_ip_addr_t * address_list )
2998
+ {
2999
+ if (!_str_null_or_empty (_mdns_server -> hostname ) &&
3000
+ strcasecmp (hostname , _mdns_server -> hostname ) == 0 ) {
3001
+ return false;
3002
+ }
3003
+ mdns_host_item_t * host = _mdns_host_list ;
3004
+ while (host != NULL ) {
3005
+ if (strcasecmp (hostname , host -> hostname ) == 0 ) {
3006
+ // free previous address list
3007
+ free_address_list (host -> address_list );
3008
+ // set current address list to the host
3009
+ host -> address_list = address_list ;
3010
+ return true;
3011
+ }
3012
+ host = host -> next ;
3013
+ }
3014
+ return false;
3015
+ }
3016
+
2996
3017
static mdns_ip_addr_t * copy_address_list (const mdns_ip_addr_t * address_list )
2997
3018
{
2998
3019
mdns_ip_addr_t * head = NULL ;
@@ -4845,6 +4866,7 @@ static void _mdns_free_action(mdns_action_t *action)
4845
4866
case ACTION_RX_HANDLE :
4846
4867
_mdns_packet_free (action -> data .rx_handle .packet );
4847
4868
break ;
4869
+ case ACTION_DELEGATE_HOSTNAME_SET_ADDR :
4848
4870
case ACTION_DELEGATE_HOSTNAME_ADD :
4849
4871
free ((char * )action -> data .delegate_hostname .hostname );
4850
4872
free_address_list (action -> data .delegate_hostname .address_list );
@@ -5065,6 +5087,13 @@ static void _mdns_execute_action(mdns_action_t *action)
5065
5087
free_address_list (action -> data .delegate_hostname .address_list );
5066
5088
}
5067
5089
break ;
5090
+ case ACTION_DELEGATE_HOSTNAME_SET_ADDR :
5091
+ if (!_mdns_delegate_hostname_set_address (action -> data .delegate_hostname .hostname ,
5092
+ action -> data .delegate_hostname .address_list )) {
5093
+ free_address_list (action -> data .delegate_hostname .address_list );
5094
+ }
5095
+ free ((char * )action -> data .delegate_hostname .hostname );
5096
+ break ;
5068
5097
case ACTION_DELEGATE_HOSTNAME_REMOVE :
5069
5098
_mdns_delegate_hostname_remove (action -> data .delegate_hostname .hostname );
5070
5099
free ((char * )action -> data .delegate_hostname .hostname );
@@ -5634,6 +5663,36 @@ esp_err_t mdns_delegate_hostname_remove(const char *hostname)
5634
5663
return ESP_OK ;
5635
5664
}
5636
5665
5666
+ esp_err_t mdns_delegate_hostname_set_address (const char * hostname , const mdns_ip_addr_t * address_list )
5667
+ {
5668
+ if (!_mdns_server ) {
5669
+ return ESP_ERR_INVALID_STATE ;
5670
+ }
5671
+ if (_str_null_or_empty (hostname ) || strlen (hostname ) > (MDNS_NAME_BUF_LEN - 1 )) {
5672
+ return ESP_ERR_INVALID_ARG ;
5673
+ }
5674
+ char * new_hostname = strndup (hostname , MDNS_NAME_BUF_LEN - 1 );
5675
+ if (!new_hostname ) {
5676
+ return ESP_ERR_NO_MEM ;
5677
+ }
5678
+
5679
+ mdns_action_t * action = (mdns_action_t * )malloc (sizeof (mdns_action_t ));
5680
+ if (!action ) {
5681
+ HOOK_MALLOC_FAILED ;
5682
+ free (new_hostname );
5683
+ return ESP_ERR_NO_MEM ;
5684
+ }
5685
+ action -> type = ACTION_DELEGATE_HOSTNAME_SET_ADDR ;
5686
+ action -> data .delegate_hostname .hostname = new_hostname ;
5687
+ action -> data .delegate_hostname .address_list = copy_address_list (address_list );
5688
+ if (xQueueSend (_mdns_server -> action_queue , & action , (TickType_t )0 ) != pdPASS ) {
5689
+ free (new_hostname );
5690
+ free (action );
5691
+ return ESP_ERR_NO_MEM ;
5692
+ }
5693
+ return ESP_OK ;
5694
+ }
5695
+
5637
5696
bool mdns_hostname_exists (const char * hostname )
5638
5697
{
5639
5698
return _hostname_is_ours (hostname );
0 commit comments