@@ -123,14 +123,29 @@ void DNSServer::replyWithIP()
123
123
if (_buffer == NULL ) return ;
124
124
_dnsHeader->QR = DNS_QR_RESPONSE;
125
125
_dnsHeader->ANCount = _dnsHeader->QDCount ;
126
- _dnsHeader->QDCount = 0 ;
126
+ // _dnsHeader->QDCount = 0;
127
127
128
128
_udp.beginPacket (_udp.remoteIP (), _udp.remotePort ());
129
129
_udp.write (_buffer, _currentPacketSize);
130
+
131
+ // Use DNS name compression : instead of repeating the name in this RNAME occurence,
132
+ // set the two MSB of the byte corresponding normally to the length to 1. The following
133
+ // 14 bits must be used to specify the offset of the domain name in the message
134
+ // (<255 here so the first byte has the 6 LSB at 0)
135
+ _udp.write ((uint8_t ) 0xC0 );
136
+ _udp.write ((uint8_t ) DNS_OFFSET_DOMAIN_NAME);
137
+ // DNS type A : host address
138
+ _udp.write ((uint8_t ) (DNS_TYPE_A >> 8 ) );
139
+ _udp.write ((uint8_t ) (DNS_TYPE_A & 0xFF ) );
140
+ // DNS class IN for INternet
141
+ _udp.write ((uint8_t ) (DNS_CLASS_IN >> 8 ) );
142
+ _udp.write ((uint8_t ) (DNS_CLASS_IN & 0xFF ) );
143
+ // DNS Time To Live
130
144
_udp.write ((unsigned char *)&_ttl, 4 );
131
- _udp.write ((uint8_t )0 );
132
- _udp.write ((uint8_t )4 );
133
- _udp.write (_resolvedIP, 4 );
145
+ // Returning an IPv4 address
146
+ _udp.write ((uint8_t ) (DNS_RDLENGTH_IPV4 >> 8 ) );
147
+ _udp.write ((uint8_t ) (DNS_RDLENGTH_IPV4 & 0xFF ) );
148
+ _udp.write (_resolvedIP, sizeof (_resolvedIP));
134
149
_udp.endPacket ();
135
150
}
136
151
0 commit comments