date and time created 87/11/17 19:18:49 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.
3 * All rights reserved. The Berkeley software License Agreement
4 * specifies the terms and conditions for redistribution.
5 */
6
2ce81398 7#if defined(LIBC_SCCS) && !defined(lint)
5442f2c7 8static char sccsid[] = "@(#)getservbyname.c 5.3 (Berkeley) %G%";
2ce81398 9#endif LIBC_SCCS and not lint
e28b94e5
SL
10
11#include <netdb.h>
12
5442f2c7
JL
13extern int _serv_stayopen;
14
e28b94e5 15struct servent *
5e649950 16getservbyname(name, proto)
e28b94e5
SL
17 char *name, *proto;
18{
19 register struct servent *p;
20 register char **cp;
21
5442f2c7 22 setservent(_serv_stayopen);
e28b94e5
SL
23 while (p = getservent()) {
24 if (strcmp(name, p->s_name) == 0)
25 goto gotname;
26 for (cp = p->s_aliases; *cp; cp++)
27 if (strcmp(name, *cp) == 0)
28 goto gotname;
29 continue;
30gotname:
31 if (proto == 0 || strcmp(p->s_proto, proto) == 0)
32 break;
33 }
5442f2c7
JL
34 if (!_serv_stayopen)
35 endservent();
e28b94e5
SL
36 return (p);
37}