![getservbyname和getservbyport getservbyname和getservbyport](https://image.shishitao.com:8440/aHR0cHM6Ly9ia3FzaW1nLmlrYWZhbi5jb20vdXBsb2FkL2NoYXRncHQtcy5wbmc%2FIQ%3D%3D.png?!?w=700&webp=1)
一、getservbyname函数原型
#include <netdb.h> struct servent *getservbyname(const char *servname, const char *protoname); 返回:成功为非空指针,否则为NULL且设置h_errno
二、servent结构
struct servent {
char *s_name;
char **s_aliases;
int s_port;
char *s_proto;
};
三、getservbyport函数原型
#include <netdb.h> struct servent *getservbyport(int port, const char *protoname); 返回:成功为非空指针,否则为NULL且设置h_errno
注意:port参数的值必须为网络字节序