Internet Protocols是採用Big-endian,因此有四個函式(定義於"netinet/in.h")可供我們轉換host byte order <--> network byte order:
uint16_t htons(uint16_t host16bitvalue) ; // host to network short
uint32_t htonl(uint32_t host32bitvalue) ; // host to network long
uint16_t ntohs(uint16_t net16bitvalue) ; // network to host short
uint32_t ntohl(uint32_t net32bitvalue) ; // network to host long
當處理port的時候,可以使用hotns()和ntohs()
當處理IPv4位址,可以使用hotnl()和ntohl()
0 意見:
張貼留言