Linux C++ - IP地址转换函数

1.

函数用途:数字网络序本地序转换

适用类型:IP地址uint32_t类型、端口号uint16_t类型

#include<netinet/in.h>
extern uint32_t ntohl (uint32_t __netlong) __THROW __attribute__ ((__const__));
extern uint16_t ntohs (uint16_t __netshort) __THROW __attribute__ ((__const__));
extern uint32_t htonl (uint32_t __hostlong) __THROW __attribute__ ((__const__));
extern uint16_t htons (uint16_t __hostshort) __THROW __attribute__ ((__const__));

2.

函数用途:点分十进制IP地址的字符串转换为网络序二进制数

适用类型:XXX.XXX.XXX.XXX转uint32_t类型

#include<apra/inet.h>
extern in_addr_t inet_addr (const char *__cp) __THROW;

extern int inet_aton (const char *__cp, struct in_addr *__inp) __THROW;

extern char *inet_nsap_ntoa (int __len, const unsigned char *__cp, char *__buf) __THROW;

 

posted @ 2018-06-13 14:22  liutianchen  阅读(2527)  评论(0编辑  收藏  举报