/* protoent.c:
*
* Example getprotoent(3) program:
*/
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
#include <netdb.h>
int main(int argc, char **argv) {
int x;
struct protoent *pp;
for (;;) {
errno = 0;
if ( !(pp = getprotoent()) ) {
break;
}
printf("%s:\n"
"\tProtocol: %d\n"
"\tAliases: ",
pp->p_name,
pp->p_proto);
for ( x=0; pp->p_aliases[x] != NULL; ++x ) {
printf("%s ",pp->p_aliases[x]);
}
putchar('\n');
}
if ( errno != 0 && errno != ENOENT ) { /* For RH-6.0 */
fprintf(stderr,
"%s: getprotoent(3) %d\n",
strerror(errno),errno);
}
return 0;
}
/*
[sgupta@rhel55x86 chap6]$ gcc protoent.c -o protoent
[sgupta@rhel55x86 chap6]$ ./protoent
ip:
Protocol: 0
Aliases: IP
hopopt:
Protocol: 0
Aliases: HOPOPT
icmp:
Protocol: 1
Aliases: ICMP
igmp:
Protocol: 2
Aliases: IGMP
ggp:
Protocol: 3
Aliases: GGP
ipencap:
Protocol: 4
Aliases: IP-ENCAP
rsvp-e2e-ignore:
Protocol: 134
Aliases: RSVP-E2E-IGNORE
udplite:
Protocol: 136
Aliases: UDPLite
mpls-in-ip:
Protocol: 137
Aliases: MPLS-in-IP
[sgupta@rhel55x86 chap6]$
*/
No comments:
Post a Comment