Host and network byte order conversion

Source: Internet
Author: User
Tags htons
There are four functions for byte sequence conversion. For 2 bytes and 4 bytes respectively. A single byte naturally has no issue with the byte sequence.
Htonl (3)-Linux man pagename

Htonl, htons, ntohl, ntohs-convert values between host and network byte order

Synopsis
#include <arpa/inet.h>uint32_t htonl(uint32_t hostlong);uint16_t htons(uint16_t hostshort);uint32_t ntohl(uint32_t netlong);uint16_t ntohs(uint16_t netshort);
Description

TheHtonl() Function converts the unsigned integerHostlongFrom host byte order to network byte order.

TheHtons() Function converts the unsigned short integerHostshortFrom host byte order to network byte order.

TheNtohl() Function converts the unsigned integerNetlongFrom Network byte order to host byte order.

TheNtohs() Function converts the unsigned short integerNetshortFrom Network byte order to host byte order.

On the i80x86 the host byte order is least significant byte first, whereas the network byte order, as used on the Internet, is most significant byte first.

Conforming

POSIX.1-2001.

Some systems require the regression sion<Netinet/in. h>Instead<ARPA/inet. h>.

See also

Gethostbyname(3),Getservent(3)

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.