1 /* 2 * Copyright (c) 1983, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 */ 7 8 #if defined(LIBC_SCCS) && !defined(lint) 9 static char sccsid[] = "@(#)getservbyname.c 8.1 (Berkeley) 06/04/93"; 10 #endif /* LIBC_SCCS and not lint */ 11 12 #include <netdb.h> 13 #include <string.h> 14 15 extern int _serv_stayopen; 16 17 struct servent * 18 getservbyname(name, proto) 19 const char *name, *proto; 20 { 21 register struct servent *p; 22 register char **cp; 23 24 setservent(_serv_stayopen); 25 while (p = getservent()) { 26 if (strcmp(name, p->s_name) == 0) 27 goto gotname; 28 for (cp = p->s_aliases; *cp; cp++) 29 if (strcmp(name, *cp) == 0) 30 goto gotname; 31 continue; 32 gotname: 33 if (proto == 0 || strcmp(p->s_proto, proto) == 0) 34 break; 35 } 36 if (!_serv_stayopen) 37 endservent(); 38 return (p); 39 } 40