网络API 索引: 1.字节序函数 2.字节操作函数 3.地址转换函数 4.readn、writen和 readline 5.测试描述符类型 6.socket函数 7.connect函数 8.bind函数 9.listen函数 10.accept函数 11.close函数 12.getsockname和 getpeername 13.select函数 14.shutdown函数 15.pselect函数 16.poll函数 17.getsockopt和 setsockopt 18.套接口选项列表 19.处理套接口的 fcntl函数 20.gethostbyname函数 21.gethostbyname2函数 22.ethostbyaddr函数 23.uname函数 24.gethostname函数 25.getservbyname函数 26.getservbyport函数 27.recv和 send 28.readv和 writev 29.readmsg和 writemsg 30.socketpair函数 31.套接口 ioctl函数 1.字节序函数 #include
uint16_t htons(uint16_t host16bitvalue); uint32_t htonl(uint32_t host32bitvalue); 返回:网络字节序值 uint16_t ntohs(uint16_t net16bitvalue); uint32_t ntohl(uint32_t net32bitvalue); 返回:主机字节序值 一个测试本机字节序的程序,可参见见unpv12e:intro/byteorder.c。 2.字节操作函数 #include void bzero(void *dest, size_t nbytes); void bcopy(const void *src, void *dest, size_t nbytes); int bcmp(const void *ptr1, const void *ptr2, size_t nbytes); 返回:0—相等,非 0—不相等 #include void *memset(void *dest, int c, size_t len); void *memcpy(void *dest, void *src, size_t nbytes); int memcmp(const void *ptr1, const void *ptr2, size_t nbytes); 返回:0—相同,>0或<0—不相同;进行比较操作时,假定两个不相等的字节均为无符号字符(unsigned char)。 3.地址转换函数 #include int inet_aton(const char *strptr, struct in_addr *addrptr); 返回:1—串有效,0—串有错。 in_addr_t inet_addr(const char *strptr); 返回:若成功,返回32为二进制的网络字节序地址;若有错,则返回INADDR_NONE。 char *inet_ntoa(struct in_addr inaddr); 返回:指向点分十进制数串的指针。 int inet_pton(int family, const char *strptr, void *addrptr); 返回:1—成功;0—输入不是有效的表达格式,-1—出错。 const char *inet_ntop(int family, const void *addrptr...