[ ]
 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Homepage FreeRTOS Labs FreeRTOS+TCP FreeRTOS+FAT Contact / Enquiries

FreeRTOS+TCP is still in the lab
FreeRTOS+TCP is already used in commercial products and we encourage you to try it yourself. Be aware however that we are still refining its design, and the source code and documentation do not yet meet Real Time Engineers Ltd's strict quality standards.
Please use the forum for support, feedback and ideas, or contact us directly if you have a specific business interest.

FreeRTOS_htons(), FreeRTOS_ntohs(), FreeRTOS_htonl() & FreeRTOS_ntohl()

[FreeRTOS+TCP API Reference]

uint16_t FreeRTOS_htons( uint16_t usValueToSwap );
uint16_t FreeRTOS_ntohs( uint16_t usValueToSwap );

uint32_t FreeRTOS_htonl( uint32_t ulValueToSwap );
uint32_t FreeRTOS_ntohl( uint32_t ulValueToSwap );

The Byte Order and Endian section of the Embedded Networking Basics and Glossary page provides an explanation of byte order considerations in IP networks.

The definition of ipconfigBYTE_ORDER in FreeRTOSIPConfig.h must be correct for the microcontroller on which FreeRTOS+TCP will run. If the microcontroller is big endian then ipconfigBYTE_ORDER must be set to pdFREERTOS_BIG_ENDIAN. If the microcontroller is little endian then ipconfigBYTE_ORDER must be set to pdFREERTOS_LITTLE_ENDIAN.


  • FreeRTOS_htons and FreeRTOS_ntohs() return the value of their 16-bit parameter with the high and low bytes swapped. For example, if the usValueToSwap parameter is 0x1122, then both macros return 0x2211.

  • FreeRTOS_htonl and FreeRTOS_ntohl() return the value of their 32-bit parameter with the byte order reversed. For example, if the ulValueToSwap parameter is 0x11223344, then both macros return 0x44332211.

If the microcontroller is big endian (and therefore ipconfigBYTE_ORDER set to pdFREERTOS_BIG_ENDIAN) then the byte order of the microcontroller and the byte order of the network already match, and all four byte swapping macros are defined to have no effect.

Byte swapping macros are primarily used when specifying the IP address and port number that make up a socket address.

Example usage:

The examples on the FreeRTOS_socket(), FreeRTOS_inet_addr() FreeRTOS_sendto() documentation pages demonstrate the use of FreeRTOS_htons().

The example on the FreeRTOS_recvfrom() documentation page demonstrates the use of FreeRTOS_ntohs().

[ Back to the top ]    [ About FreeRTOS ]    [ FreeRTOS Labs Sitemap ]    [ Main FreeRTOS Sitemap ]    [ ]

Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.