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.