Network byte sequence he host byte sequence

Source: Internet
Author: User
Tags htons

Nbo and HBONetwork byte sequenceNbo (Network byte order): stores data in a sequence from high to low and uses a unifiedNetwork byte sequenceTo avoid compatibility issues. Host byte order (HBO, host byte order): different machines HBO are different. There are two types of computer data storage priorities related to CPU design: high byte priority and low byte priority. Data on the internet is transmitted over the network in high byte precedence. Therefore, for machines that store data in low byte precedence mode, data transmission over the Internet requires conversion.

Htonl()
Brief description:
Converts the unsigned Length Integer of the host to the network byte sequence. # Include <Winsock. h> u_long Pascal far Htonl(U_long hostlong); hostlong: 32-digit host bytes in sequence. Note:
This function converts a 32-bit string from the host byte sequence to the network byte sequence. Return Value:
Htonl() Returns the value of a network byte sequence.
 
Inet_ntoa () Brief description:
Converts a network address to a string format separated. # Include <Winsock. h> char far * Pascal far inet_ntoa (struct in_addr in); In: a structure that represents the Internet host address. Note:
This function converts an Internet address structure represented by the In parameter to a string separated by A. B. C. D. Note that the strings returned by inet_ntoa () are stored in the memory allocated by the Windows interface. The application should not assume how the memory is allocated. Before calling the next Windows interface of the same thread, the data will be valid. Return Value:
If no error occurs, inet_ntoa () returns a character pointer. Otherwise, nvll is returned. The data should be copied before the next Windows interface call. Some of the data transmitted over the network is in the same order as the local bytes, while others are completely different. To ensure data consistency, you must convert the local data to the format used on the network, then, the data is sent and received in the same way. After conversion, the data is used. The basic library function provides such a function for byte conversion, for example, with htons () htonl () ntohs () ntohl (), here n represents network, H represents host, htons () htonl () is used to convert local bytes to network bytes, s indicates short, that is, 2-byte operation, and l indicates long, that is, 4-byte operation. Similarly, ntohs () ntohl () is used to convert network bytes to the local format.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.