网络编程基础6-获得协议信息getprotoent

/* 
1. 获得协议信息,存储与结构体 struct protoent,3个成员
2. 读取静态文件/etc/protocols获得协议信息
*/
#include <stdio.h>  
#include <stdlib.h>  
#include <netdb.h>  

int main()  
{  
    char **p = NULL;  
    struct protoent *proto = NULL;  
   // setprotoent(1);  
    while( (proto = getprotoent()) != NULL )  
    {  
        printf("protocol name: %s\n", proto->p_name);  
        for(p = proto->p_aliases; *p; p++)  
        {  
            printf("alternate proto name: %s\n", *p);  
        }  
        printf("protocol number: %d\n", proto->p_proto);  
        printf("\n");  
    }  
    endprotoent();  
    return 0;  
}

这里写图片描述

#if 0
/* Description of data base entry for a single service.  */
struct protoent
{
  char *p_name;         /* Official protocol name.  */
  char **p_aliases;     /* Alias list.  */
  int p_proto;          /* Protocol number.  */
};
/* Open protocol data base files and mark them as staying open even
   after a later search if STAY_OPEN is non-zero.

   This function is a possible cancellation point and therefore not
   marked with __THROW.  */
extern void setprotoent (int __stay_open);

/* Close protocol data base files and clear `stay open' flag.

   This function is a possible cancellation point and therefore not
   marked with __THROW.  */
extern void endprotoent (void);

/* Get next entry from protocol data base file.  Open data base if
   necessary.

   This function is a possible cancellation point and therefore not
   marked with __THROW.  */
extern struct protoent *getprotoent (void);

/* Return entry from protocol data base for network with NAME.

   This function is a possible cancellation point and therefore not
   marked with __THROW.  */
extern struct protoent *getprotobyname (__const char *__name);

/* Return entry from protocol data base which number is PROTO.

   This function is a possible cancellation point and therefore not
   marked with __THROW.  */
extern struct protoent *getprotobynumber (int __proto);
#endif
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值