@@ -179,7 +179,8 @@ uint16_t DNSClient::BuildRequest(const char* aName)
179
179
180
180
// FIXME We should also check that there's enough space available to write to, rather
181
181
// 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));
183
184
184
185
twoByteBuffer = htons (QUERY_FLAG | OPCODE_STANDARD_QUERY | RECURSION_DESIRED_FLAG);
185
186
iUdp.write ((uint8_t *)&twoByteBuffer, sizeof (twoByteBuffer));
@@ -264,9 +265,9 @@ uint16_t DNSClient::ProcessResponse(uint16_t aTimeout, IPAddress& aAddress)
264
265
}
265
266
iUdp.read (header, DNS_HEADER_SIZE);
266
267
267
- uint16_t header_flags = htons (*(( uint16_t *)& header[2 ]) );
268
+ uint16_t header_flags = word ( header[2 ], header[ 3 ] );
268
269
// Check that it's a response to this request
269
- if ( ( iRequestId != (*(( uint16_t *)& header[0 ])) ) ||
270
+ if ( (iRequestId != word ( header[0 ], header[ 1 ]) ) ||
270
271
((header_flags & QUERY_RESPONSE_MASK) != (uint16_t )RESPONSE_FLAG) )
271
272
{
272
273
// Mark the entire packet as read
@@ -283,7 +284,7 @@ uint16_t DNSClient::ProcessResponse(uint16_t aTimeout, IPAddress& aAddress)
283
284
}
284
285
285
286
// 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 ] );
287
288
if (answerCount == 0 )
288
289
{
289
290
// Mark the entire packet as read
@@ -292,7 +293,7 @@ uint16_t DNSClient::ProcessResponse(uint16_t aTimeout, IPAddress& aAddress)
292
293
}
293
294
294
295
// 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++)
296
297
{
297
298
// Skip over the name
298
299
uint8_t len;
0 commit comments