date and time created 91/04/12 13:40:31 by bostic
[unix-history] / usr / src / lib / libc / net / getservbyname.c
CommitLineData
8ea4199d
DF
1/*
2 * Copyright (c) 1983 Regents of the University of California.
6b2f9dd0
KB
3 * All rights reserved.
4 *
269a7923 5 * %sccs.include.redist.c%
8ea4199d
DF
6 */
7
2ce81398 8#if defined(LIBC_SCCS) && !defined(lint)
24fac7d8 9static char sccsid[] = "@(#)getservbyname.c 5.7 (Berkeley) %G%";
6b2f9dd0 10#endif /* LIBC_SCCS and not lint */
e28b94e5
SL
11
12#include <netdb.h>
24fac7d8 13#include <string.h>
e28b94e5 14
5442f2c7
JL
15extern int _serv_stayopen;
16
e28b94e5 17struct servent *
5e649950 18getservbyname(name, proto)
24fac7d8 19 const char *name, *proto;
e28b94e5
SL
20{
21 register struct servent *p;
22 register char **cp;
23
5442f2c7 24 setservent(_serv_stayopen);
e28b94e5
SL
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;
32gotname:
33 if (proto == 0 || strcmp(p->s_proto, proto) == 0)
34 break;
35 }
5442f2c7
JL
36 if (!_serv_stayopen)
37 endservent();
e28b94e5
SL
38 return (p);
39}