#include <netinet/in.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)
1、主机序转网络序
(1) htonl
uint32_t htonl (uint32_t hostlong)
Description:
This function converts the uint32_t integer hostlong from host byte order to network byte
order.
This is used for IPv4 Internet addresses.
(2) htons
uint16_t htons (uint16_t hostshort)
Description:
This function converts the uint16_t integer hostshort from host byte order to network byte
order.
2、网络序转主机序
(1) ntohl
uint32_t ntohl (uint32_t netlong)
Description:
This function converts the uint32_t integer netlong from network byte order to host byte
order.
This is used for IPv4 Internet addresses.
(2) ntohs
uint16_t ntohs (uint16_t netshort)
Description:
This function converts the uint16_t integer netshort from network byte order to host byte
order.