@@ -179,7 +179,8 @@ uint16_t DNSClient::BuildRequest(const char* aName)
179179
180180 // FIXME We should also check that there's enough space available to write to, rather
181181 // FIXME than assume there's enough space (as the code does at present)
182- iUdp.write ((uint8_t *)&iRequestId, sizeof (iRequestId));
182+ uint16_t _id = htons (iRequestId);
183+ iUdp.write ((uint8_t *)&_id, sizeof (_id));
183184
184185 twoByteBuffer = htons (QUERY_FLAG | OPCODE_STANDARD_QUERY | RECURSION_DESIRED_FLAG);
185186 iUdp.write ((uint8_t *)&twoByteBuffer, sizeof (twoByteBuffer));
@@ -264,9 +265,9 @@ uint16_t DNSClient::ProcessResponse(uint16_t aTimeout, IPAddress& aAddress)
264265 }
265266 iUdp.read (header, DNS_HEADER_SIZE);
266267
267- uint16_t header_flags = htons (*(( uint16_t *)& header[2 ]) );
268+ uint16_t header_flags = word ( header[2 ], header[ 3 ] );
268269 // Check that it's a response to this request
269- if ( ( iRequestId != (*(( uint16_t *)& header[0 ])) ) ||
270+ if ( (iRequestId != word ( header[0 ], header[ 1 ]) ) ||
270271 ((header_flags & QUERY_RESPONSE_MASK) != (uint16_t )RESPONSE_FLAG) )
271272 {
272273 // Mark the entire packet as read
@@ -283,7 +284,7 @@ uint16_t DNSClient::ProcessResponse(uint16_t aTimeout, IPAddress& aAddress)
283284 }
284285
285286 // And make sure we've got (at least) one answer
286- uint16_t answerCount = htons (*(( uint16_t *)& header[6 ]) );
287+ uint16_t answerCount = word ( header[6 ], header[ 7 ] );
287288 if (answerCount == 0 )
288289 {
289290 // Mark the entire packet as read
@@ -292,7 +293,7 @@ uint16_t DNSClient::ProcessResponse(uint16_t aTimeout, IPAddress& aAddress)
292293 }
293294
294295 // Skip over any questions
295- for (uint16_t i =0 ; i < htons (*(( uint16_t *)& header[4 ]) ); i++)
296+ for (uint16_t i =0 ; i < word ( header[4 ], header[ 5 ] ); i++)
296297 {
297298 // Skip over the name
298299 uint8_t len;
0 commit comments