diff options
Diffstat (limited to 'src/lib/libc/net/getservbyport.c')
-rw-r--r-- | src/lib/libc/net/getservbyport.c | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/src/lib/libc/net/getservbyport.c b/src/lib/libc/net/getservbyport.c index 992a77d638..e8b8efc504 100644 --- a/src/lib/libc/net/getservbyport.c +++ b/src/lib/libc/net/getservbyport.c | |||
@@ -28,29 +28,38 @@ | |||
28 | */ | 28 | */ |
29 | 29 | ||
30 | #if defined(LIBC_SCCS) && !defined(lint) | 30 | #if defined(LIBC_SCCS) && !defined(lint) |
31 | static char rcsid[] = "$OpenBSD: getservbyport.c,v 1.4 2003/06/02 20:18:35 millert Exp $"; | 31 | static char rcsid[] = "$OpenBSD: getservbyport.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 | #include <stdio.h> | ||
35 | #include <string.h> | 36 | #include <string.h> |
36 | 37 | ||
37 | extern int _serv_stayopen; | ||
38 | |||
39 | struct servent * | 38 | struct servent * |
40 | getservbyport(port, proto) | 39 | getservbyport_r(int port, const char *proto, struct servent *se, |
41 | int port; | 40 | struct servent_data *sd) |
42 | const char *proto; | ||
43 | { | 41 | { |
44 | register struct servent *p; | 42 | struct servent *p; |
45 | 43 | ||
46 | setservent(_serv_stayopen); | 44 | setservent_r(sd->stayopen, sd); |
47 | while ((p = getservent())) { | 45 | while ((p = getservent_r(se, sd))) { |
48 | if (p->s_port != port) | 46 | if (p->s_port != port) |
49 | continue; | 47 | continue; |
50 | if (proto == 0 || strcmp(p->s_proto, proto) == 0) | 48 | if (proto == 0 || strcmp(p->s_proto, proto) == 0) |
51 | break; | 49 | break; |
52 | } | 50 | } |
53 | if (!_serv_stayopen) | 51 | if (!sd->stayopen && sd->fp != NULL) { |
54 | endservent(); | 52 | fclose(sd->fp); |
53 | sd->fp = NULL; | ||
54 | } | ||
55 | return (p); | 55 | return (p); |
56 | } | 56 | } |
57 | |||
58 | struct servent * | ||
59 | getservbyport(int port, const char *proto) | ||
60 | { | ||
61 | extern struct servent_data _servent_data; | ||
62 | static struct servent serv; | ||
63 | |||
64 | return (getservbyport_r(port, proto, &serv, &_servent_data)); | ||
65 | } | ||