diff options
Diffstat (limited to 'src/lib/libc/net/getproto.c')
-rw-r--r-- | src/lib/libc/net/getproto.c | 31 |
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) |
31 | static char rcsid[] = "$OpenBSD: getproto.c,v 1.4 2003/06/02 20:18:35 millert Exp $"; | 31 | static 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> | |
36 | extern int _proto_stayopen; | ||
37 | 36 | ||
38 | struct protoent * | 37 | struct protoent * |
39 | getprotobynumber(proto) | 38 | getprotobynumber_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 | |||
53 | struct protoent * | ||
54 | getprotobynumber(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 | } | ||