名字与地址转换

DNS(Domain Name System)


gethostname函数

#include <netdb.h>

struct  hostent  *gethostname(const  char  *hostname);

struct  hostent{

char   *h_name; /* official (canonical) name of host */

char   **h_aliases; /* pointer to array of pointers to alias names */

int h_addrtype;  /* host address type: AF_INET */

int h_length; /* length of address: 4 */

char **h_addr_list; /* ptr to array of ptrs with IPv4 addrs */

};


gethostbyaddr函数

struct  hostent  *gethostbyaddr(const  char  *addr,  socklen_t  len,  int  family);


getservbyname和getservbyport函数

struct  servent  *getservbyname(const  char  *servname,  const  char  *protoname);

struct  servent{

char   *s_name; /* official service name */

char   **s_aliases; /* alias list */

int   s_port; /* port number, network byte order */

char   *s_proto; /* protocol to use */

};

struct  servent  *getservbyport(int  port,  const  char  *protoname);


getaddrinfo函数

int  getaddrinfo(const  char  *hostname,  const  char  *service,  const  struct  addrinfo  *hints,  struct  addrinfo  **result);

struct  addrinfo{

int ai_flags; /* AI_PASSIVE, AI_CANONNAME */

int ai_family; /* AF_xxx */

int ai_socktype; /* SOCK_xxx */

int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */

socklen_t ai_addrlen; /* length of ai_addr */

char *ai_canonname; /* ptr to canonical name for host */

struct  sockaddr*ai_addr;/* ptr to socket address structure */

struct  addrinfo*ai_next;/* ptr to next structure in linked list */

};

//返回错误描述消息字符串的指针

const char  *gai_strerror(int  error);

//释放掉addrinfo结构及由它们指向的任何动态存储空间

void  freeaddrinfo(struct  addrinfo  *ai);


getnameinfo函数

//它以一个套接字地址为参数,返回描述其中的主机的一个字符串和描述其中的服务的另一个字符串

int  getnameinfo(const  struct  sockaddr  *sockaddr,  socklen_t  addrlen, 

       char  *host,  socklen_t  hostlen,

       char  *serv,  socklen_t  servlen,  int  flags);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值