summaryrefslogtreecommitdiff
path: root/src/lib/libc/net/getproto.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libc/net/getproto.c')
-rw-r--r--src/lib/libc/net/getproto.c31
1 files changed, 20 insertions, 11 deletions
diff --git a/src/lib/libc/net/getproto.c b/src/lib/libc/net/getproto.c
index dee089d5c2..3f05a93cce 100644
--- a/src/lib/libc/net/getproto.c
+++ b/src/lib/libc/net/getproto.c
@@ -28,24 +28,33 @@
28 */ 28 */
29 29
30#if defined(LIBC_SCCS) && !defined(lint) 30#if defined(LIBC_SCCS) && !defined(lint)
31static char rcsid[] = "$OpenBSD: getproto.c,v 1.4 2003/06/02 20:18:35 millert Exp $"; 31static char rcsid[] = "$OpenBSD: getproto.c,v 1.5 2004/10/17 20:24:23 millert Exp $";
32#endif /* LIBC_SCCS and not lint */ 32#endif /* LIBC_SCCS and not lint */
33 33
34#include <netdb.h> 34#include <netdb.h>
35 35#include <stdio.h>
36extern int _proto_stayopen;
37 36
38struct protoent * 37struct protoent *
39getprotobynumber(proto) 38getprotobynumber_r(int num, struct protoent *pe, struct protoent_data *pd)
40 register int proto;
41{ 39{
42 register struct protoent *p; 40 struct protoent *p;
43 41
44 setprotoent(_proto_stayopen); 42 setprotoent_r(pd->stayopen, pd);
45 while ((p = getprotoent())) 43 while ((p = getprotoent_r(pe, pd)))
46 if (p->p_proto == proto) 44 if (p->p_proto == num)
47 break; 45 break;
48 if (!_proto_stayopen) 46 if (!pd->stayopen && pd->fp != NULL) {
49 endprotoent(); 47 (void)fclose(pd->fp);
48 pd->fp = NULL;
49 }
50 return (p); 50 return (p);
51} 51}
52
53struct protoent *
54getprotobynumber(int num)
55{
56 extern struct protoent_data _protoent_data;
57 static struct protoent proto;
58
59 return getprotobynumber_r(num, &proto, &_protoent_data);
60}