121381Sdist /* 2*61150Sbostic * Copyright (c) 1983, 1993 3*61150Sbostic * The Regents of the University of California. All rights reserved. 433679Sbostic * 542626Sbostic * %sccs.include.redist.c% 621381Sdist */ 77902Ssam 826622Sdonn #if defined(LIBC_SCCS) && !defined(lint) 9*61150Sbostic static char sccsid[] = "@(#)getservbyname.c 8.1 (Berkeley) 06/04/93"; 1033679Sbostic #endif /* LIBC_SCCS and not lint */ 1121381Sdist 127902Ssam #include <netdb.h> 1346604Sbostic #include <string.h> 147902Ssam 1528280Slepreau extern int _serv_stayopen; 1628280Slepreau 177902Ssam struct servent * getservbyname(name,proto)188324Ssamgetservbyname(name, proto) 1946604Sbostic const char *name, *proto; 207902Ssam { 217902Ssam register struct servent *p; 227902Ssam register char **cp; 237902Ssam 2428280Slepreau setservent(_serv_stayopen); 257902Ssam while (p = getservent()) { 267902Ssam if (strcmp(name, p->s_name) == 0) 277902Ssam goto gotname; 287902Ssam for (cp = p->s_aliases; *cp; cp++) 297902Ssam if (strcmp(name, *cp) == 0) 307902Ssam goto gotname; 317902Ssam continue; 327902Ssam gotname: 337902Ssam if (proto == 0 || strcmp(p->s_proto, proto) == 0) 347902Ssam break; 357902Ssam } 3628280Slepreau if (!_serv_stayopen) 3728280Slepreau endservent(); 387902Ssam return (p); 397902Ssam } 40