@@ -160,6 +160,7 @@ static bool _mdns_service_match(const mdns_service_t * srv, const char * service
160
160
* @param server the server
161
161
* @param service service type to match
162
162
* @param proto proto to match
163
+ * @param hostname hostname of the service (if non-null)
163
164
*
164
165
* @return the service item if found or NULL on error
165
166
*/
@@ -177,7 +178,7 @@ static mdns_srv_item_t * _mdns_get_service_item(const char * service, const char
177
178
178
179
static mdns_host_item_t * mdns_get_host_item (const char * hostname )
179
180
{
180
- if (hostname == NULL || strcasecmp (hostname , _mdns_server -> hostname ) == 0 ) {
181
+ if (strcasecmp (hostname , _mdns_server -> hostname ) == 0 ) {
181
182
return & _mdns_self_host ;
182
183
}
183
184
mdns_host_item_t * host = _mdns_host_list ;
@@ -1122,22 +1123,14 @@ static void _mdns_free_tx_packet(mdns_tx_packet_t * packet)
1122
1123
if (!packet ) {
1123
1124
return ;
1124
1125
}
1125
- mdns_out_question_t * q = packet -> questions ;
1126
+ mdns_out_question_t * q = packet -> questions ;
1126
1127
while (q ) {
1127
- mdns_out_question_t * next = q -> next ;
1128
+ mdns_out_question_t * next = q -> next ;
1128
1129
if (q -> own_dynamic_memory ) {
1129
- if (q -> host ) {
1130
- free ((char * )q -> host );
1131
- }
1132
- if (q -> service ) {
1133
- free ((char * )q -> service );
1134
- }
1135
- if (q -> proto ) {
1136
- free ((char * )q -> proto );
1137
- }
1138
- if (q -> domain ) {
1139
- free ((char * )q -> domain );
1140
- }
1130
+ free ((char * )q -> host );
1131
+ free ((char * )q -> service );
1132
+ free ((char * )q -> proto );
1133
+ free ((char * )q -> domain );
1141
1134
}
1142
1135
free (q );
1143
1136
q = next ;
@@ -4870,7 +4863,8 @@ esp_err_t mdns_instance_name_set(const char * instance)
4870
4863
esp_err_t mdns_service_add_for_host (const char * instance , const char * service , const char * proto ,
4871
4864
const char * hostname , uint16_t port , mdns_txt_item_t txt [], size_t num_items )
4872
4865
{
4873
- if (!_mdns_server || _str_null_or_empty (service ) || _str_null_or_empty (proto ) || !port ) {
4866
+ if (!_mdns_server || _str_null_or_empty (service ) || _str_null_or_empty (proto ) || _str_null_or_empty (hostname ) ||
4867
+ !port ) {
4874
4868
return ESP_ERR_INVALID_ARG ;
4875
4869
}
4876
4870
@@ -4930,7 +4924,7 @@ esp_err_t mdns_service_add_for_host(const char * instance, const char * service,
4930
4924
esp_err_t mdns_service_add (const char * instance , const char * service , const char * proto , uint16_t port ,
4931
4925
mdns_txt_item_t txt [], size_t num_items )
4932
4926
{
4933
- if (!_mdns_server ) {
4927
+ if (!_mdns_server || _str_null_or_empty ( _mdns_server -> hostname ) ) {
4934
4928
return ESP_ERR_INVALID_STATE ;
4935
4929
}
4936
4930
return mdns_service_add_for_host (instance , service , proto , _mdns_server -> hostname , port , txt , num_items );
@@ -5405,7 +5399,7 @@ void mdns_debug_packet(const uint8_t * data, size_t len)
5405
5399
header .answers = 0 ;
5406
5400
header .additional = 0 ;
5407
5401
header .servers = 0 ;
5408
- _mdns_dbg_printf ("ERROR: %s:%u \n" , __FILE__ , __LINE__ );
5402
+ _mdns_dbg_printf ("ERROR: parse header questions \n" );
5409
5403
break ;
5410
5404
}
5411
5405
@@ -5453,7 +5447,7 @@ void mdns_debug_packet(const uint8_t * data, size_t len)
5453
5447
5454
5448
content = _mdns_parse_fqdn (data , content , name );
5455
5449
if (!content ) {
5456
- _mdns_dbg_printf ("ERROR: %s:%u \n" , __FILE__ , __LINE__ );
5450
+ _mdns_dbg_printf ("ERROR: parse mdns records \n" );
5457
5451
break ;
5458
5452
}
5459
5453
@@ -5467,7 +5461,7 @@ void mdns_debug_packet(const uint8_t * data, size_t len)
5467
5461
5468
5462
content = data_ptr + data_len ;
5469
5463
if (content > (data + len )) {
5470
- _mdns_dbg_printf ("ERROR: %s:%u \n" , __FILE__ , __LINE__ );
5464
+ _mdns_dbg_printf ("ERROR: content length overflow \n" );
5471
5465
break ;
5472
5466
}
5473
5467
@@ -5520,13 +5514,13 @@ void mdns_debug_packet(const uint8_t * data, size_t len)
5520
5514
_mdns_dbg_printf ("[%u] " , data_len );
5521
5515
if (type == MDNS_TYPE_PTR ) {
5522
5516
if (!_mdns_parse_fqdn (data , data_ptr , name )) {
5523
- _mdns_dbg_printf ("ERROR: %s:%u \n" , __FILE__ , __LINE__ );
5517
+ _mdns_dbg_printf ("ERROR: parse PTR \n" );
5524
5518
continue ;
5525
5519
}
5526
5520
_mdns_dbg_printf ("%s.%s.%s.%s.\n" , name -> host , name -> service , name -> proto , name -> domain );
5527
5521
} else if (type == MDNS_TYPE_SRV ) {
5528
5522
if (!_mdns_parse_fqdn (data , data_ptr + MDNS_SRV_FQDN_OFFSET , name )) {
5529
- _mdns_dbg_printf ("ERROR: %s:%u \n" , __FILE__ , __LINE__ );
5523
+ _mdns_dbg_printf ("ERROR: parse SRV \n" );
5530
5524
continue ;
5531
5525
}
5532
5526
uint16_t priority = _mdns_read_u16 (data_ptr , MDNS_SRV_PRIORITY_OFFSET );
@@ -5538,7 +5532,7 @@ void mdns_debug_packet(const uint8_t * data, size_t len)
5538
5532
while (i < data_len ) {
5539
5533
uint8_t partLen = data_ptr [i ++ ];
5540
5534
if ((i + partLen ) > data_len ) {
5541
- _mdns_dbg_printf ("ERROR: %s:%u \n" , __FILE__ , __LINE__ );
5535
+ _mdns_dbg_printf ("ERROR: parse TXT \n" );
5542
5536
break ;
5543
5537
}
5544
5538
char txt [partLen + 1 ];
0 commit comments