Chapter 10

Network Order

This module provides functions to convert from the native byte order on the AVR microcontroller to a big-endian network order like the order used by the Internet Protocol.

10.1  Usage

To use the network order module, place the following in your source files:

  #include <network.h>

10.2  Functions

uint16_t htons(uint16_t host)   function

This function takes a 16 bit word in host order, host, and returns it in network order.

uint32_t htonl(uint32_t host)   function

This function takes a 32 bit word in host order, host, and returns it in network order.

uint16_t ntohs(uint16_t network)   function

This function takes a 16 bit word in network order, network, and returns it in host order.

uint32_t ntohl(uint32_t network)   function

This function takes a 32 bit word in network order, network, and returns it in host order.

uint16_t ntohb2(const uint8_t* network2)   function

This function takes a pointer to two bytes in network order, network2, and returns its value in host order.

void htonb2(uint16_t host, uint8_t* network2)   function

This functions takes a 16 bit word in host order, host, and writes its value in network order at the two bytes pointed to by network2.

uint32_t ntohb3(const uint8_t* network3)   function

This function takes a pointer to three bytes in network order, network3, and returns its value in host order.

void htonb3(uint32_t host, uint8_t* network3)   function

This functions takes a 32 bit word in host order, host, and writes its value in network order at the three bytes pointed to by network3. Only the least significant 24 bits of host are used in this conversion.

uint32_t ntohb4(const uint8_t* network4)   function

This function takes a pointer to four bytes in network order, network4, and returns its value in host order.

void htonb4(uint32_t host, uint8_t* network4)   function

This functions takes a 32 bit word in host order, host, and writes its value in network order at the four bytes pointed to by network4.