@@ -542,15 +542,24 @@ void MDNSResponder::_parsePacket(){
542
542
while (numAnswers--) {
543
543
// Read name
544
544
stringsRead = 0 ;
545
+ size_t last_bufferpos = 0 ;
545
546
do {
546
547
tmp8 = _conn_read8 ();
547
- if (tmp8 & 0xC0 ) { // Compressed pointer (not supported)
548
- tmp8 = _conn_read8 ();
549
- break ;
550
- }
551
548
if (tmp8 == 0x00 ) { // End of name
552
549
break ;
553
550
}
551
+ if (tmp8 & 0xC0 ) { // Compressed pointer
552
+ uint16_t offset = ((((uint16_t )tmp8) & ~0xC0 ) << 8 ) | _conn_read8 ();
553
+ last_bufferpos = _conn->tell ();
554
+ #ifdef DEBUG_ESP_MDNS_RX
555
+ DEBUG_ESP_PORT.print (" Compressed pointer, jumping from " );
556
+ DEBUG_ESP_PORT.print (last_bufferpos);
557
+ DEBUG_ESP_PORT.print (" to " );
558
+ DEBUG_ESP_PORT.println (offset);
559
+ #endif
560
+ _conn->seek (offset);
561
+ tmp8 = _conn_read8 ();
562
+ }
554
563
if (stringsRead > 3 ){
555
564
#ifdef DEBUG_ESP_MDNS_RX
556
565
DEBUG_ESP_PORT.println (" failed to read the response name" );
@@ -577,6 +586,14 @@ void MDNSResponder::_parsePacket(){
577
586
}
578
587
stringsRead++;
579
588
} while (true );
589
+ if (last_bufferpos > 0 )
590
+ {
591
+ _conn->seek (last_bufferpos);
592
+ #ifdef DEBUG_ESP_MDNS_RX
593
+ DEBUG_ESP_PORT.print (" Compressed pointer, jumping back to " );
594
+ DEBUG_ESP_PORT.println (last_bufferpos);
595
+ #endif
596
+ }
580
597
581
598
uint16_t answerType = _conn_read16 (); // Read type
582
599
uint16_t answerClass = _conn_read16 (); // Read class
@@ -635,32 +652,45 @@ void MDNSResponder::_parsePacket(){
635
652
uint16_t answerPrio = _conn_read16 (); // Read priority
636
653
uint16_t answerWeight = _conn_read16 (); // Read weight
637
654
answerPort = _conn_read16 (); // Read port
655
+ last_bufferpos = 0 ;
638
656
639
657
(void ) answerPrio;
640
658
(void ) answerWeight;
641
659
642
660
// Read hostname
643
661
tmp8 = _conn_read8 ();
644
- if (tmp8 & 0xC0 ) { // Compressed pointer (not supported)
662
+ if (tmp8 & 0xC0 ) { // Compressed pointer
663
+ uint16_t offset = ((((uint16_t )tmp8) & ~0xC0 ) << 8 ) | _conn_read8 ();
664
+ last_bufferpos = _conn->tell ();
645
665
#ifdef DEBUG_ESP_MDNS_RX
646
- DEBUG_ESP_PORT.println (" Skipping compressed pointer" );
666
+ DEBUG_ESP_PORT.print (" Compressed pointer, jumping from " );
667
+ DEBUG_ESP_PORT.print (last_bufferpos);
668
+ DEBUG_ESP_PORT.print (" to " );
669
+ DEBUG_ESP_PORT.println (offset);
647
670
#endif
671
+ _conn->seek (offset);
648
672
tmp8 = _conn_read8 ();
649
673
}
650
-
651
- else {
652
- _conn_readS (answerHostName, tmp8);
653
- answerHostName[tmp8] = ' \0 ' ;
674
+ _conn_readS (answerHostName, tmp8);
675
+ answerHostName[tmp8] = ' \0 ' ;
654
676
#ifdef DEBUG_ESP_MDNS_RX
655
- DEBUG_ESP_PORT.printf (" SRV %d " , tmp8);
656
- for (int n = 0 ; n < tmp8; n++) {
657
- DEBUG_ESP_PORT.printf (" %02x " , answerHostName[n]);
658
- }
659
- DEBUG_ESP_PORT.printf (" \n %s\n " , answerHostName);
677
+ DEBUG_ESP_PORT.printf (" SRV %d " , tmp8);
678
+ for (int n = 0 ; n < tmp8; n++) {
679
+ DEBUG_ESP_PORT.printf (" %02x " , answerHostName[n]);
680
+ }
681
+ DEBUG_ESP_PORT.printf (" \n %s\n " , answerHostName);
660
682
#endif
661
- if (answerRdlength - (6 + 1 + tmp8) > 0 ) { // Skip any remaining rdata
662
- _conn_readS (hostName, answerRdlength - (6 + 1 + tmp8));
663
- }
683
+ if (last_bufferpos > 0 )
684
+ {
685
+ _conn->seek (last_bufferpos);
686
+ tmp8 = 2 ; // Size of compression octets
687
+ #ifdef DEBUG_ESP_MDNS_RX
688
+ DEBUG_ESP_PORT.print (" Compressed pointer, jumping back to " );
689
+ DEBUG_ESP_PORT.println (last_bufferpos);
690
+ #endif
691
+ }
692
+ if (answerRdlength - (6 + 1 + tmp8) > 0 ) { // Skip any remaining rdata
693
+ _conn_readS (hostName, answerRdlength - (6 + 1 + tmp8));
664
694
}
665
695
}
666
696
@@ -675,7 +705,7 @@ void MDNSResponder::_parsePacket(){
675
705
DEBUG_ESP_PORT.printf (" Ignoring unsupported type %02x\n " , tmp8);
676
706
#endif
677
707
for (int n = 0 ; n < answerRdlength; n++)
678
- (void )_conn_read8 ();
708
+ (void )_conn_read8 ();
679
709
}
680
710
681
711
if ((partsCollected == 0x0F ) && serviceMatch) {
0 commit comments