xref: /original-bsd/lib/libc/net/getservbyport.c (revision cf2124ff)
1 /*
2  * Copyright (c) 1983 Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  */
7 
8 #if defined(LIBC_SCCS) && !defined(lint)
9 static char sccsid[] = "@(#)getservbyport.c	5.7 (Berkeley) 02/24/91";
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 getservbyport(port, proto)
19 	int port;
20 	const char *proto;
21 {
22 	register struct servent *p;
23 
24 	setservent(_serv_stayopen);
25 	while (p = getservent()) {
26 		if (p->s_port != port)
27 			continue;
28 		if (proto == 0 || strcmp(p->s_proto, proto) == 0)
29 			break;
30 	}
31 	if (!_serv_stayopen)
32 		endservent();
33 	return (p);
34 }
35