查找域名、由名字查找某个熟知的端口、由名字查找协议

1.由名字查找某个熟知的端口

struct servent{
    char   *s_name;     /* official service name */
    char **s_aliases;   /* other aliases */
    char     s_port;       /* prot ofr this service */
    char   *s_proto;     /* protocol to use */
};

struct servent *sptr;
sptr = getservbyname("smtp","tcp"));

 

2.由名字查找协议

struct protoent{
    char    *pname;
    char  **p_aliases;
    char      p_proto;
};

struct protoent *pptr;
pptr=getprotobyname("udp");

 

3.查找域名

struct hostent{
    char     *h_name;
    char   **h_aliases;
    char       h_addrtype;
    char       h_length;                   /* address length */
    char   **h_addr_list;               /* list of addresses */
};

struct hostent *htpr;
char *str="dlut.edu.cn";
htpr = gethostbyname(str);

 

 

 

 

 

 

 

 

posted @ 2013-06-03 10:38  cococo点点  阅读(393)  评论(0编辑  收藏  举报