@@ -437,8 +437,8 @@ static const uint8_t *_mdns_read_fqdn(const uint8_t *packet, const uint8_t *star
437
437
if (name -> parts == 1 && buf [0 ] != '_'
438
438
&& (strcasecmp (buf , MDNS_DEFAULT_DOMAIN ) != 0 )
439
439
&& (strcasecmp (buf , "arpa" ) != 0 )
440
- && (strcasecmp (buf , "ip6" ) != 0 )
441
440
#ifndef CONFIG_MDNS_RESPOND_REVERSE_QUERIES
441
+ && (strcasecmp (buf , "ip6" ) != 0 )
442
442
&& (strcasecmp (buf , "in-addr" ) != 0 )
443
443
#endif
444
444
) {
@@ -1162,7 +1162,7 @@ static uint16_t _mdns_append_question(uint8_t *packet, uint16_t *index, mdns_out
1162
1162
{
1163
1163
uint8_t part_length ;
1164
1164
#ifdef CONFIG_MDNS_RESPOND_REVERSE_QUERIES
1165
- if (q -> host && strstr (q -> host , "in-addr" )) {
1165
+ if (q -> host && ( strstr (q -> host , "in-addr" ) || strstr ( q -> host , "ip6" ) )) {
1166
1166
part_length = append_fqdn_dots (packet , index , q -> host , false);
1167
1167
if (!part_length ) {
1168
1168
return 0 ;
@@ -1275,7 +1275,7 @@ static uint8_t _mdns_append_host_answer(uint8_t *packet, uint16_t *index, mdns_h
1275
1275
*/
1276
1276
static uint8_t _mdns_append_reverse_ptr_record (uint8_t * packet , uint16_t * index , const char * name )
1277
1277
{
1278
- if (strstr (name , "in-addr" ) == NULL ) {
1278
+ if (strstr (name , "in-addr" ) == NULL && strstr ( name , "ip6" ) == NULL ) {
1279
1279
return 0 ;
1280
1280
}
1281
1281
@@ -1339,7 +1339,8 @@ static uint8_t _mdns_append_answer(uint8_t *packet, uint16_t *index, mdns_out_an
1339
1339
if (answer -> service ) {
1340
1340
return _mdns_append_service_ptr_answers (packet , index , answer -> service , answer -> flush , answer -> bye );
1341
1341
#ifdef CONFIG_MDNS_RESPOND_REVERSE_QUERIES
1342
- } else if (answer -> host && answer -> host -> hostname && strstr (answer -> host -> hostname , "in-addr" )) {
1342
+ } else if (answer -> host && answer -> host -> hostname &&
1343
+ (strstr (answer -> host -> hostname , "in-addr" ) || strstr (answer -> host -> hostname , "ip6" ))) {
1343
1344
return _mdns_append_reverse_ptr_record (packet , index , answer -> host -> hostname ) > 0 ;
1344
1345
#endif /* CONFIG_MDNS_RESPOND_REVERSE_QUERIES */
1345
1346
} else {
@@ -3966,6 +3967,13 @@ void _mdns_disable_pcb(mdns_if_t tcpip_if, mdns_ip_protocol_t ip_protocol)
3966
3967
_mdns_server -> interfaces [tcpip_if ].pcbs [ip_protocol ].state = PCB_OFF ;
3967
3968
}
3968
3969
3970
+ #ifdef CONFIG_MDNS_RESPOND_REVERSE_QUERIES
3971
+ static inline char nibble_to_hex (int var )
3972
+ {
3973
+ return var > 9 ? var - 10 + 'a' : var + '0' ;
3974
+ }
3975
+ #endif
3976
+
3969
3977
/**
3970
3978
* @brief Performs interface changes based on system events or custom commands
3971
3979
*/
@@ -4007,6 +4015,31 @@ static void perform_event_action(mdns_if_t mdns_if, mdns_event_actions_t action)
4007
4015
}
4008
4016
}
4009
4017
}
4018
+
4019
+ if (action & MDNS_EVENT_IP6_REVERSE_LOOKUP ) {
4020
+ esp_ip6_addr_t addr6 ;
4021
+ if (!esp_netif_get_ip6_linklocal (_mdns_get_esp_netif (mdns_if ), & addr6 ) && !_ipv6_address_is_zero (addr6 )) {
4022
+ uint8_t * paddr = (uint8_t * )& addr6 .addr ;
4023
+ const char sub [] = "ip6" ;
4024
+ const size_t query_name_size = 4 * sizeof (addr6 .addr ) /* (2 nibbles + 2 dots)/per byte of IP address */ + sizeof (sub );
4025
+ char * reverse_query_name = malloc (query_name_size );
4026
+ if (reverse_query_name ) {
4027
+ char * ptr = & reverse_query_name [query_name_size ]; // point to the end
4028
+ memcpy (ptr - sizeof (sub ), sub , sizeof (sub )); // copy the IP sub-domain
4029
+ ptr -= sizeof (sub ) + 1 ; // move before the sub-domain
4030
+ while (reverse_query_name < ptr ) { // continue populating reverse query from the end
4031
+ * ptr -- = '.' ; // nibble by nibble, until we reach the beginning
4032
+ * ptr -- = nibble_to_hex (((* paddr ) >> 4 ) & 0x0F );
4033
+ * ptr -- = '.' ;
4034
+ * ptr -- = nibble_to_hex ((* paddr ) & 0x0F );
4035
+ paddr ++ ;
4036
+ }
4037
+ ESP_LOGD (TAG , "Registered reverse query: %s.arpa" , reverse_query_name );
4038
+ _mdns_delegate_hostname_add (reverse_query_name , NULL );
4039
+ }
4040
+ }
4041
+ }
4042
+
4010
4043
#endif /* CONFIG_MDNS_RESPOND_REVERSE_QUERIES */
4011
4044
}
4012
4045
0 commit comments