侧边栏壁纸
博主头像
noerror

虚灵不寐,众理具而万事出。

  • 累计撰写 239 篇文章
  • 累计创建 9 个标签
  • 累计收到 2 条评论
标签搜索

目 录CONTENT

文章目录

getprotoent函数用法详解

noerror
2022-11-09 / 0 评论 / 0 点赞 / 188 阅读 / 442 字 / 正在检测是否收录...

getprotoent函数用法详解

getprotoent函数简介

  • 头文件包含
#include <netdb.h>
  • 函数定义
struct protoent *getprotoent(void);
struct protoent *getprotobyname(const char * name );
struct protoent *getprotobynumber(int  proto );
void setprotoent(int  stayopen );
void endprotoent(void);

getprotoent函数常见使用错误

  • 编译错误
    warning: implicit declaration of function ‘getprotoent’ [-Wimplicit-function-declaration]
    解决办法:包含头文件
#include <netdb.h>

getprotoent函数详细描述

getprotoent ()函数从协议数据库(参见protocols (5)))中读取下一个条目,并返回一个protoent结构,其中包含该条目中的分段字段。如有必要,将打开到数据库的连接。
getprotobyname ()函数为数据库中与协议名称name 匹配的条目返回protoent结构。如有必要,将打开到数据库的连接。
getprotobynumber ()函数为来自数据库的条目返回一个protoent结构,该结构与协议号number 相匹配。如有必要,将打开到数据库的连接。
setprotoent ()函数打开到数据库的连接,并将下一个条目设置为第一个条目。如果stayopen不为零,那么在调用getproto* ()函数之一之间,到数据库的连接不会关闭。
endprotoent ()函数关闭与数据库的连接。
中的protoent结构定义如下:

struct protoent {
   char  *p_name;       /* official protocol name */
   char **p_aliases;    /* alias list */
   int    p_proto;      /* protocol number */
}

protoent结构的成员包括:

  • p_name协议的正式名称。
  • p_aliases协议的替代名称的空终止列表。
  • p_proto协议号。

getprotoent函数返回值

getprotoent () getprotobyname ()和getprotobynumber ()函数返回一个指向静态分配的protoent结构的指针,或者在发生错误或到达文件末尾时返回一个空指针。

0

评论区