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);
本文转自cococo点点博客园博客,原文链接:http://www.cnblogs.com/coder2012/archive/2013/06/03/3114744.html,如需转载请自行联系原作者