Skip to content

Commit 68ac2ae

Browse files
committed
Remove redundant macros. Saves 32 bytes of memory
1 parent 481f960 commit 68ac2ae

File tree

3 files changed

+16
-36
lines changed

3 files changed

+16
-36
lines changed

src/Dhcp.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -134,15 +134,15 @@ void DhcpClass::send_DHCP_MESSAGE(uint8_t messageType, uint16_t secondsElapsed)
134134
buffer[3] = DHCP_HOPS; // hops
135135

136136
// xid
137-
unsigned long xid = htonl(_dhcpTransactionId);
137+
unsigned long xid = _dhcpTransactionId;
138138
memcpy(buffer + 4, &(xid), 4);
139139

140140
// 8, 9 - seconds elapsed
141141
buffer[8] = ((secondsElapsed & 0xff00) >> 8);
142142
buffer[9] = (secondsElapsed & 0x00ff);
143143

144144
// flags
145-
unsigned short flags = htons(DHCP_FLAGSBROADCAST);
145+
unsigned short flags = DHCP_FLAGSBROADCAST;
146146
memcpy(buffer + 10, &(flags), 2);
147147

148148
// ciaddr: already zeroed
@@ -251,7 +251,7 @@ uint8_t DhcpClass::parseDHCPResponse(unsigned long responseTimeout, uint32_t& tr
251251
_dhcpUdpSocket.read((uint8_t*)&fixedMsg, sizeof(RIP_MSG_FIXED));
252252

253253
if (fixedMsg.op == DHCP_BOOTREPLY && _dhcpUdpSocket.remotePort() == DHCP_SERVER_PORT) {
254-
transactionId = ntohl(fixedMsg.xid);
254+
transactionId = fixedMsg.xid;
255255
if (memcmp(fixedMsg.chaddr, _dhcpMacAddr, 6) != 0 ||
256256
(transactionId < _dhcpInitialTransactionId) ||
257257
(transactionId > _dhcpTransactionId)) {
@@ -309,19 +309,19 @@ uint8_t DhcpClass::parseDHCPResponse(unsigned long responseTimeout, uint32_t& tr
309309
case dhcpT1value :
310310
opt_len = _dhcpUdpSocket.read();
311311
_dhcpUdpSocket.read((uint8_t*)&_dhcpT1, sizeof(_dhcpT1));
312-
_dhcpT1 = ntohl(_dhcpT1);
312+
_dhcpT1 = _dhcpT1;
313313
break;
314314

315315
case dhcpT2value :
316316
opt_len = _dhcpUdpSocket.read();
317317
_dhcpUdpSocket.read((uint8_t*)&_dhcpT2, sizeof(_dhcpT2));
318-
_dhcpT2 = ntohl(_dhcpT2);
318+
_dhcpT2 = _dhcpT2;
319319
break;
320320

321321
case dhcpIPaddrLeaseTime :
322322
opt_len = _dhcpUdpSocket.read();
323323
_dhcpUdpSocket.read((uint8_t*)&_dhcpLeaseTime, sizeof(_dhcpLeaseTime));
324-
_dhcpLeaseTime = ntohl(_dhcpLeaseTime);
324+
_dhcpLeaseTime = _dhcpLeaseTime;
325325
_renewInSec = _dhcpLeaseTime;
326326
break;
327327

src/Dns.cpp

+10-10
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,10 @@ uint16_t DNSClient::BuildRequest(const char* aName)
161161
// FIXME than assume there's enough space (as the code does at present)
162162
iUdp.write((uint8_t*)&iRequestId, sizeof(iRequestId));
163163

164-
twoByteBuffer = htons(QUERY_FLAG | OPCODE_STANDARD_QUERY | RECURSION_DESIRED_FLAG);
164+
twoByteBuffer = QUERY_FLAG | OPCODE_STANDARD_QUERY | RECURSION_DESIRED_FLAG;
165165
iUdp.write((uint8_t*)&twoByteBuffer, sizeof(twoByteBuffer));
166166

167-
twoByteBuffer = htons(1); // One question record
167+
twoByteBuffer = 1; // One question record
168168
iUdp.write((uint8_t*)&twoByteBuffer, sizeof(twoByteBuffer));
169169

170170
twoByteBuffer = 0; // Zero answer records
@@ -201,10 +201,10 @@ uint16_t DNSClient::BuildRequest(const char* aName)
201201
len = 0;
202202
iUdp.write(&len, sizeof(len));
203203
// Finally the type and class of question
204-
twoByteBuffer = htons(TYPE_A);
204+
twoByteBuffer = TYPE_A;
205205
iUdp.write((uint8_t*)&twoByteBuffer, sizeof(twoByteBuffer));
206206

207-
twoByteBuffer = htons(CLASS_IN); // Internet class of question
207+
twoByteBuffer = CLASS_IN; // Internet class of question
208208
iUdp.write((uint8_t*)&twoByteBuffer, sizeof(twoByteBuffer));
209209
// Success! Everything buffered okay
210210
return 1;
@@ -243,7 +243,7 @@ uint16_t DNSClient::ProcessResponse(uint16_t aTimeout, IPAddress& aAddress)
243243
}
244244
iUdp.read(header.byte, DNS_HEADER_SIZE);
245245

246-
uint16_t header_flags = htons(header.word[1]);
246+
uint16_t header_flags = header.word[1];
247247
// Check that it's a response to this request
248248
if ((iRequestId != (header.word[0])) ||
249249
((header_flags & QUERY_RESPONSE_MASK) != (uint16_t)RESPONSE_FLAG) ) {
@@ -260,15 +260,15 @@ uint16_t DNSClient::ProcessResponse(uint16_t aTimeout, IPAddress& aAddress)
260260
}
261261

262262
// And make sure we've got (at least) one answer
263-
uint16_t answerCount = htons(header.word[3]);
263+
uint16_t answerCount = header.word[3];
264264
if (answerCount == 0) {
265265
// Mark the entire packet as read
266266
iUdp.flush(); // FIXME
267267
return -6; //INVALID_RESPONSE;
268268
}
269269

270270
// Skip over any questions
271-
for (uint16_t i=0; i < htons(header.word[2]); i++) {
271+
for (uint16_t i=0; i < header.word[2]; i++) {
272272
// Skip over the name
273273
uint8_t len;
274274
do {
@@ -329,8 +329,8 @@ uint16_t DNSClient::ProcessResponse(uint16_t aTimeout, IPAddress& aAddress)
329329
// Don't need header_flags anymore, so we can reuse it here
330330
iUdp.read((uint8_t*)&header_flags, sizeof(header_flags));
331331

332-
if ( (htons(answerType) == TYPE_A) && (htons(answerClass) == CLASS_IN) ) {
333-
if (htons(header_flags) != 4) {
332+
if ( (answerType == TYPE_A) && (answerClass == CLASS_IN) ) {
333+
if (header_flags != 4) {
334334
// It's a weird size
335335
// Mark the entire packet as read
336336
iUdp.flush(); // FIXME
@@ -341,7 +341,7 @@ uint16_t DNSClient::ProcessResponse(uint16_t aTimeout, IPAddress& aAddress)
341341
return SUCCESS;
342342
} else {
343343
// This isn't an answer type we're after, move onto the next one
344-
iUdp.read((uint8_t *)NULL, htons(header_flags));
344+
iUdp.read((uint8_t *)NULL, header_flags);
345345
}
346346
}
347347

src/utility/w5100.h

-20
Original file line numberDiff line numberDiff line change
@@ -447,24 +447,4 @@ class W5100Class {
447447

448448
extern W5100Class W5100;
449449

450-
451-
452-
#endif
453-
454-
#ifndef UTIL_H
455-
#define UTIL_H
456-
457-
#ifndef htons
458-
459-
#define htons(x) ( (((x)<<8)&0xFF00) | (((x)>>8)&0xFF) )
460-
#define ntohs(x) htons(x)
461-
462-
#define htonl(x) ( ((x)<<24 & 0xFF000000UL) | \
463-
((x)<< 8 & 0x00FF0000UL) | \
464-
((x)>> 8 & 0x0000FF00UL) | \
465-
((x)>>24 & 0x000000FFUL) )
466-
#define ntohl(x) htonl(x)
467-
468-
#endif // !defined(htons)
469-
470450
#endif

0 commit comments

Comments
 (0)