summaryrefslogtreecommitdiff
path: root/src/lib/libc/net/getprotoname.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libc/net/getprotoname.c')
-rw-r--r--src/lib/libc/net/getprotoname.c54
1 files changed, 28 insertions, 26 deletions
diff --git a/src/lib/libc/net/getprotoname.c b/src/lib/libc/net/getprotoname.c
index 4f8cf21c3f..f257bf4a71 100644
--- a/src/lib/libc/net/getprotoname.c
+++ b/src/lib/libc/net/getprotoname.c
@@ -1,5 +1,3 @@
1/* $NetBSD: getprotoname.c,v 1.4 1995/02/25 06:20:36 cgd Exp $ */
2
3/* 1/*
4 * Copyright (c) 1983, 1993 2 * Copyright (c) 1983, 1993
5 * The Regents of the University of California. All rights reserved. 3 * The Regents of the University of California. All rights reserved.
@@ -12,11 +10,7 @@
12 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 11 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 12 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software 13 * 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 14 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission. 15 * without specific prior written permission.
22 * 16 *
@@ -34,35 +28,43 @@
34 */ 28 */
35 29
36#if defined(LIBC_SCCS) && !defined(lint) 30#if defined(LIBC_SCCS) && !defined(lint)
37#if 0 31static char rcsid[] = "$OpenBSD: getprotoname.c,v 1.6 2004/10/25 03:09:01 millert Exp $";
38static char sccsid[] = "@(#)getprotoname.c 8.1 (Berkeley) 6/4/93";
39#else
40static char rcsid[] = "$NetBSD: getprotoname.c,v 1.4 1995/02/25 06:20:36 cgd Exp $";
41#endif
42#endif /* LIBC_SCCS and not lint */ 32#endif /* LIBC_SCCS and not lint */
43 33
44#include <netdb.h> 34#include <netdb.h>
35#include <stdio.h>
45#include <string.h> 36#include <string.h>
46 37
47extern int _proto_stayopen; 38int
48 39getprotobyname_r(const char *name, struct protoent *pe,
49struct protoent * 40 struct protoent_data *pd)
50getprotobyname(name)
51 register const char *name;
52{ 41{
53 register struct protoent *p; 42 char **cp;
54 register char **cp; 43 int error;
55 44
56 setprotoent(_proto_stayopen); 45 setprotoent_r(pd->stayopen, pd);
57 while (p = getprotoent()) { 46 while ((error = getprotoent_r(pe, pd)) == 0) {
58 if (strcmp(p->p_name, name) == 0) 47 if (strcmp(pe->p_name, name) == 0)
59 break; 48 break;
60 for (cp = p->p_aliases; *cp != 0; cp++) 49 for (cp = pe->p_aliases; *cp != 0; cp++)
61 if (strcmp(*cp, name) == 0) 50 if (strcmp(*cp, name) == 0)
62 goto found; 51 goto found;
63 } 52 }
64found: 53found:
65 if (!_proto_stayopen) 54 if (!pd->stayopen && pd->fp != NULL) {
66 endprotoent(); 55 fclose(pd->fp);
67 return (p); 56 pd->fp = NULL;
57 }
58 return (error);
59}
60
61struct protoent *
62getprotobyname(const char *name)
63{
64 extern struct protoent_data _protoent_data;
65 static struct protoent proto;
66
67 if (getprotobyname_r(name, &proto, &_protoent_data) != 0)
68 return (NULL);
69 return (&proto);
68} 70}