I believe getprotoent()
function gets values from /etc/protocols
.
I made the following sample program: test.c.
It shows
proto.p_name = ip
*proto.p_aliases = IP
proto.p_proto = 0
These values are the same as the first entry in /etc/protocols
.
I want to know how I can get the values of the 2nd entries like looping with evaluate some pointers not using getprotobyname()
or getprotobynumber()
.
Test.c
#include <stdio.h>
#include <string.h>
#include <netdb.h>
int main(int argc,char *argv[])
{
protEnt();
}
int protEnt()
{
setprotoent(2);
struct protoent proto;
proto = *getprotoent();
printf("proto.p_name = %s\n",proto.p_name);
printf("*proto.p_aliases = %s\n",*proto.p_aliases);
printf("proto.p_proto = %d\n",proto.p_proto);
proto = *getprotoent();
endprotoent();
}