getservbyname.c
00001 #include <stdio.h>
00002 #include <netdb.h>
00003
00004 void check_servent(char * service, char * protocol) {
00005 struct servent * sp = getservbyname(service,protocol);
00006 if (sp == NULL) {
00007 fprintf(stderr, "Service %s avec le protocole %s introuvable\n",
00008 service,(protocol == NULL)?"NULL":protocol);
00009 } else {
00010 printf("Service %s \t- protocol %s - Port %d\n",
00011 sp->s_name, sp->s_proto, sp->s_port);
00012 }
00013 }
00014
00015 int main( int argc, char* argv[])
00016 {
00017 check_servent("domain", "udp");
00018 check_servent("ftp", "tcp");
00019 check_servent("ftp", NULL);
00020 check_servent("ftp", "udp");
00021 return 0;
00022 }
00023