设为首页 加入收藏

TOP

Linux C网络常用结构体及函数汇总
2014-11-24 14:16:50 来源: 作者: 【 】 浏览:1
Tags:Linux 网络 常用 结构 函数 汇总

一。结构体


  共4字节


4.


   struct hostent {
   char *  h_name;   //地址的正式名称
   char **   h_aliases;   // 空字节-地址的预备名称的指针
   int    h_addrtype;   //地址类型; 通常是AF_INET
   int    h_length;    // 地址的比特长度
   char **  h_addr_list;   // 零字节-主机网络地址指针。网络字节顺序
   };


 #define h_addr h_addr_list[0]   //h_addr_list中的第一地址



二.转换函数


1. #include

uint32_t htonl(uint32_t hostlong);
uint16_t htons(uint16_t hostshort);
uint32_t ntohl(uint32_t netlong);
uint16_t ntohs(uint16_t netshort);


2.inet_ntoa


#include


char *inet_ntoa (struct in_addr)


将网络主机地址转为网络标准点分格式的字符串。


3.inet_addr



#include


in_addr_t inet_addr(const char *cp);
将字符串cp(标准的IPV4点分十进制格式地址)转为一个合适的可作为网络地址的整数。


其中


typedef uint32_t in_addr_t;



:typedef unsigned int uint32_t;


所以:in_addr_t ->unsigned int



4.


gethostbyname


gethostbyaddr


#include



struct hostent *   gethostbyaddr(const void *addr, socklen_t len, int type);


struct hostent *   gethostbyname(const char *name);



5.


socket


#Include


int socket(int domain, int type, int protocol);


connect


int connect(int socket, const struct sockaddr *address,
socklen_t address_len);


bind


int bind(int socket, const struct sockaddr *address,
socklen_t address_len);


listen


int listen(int socket, int backlog);


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Linux驱动移植:支持异步IO 下一篇[Android SQLite]数据存储与访问 ..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: