function::htonll - Linux


Overview

The function::htonll function converts a 64-bit unsigned integer from host byte order to network byte order. This is useful when preparing data for transmission across a network.

Syntax

uint64_t htonll(uint64_t hostlong);

Options/Flags

None.

Examples

uint64_t host_value = 0x123456789abcdef0;
uint64_t network_value = htonll(host_value);
// network_value is now 0xefcdab8967452310

Common Issues

Make sure to use the correct data type for the input value. Passing an incorrect type can lead to unexpected results.

Integration

function::htonll is commonly used in conjunction with other network-related functions, such as function::ntohll. For example, a simple echo server can use the following code to convert received data from network byte order to host byte order:

while (true) {
  uint64_t received_value;
  recv(sockfd, &received_value, sizeof(received_value), 0);
  uint64_t host_value = ntohll(received_value);
  // Process the host_value...
}

Related Commands

  • function::ntohll: Converts a 64-bit unsigned integer from network byte order to host byte order.
  • function::htonl: Converts a 32-bit unsigned integer from host byte order to network byte order.
  • function::ntohl: Converts a 32-bit unsigned integer from network byte order to host byte order.