Skip to content

Commit 7c32bbe

Browse files
authored
Merge pull request #161 from gudnimg/master
Fix compiler warning in `htons()`
2 parents 481f960 + 5509403 commit 7c32bbe

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/utility/w5100.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,14 +455,23 @@ extern W5100Class W5100;
455455
#define UTIL_H
456456

457457
#ifndef htons
458+
// The host order of the Arduino platform is little endian.
459+
// Sometimes it is desired to convert to big endian (or
460+
// network order)
458461

459-
#define htons(x) ( (((x)<<8)&0xFF00) | (((x)>>8)&0xFF) )
462+
// Host to Network short
463+
#define htons(x) ( (((x)&0xFF)<<8) | (((x)>>8)&0xFF) )
464+
465+
// Network to Host short
460466
#define ntohs(x) htons(x)
461467

468+
// Host to Network long
462469
#define htonl(x) ( ((x)<<24 & 0xFF000000UL) | \
463470
((x)<< 8 & 0x00FF0000UL) | \
464471
((x)>> 8 & 0x0000FF00UL) | \
465472
((x)>>24 & 0x000000FFUL) )
473+
474+
// Network to Host long
466475
#define ntohl(x) htonl(x)
467476

468477
#endif // !defined(htons)

0 commit comments

Comments
 (0)