- 17
- 0
- 约1.75万字
- 约 53页
- 2017-06-18 发布于湖北
- 举报
第06章名字与地址转换编程资料
获取服务名字函数(cont.) #include netdb.h struct servent *getservbyport(int port, const char *protoname); 返回:非空指针-成功;空指针-出错。 该函数根据端口号和可选的协议查找相应的服务; 参数port必须为网络字节序; 如: struct servent *sptr; sptr = getservbyport(htons(53), “UDP); /*DNS using UDP */ sptr = getservbyport(htons(21), “TCP”); /* FTP using TCP */ sptr = getservbyport(htons(21), NULL); /* FTP using TCP */ sptr = getservbyport(htons(21),”UDP”); /* this call will fail */ #include netdb.h #include errno.h #include stdio.h int main() { struct servent *srv; int i; for (i=1;i100;i++) { srv=getservbyport(htons(i),
原创力文档

文档评论(0)