• UNP Ch 11, Name and Address Conversion


         这一章比较混乱,现在整理一下。

    一、数据结构:

    1、hostent: 这个数据结构用在gethostbyname这个函数中,表示与host 相关的一些 entries.

    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 */
    };

    image

    2、servent: 这个数据结构用在getservbyname这个函数中,表示service 相关的一些 entries.

    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 */
    };


    3、addrinfo: 这个数据结构用在getaddrinfo这个函数中,是它的返回值,表示与 IPv4或者IPv6 地址相关的一些信息.

    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 */
    };

    image

    二、基本函数:

    1、gethostbyname

    image

    2、gethostbyaddr

    image

    3、getservbyname

    image

    4、getservbyport

    image

    5、getaddrinfo

    image

    6、gai_strerror

    image

    7、freeaddrinfo

    image

    8、getnameinfo

    image

         这些函数基本上都是resolver 所提供的函数,可以用来查找DNS,也可以不查找DNS而在本地电脑上查找相应的文件,这就需要设定相应的flags 等参数。

    三、resolver

    image

  • 相关阅读:
    模拟打车
    atm转账
    python字符串,列表,字典,集合的常用方法
    while和for的简单使用
    数据库的基本命令
    jmeter监控linux的性能
    jmeter的错误解决Cannot create PoolableConnectionFactory (Access denied for user 'root'@'localhost' (using password: YES))
    jmeter的正则参数化
    jmeter的参数化关联
    使用Python解析JSON
  • 原文地址:https://www.cnblogs.com/wangshuo/p/2031500.html
Copyright © 2020-2023  润新知