15.8.c
来自「该程序包详细讲述了Linux环境下的Socket编程」· C语言 代码 · 共 44 行
C
44 行
#include <stdio.h>#include <netdb.h> int main(){ struct servent *ser; if( ser=getservbyport(htons(23),"tcp")) { printf("name : %s\n",ser->s_name); printf("port : %d\n",ntohs(ser->s_port)); printf("protocol:%s\n",ser->s_proto); printf("alias: %s\n",ser->s_aliases[0]); } else { printf("there is no such a service.\n"); } if( ser=getservbyport(htons(80),"tcp")) { printf("name : %s\n",ser->s_name); printf("port : %d\n",ntohs(ser->s_port)); printf("protocol:%s\n",ser->s_proto); printf("alias: %s\n",ser->s_aliases[0]); } else { printf("there is no such a service.\n"); } if( ser=getservbyport(htons(61111),"tcp")) { printf("name : %s\n",ser->s_name); printf("port : %d\n",ntohs(ser->s_port)); printf("protocol:%s\n",ser->s_proto); printf("alias: %s\n",ser->s_aliases[0]); } else { printf("there is no such a service.\n"); } }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?