linux网络编程中常用的辅助函数
来源:互联网 发布:靠谱淘宝 外贸 知乎 编辑:程序博客网 时间:2024/05/19 03:18
一、字节序转换:
unsigned long int htonl(unsigned long int hostlong)
unsigned short int htons(unisgned short int hostshort)
unsigned long int ntohl(unsigned long int netlong)
unsigned short int ntohs(unsigned short int netshort)
其中:h->host,n->network,s->short,l->long
二、字符串格式和整数地址转换:
int inet_aton(const char *cp, struct in_addr *inp); //转换成网络序的整数,地址可用返回非0,不可用返回0
in_addr_t inet_addr(const char *cp); //转换成网络序的整数,由于返回值-1和地址255.255.255.255意思相同,所以不推荐使用
in_addr_t inet_network(const char *cp); //转换成主机序的整数,地址无效返回-1
char *inet_ntoa(struct in_addr in); //转换成点分十进制的串,该buff为静态分配
struct in_addr inet_makeaddr(int net, int host); //遗留接口,既然是遗留不推荐使用。
in_addr_t inet_lnaof(struct in_addr in); //遗留接口,既然是遗留不推荐使用。
in_addr_t inet_netof(struct in_addr in); //遗留接口,既然是遗留不推荐使用。
--------------
int inet_pton(int af, const char *src, void *dst);//转换成网络序的整数,多了个参数可以支持IPv4和IPv6,成功返回1,地址串有问题返回0,地址域有问题返回-1
inet_aton系列 VS inet_pton:
inet_pton支持IPv6和IPv4,但是对于IPv4来说,只支持点分十进制表示的串;然而inet_aton系列支持更一般的点分八进制和点分十六进制(然并卵)
三、关于DNS解析相关的内容后面补
struct hostent *gethostbyname(const char *name);
unsigned long int htonl(unsigned long int hostlong)
unsigned short int htons(unisgned short int hostshort)
unsigned long int ntohl(unsigned long int netlong)
unsigned short int ntohs(unsigned short int netshort)
其中:h->host,n->network,s->short,l->long
二、字符串格式和整数地址转换:
int inet_aton(const char *cp, struct in_addr *inp); //转换成网络序的整数,地址可用返回非0,不可用返回0
in_addr_t inet_addr(const char *cp); //转换成网络序的整数,由于返回值-1和地址255.255.255.255意思相同,所以不推荐使用
in_addr_t inet_network(const char *cp); //转换成主机序的整数,地址无效返回-1
char *inet_ntoa(struct in_addr in); //转换成点分十进制的串,该buff为静态分配
struct in_addr inet_makeaddr(int net, int host); //遗留接口,既然是遗留不推荐使用。
in_addr_t inet_lnaof(struct in_addr in); //遗留接口,既然是遗留不推荐使用。
in_addr_t inet_netof(struct in_addr in); //遗留接口,既然是遗留不推荐使用。
--------------
int inet_pton(int af, const char *src, void *dst);//转换成网络序的整数,多了个参数可以支持IPv4和IPv6,成功返回1,地址串有问题返回0,地址域有问题返回-1
inet_aton系列 VS inet_pton:
inet_pton支持IPv6和IPv4,但是对于IPv4来说,只支持点分十进制表示的串;然而inet_aton系列支持更一般的点分八进制和点分十六进制(然并卵)
三、关于DNS解析相关的内容后面补
struct hostent *gethostbyname(const char *name);
0 0
- linux网络编程中常用的辅助函数
- Linux中网络编程常用函数
- 网络编程中常用的一些函数
- Linux网络编程常用函数
- Linux网络编程常用函数
- Linux网络编程常用函数
- Linux网络编程常用函数
- Linux网络编程常用函数
- Linux编程常用的函数(八) 网络编程
- Linux网络编程之[Socket通信的常用函数简介]
- 网络编程学习_socket辅助函数(一)
- 关于网络编程中一些常用函数的理解
- 网络编程中常用的函数及结构体总结
- Linux socket 网络编程常用函数总结
- Linux 网络编程常用函数详解
- 网络编程中常用函数实现
- 一些常用的辅助代码 (网络收藏)
- 一些常用的辅助代码 (网络收藏)
- 前端注意事项总结
- iOS 蓝牙4.0(BLE)后台或者锁屏也可以接收数据的方法
- TCL第三代黑水晶超薄电视C1上市 缔造业界新高度
- CABasicAnimation, CAKeyframeAnimation,CAAnimationGroup动画的用法
- j-s 获-取-终-端的相关信息(根据访-问类-型跳-转)
- linux网络编程中常用的辅助函数
- ubuntu14.04 安装google chrome
- 每个人都会记得一些事,那些让自己成熟的过程。
- Data Structure for HTML DOM with compare text inside
- Parcelable和Serializable的区别:
- P3-weixin 微信插件式开发规范
- Fastest Gaussian Blur in CPU
- LINUX卸载mysql
- 使用Nginx+uWSGI+Django方法部署Django程序