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

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);

 

 

 

 

 

 

 

 

你可能感兴趣的:(端口)