diff options
Diffstat (limited to 'src/lib/libc/net/getservbyport.c')
| -rw-r--r-- | src/lib/libc/net/getservbyport.c | 56 |
1 files changed, 27 insertions, 29 deletions
diff --git a/src/lib/libc/net/getservbyport.c b/src/lib/libc/net/getservbyport.c index c34790737b..46679ba366 100644 --- a/src/lib/libc/net/getservbyport.c +++ b/src/lib/libc/net/getservbyport.c | |||
| @@ -1,5 +1,4 @@ | |||
| 1 | /* $NetBSD: getservbyport.c,v 1.4 1995/02/25 06:20:37 cgd Exp $ */ | 1 | /* $OpenBSD: getservbyport.c,v 1.7 2005/08/06 20:30:03 espie Exp $ */ |
| 2 | |||
| 3 | /* | 2 | /* |
| 4 | * Copyright (c) 1983, 1993 | 3 | * Copyright (c) 1983, 1993 |
| 5 | * The Regents of the University of California. All rights reserved. | 4 | * The Regents of the University of California. All rights reserved. |
| @@ -12,11 +11,7 @@ | |||
| 12 | * 2. Redistributions in binary form must reproduce the above copyright | 11 | * 2. Redistributions in binary form must reproduce the above copyright |
| 13 | * notice, this list of conditions and the following disclaimer in the | 12 | * notice, this list of conditions and the following disclaimer in the |
| 14 | * documentation and/or other materials provided with the distribution. | 13 | * documentation and/or other materials provided with the distribution. |
| 15 | * 3. All advertising materials mentioning features or use of this software | 14 | * 3. Neither the name of the University nor the names of its contributors |
| 16 | * must display the following acknowledgement: | ||
| 17 | * This product includes software developed by the University of | ||
| 18 | * California, Berkeley and its contributors. | ||
| 19 | * 4. Neither the name of the University nor the names of its contributors | ||
| 20 | * may be used to endorse or promote products derived from this software | 15 | * may be used to endorse or promote products derived from this software |
| 21 | * without specific prior written permission. | 16 | * without specific prior written permission. |
| 22 | * | 17 | * |
| @@ -33,34 +28,37 @@ | |||
| 33 | * SUCH DAMAGE. | 28 | * SUCH DAMAGE. |
| 34 | */ | 29 | */ |
| 35 | 30 | ||
| 36 | #if defined(LIBC_SCCS) && !defined(lint) | ||
| 37 | #if 0 | ||
| 38 | static char sccsid[] = "@(#)getservbyport.c 8.1 (Berkeley) 6/4/93"; | ||
| 39 | #else | ||
| 40 | static char rcsid[] = "$NetBSD: getservbyport.c,v 1.4 1995/02/25 06:20:37 cgd Exp $"; | ||
| 41 | #endif | ||
| 42 | #endif /* LIBC_SCCS and not lint */ | ||
| 43 | |||
| 44 | #include <netdb.h> | 31 | #include <netdb.h> |
| 32 | #include <stdio.h> | ||
| 45 | #include <string.h> | 33 | #include <string.h> |
| 46 | 34 | ||
| 47 | extern int _serv_stayopen; | 35 | int |
| 48 | 36 | getservbyport_r(int port, const char *proto, struct servent *se, | |
| 49 | struct servent * | 37 | struct servent_data *sd) |
| 50 | getservbyport(port, proto) | ||
| 51 | int port; | ||
| 52 | const char *proto; | ||
| 53 | { | 38 | { |
| 54 | register struct servent *p; | 39 | int error; |
| 55 | 40 | ||
| 56 | setservent(_serv_stayopen); | 41 | setservent_r(sd->stayopen, sd); |
| 57 | while (p = getservent()) { | 42 | while ((error = getservent_r(se, sd)) == 0) { |
| 58 | if (p->s_port != port) | 43 | if (se->s_port != port) |
| 59 | continue; | 44 | continue; |
| 60 | if (proto == 0 || strcmp(p->s_proto, proto) == 0) | 45 | if (proto == 0 || strcmp(se->s_proto, proto) == 0) |
| 61 | break; | 46 | break; |
| 62 | } | 47 | } |
| 63 | if (!_serv_stayopen) | 48 | if (!sd->stayopen && sd->fp != NULL) { |
| 64 | endservent(); | 49 | fclose(sd->fp); |
| 65 | return (p); | 50 | sd->fp = NULL; |
| 51 | } | ||
| 52 | return (error); | ||
| 53 | } | ||
| 54 | |||
| 55 | struct servent * | ||
| 56 | getservbyport(int port, const char *proto) | ||
| 57 | { | ||
| 58 | extern struct servent_data _servent_data; | ||
| 59 | static struct servent serv; | ||
| 60 | |||
| 61 | if (getservbyport_r(port, proto, &serv, &_servent_data) != 0) | ||
| 62 | return (NULL); | ||
| 63 | return (&serv); | ||
| 66 | } | 64 | } |
