summaryrefslogtreecommitdiff
path: root/src/lib/libc/net/getnetent.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libc/net/getnetent.c')
-rw-r--r--src/lib/libc/net/getnetent.c47
1 files changed, 22 insertions, 25 deletions
diff --git a/src/lib/libc/net/getnetent.c b/src/lib/libc/net/getnetent.c
index b4e16b8f5d..3e52c1ff4d 100644
--- a/src/lib/libc/net/getnetent.c
+++ b/src/lib/libc/net/getnetent.c
@@ -1,5 +1,3 @@
1/* $NetBSD: getnetent.c,v 1.4 1995/02/25 06:20:33 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,11 +28,7 @@
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: getnetent.c,v 1.10 2005/03/25 13:24:12 otto Exp $";
38static char sccsid[] = "@(#)getnetent.c 8.1 (Berkeley) 6/4/93";
39#else
40static char rcsid[] = "$NetBSD: getnetent.c,v 1.4 1995/02/25 06:20:33 cgd Exp $";
41#endif
42#endif /* LIBC_SCCS and not lint */ 32#endif /* LIBC_SCCS and not lint */
43 33
44#include <sys/types.h> 34#include <sys/types.h>
@@ -58,8 +48,7 @@ static char *net_aliases[MAXALIASES];
58int _net_stayopen; 48int _net_stayopen;
59 49
60void 50void
61setnetent(f) 51setnetent(int f)
62 int f;
63{ 52{
64 if (netf == NULL) 53 if (netf == NULL)
65 netf = fopen(_PATH_NETWORKS, "r" ); 54 netf = fopen(_PATH_NETWORKS, "r" );
@@ -69,7 +58,7 @@ setnetent(f)
69} 58}
70 59
71void 60void
72endnetent() 61endnetent(void)
73{ 62{
74 if (netf) { 63 if (netf) {
75 fclose(netf); 64 fclose(netf);
@@ -79,24 +68,29 @@ endnetent()
79} 68}
80 69
81struct netent * 70struct netent *
82getnetent() 71getnetent(void)
83{ 72{
84 char *p; 73 char *p, *cp, **q;
85 register char *cp, **q; 74 size_t len;
86 75
87 if (netf == NULL && (netf = fopen(_PATH_NETWORKS, "r" )) == NULL) 76 if (netf == NULL && (netf = fopen(_PATH_NETWORKS, "r" )) == NULL)
88 return (NULL); 77 return (NULL);
89again: 78again:
90 p = fgets(line, BUFSIZ, netf); 79 if ((p = fgetln(netf, &len)) == NULL)
91 if (p == NULL)
92 return (NULL); 80 return (NULL);
93 if (*p == '#') 81 if (p[len-1] == '\n')
82 len--;
83 if (len >= sizeof(line) || len == 0)
94 goto again; 84 goto again;
95 cp = strpbrk(p, "#\n"); 85 p = memcpy(line, p, len);
96 if (cp == NULL) 86 line[len] = '\0';
87 if (*p == '#')
97 goto again; 88 goto again;
98 *cp = '\0'; 89 if ((cp = strchr(p, '#')) != NULL)
90 *cp = '\0';
99 net.n_name = p; 91 net.n_name = p;
92 if (strlen(net.n_name) >= MAXHOSTNAMELEN-1)
93 net.n_name[MAXHOSTNAMELEN-1] = '\0';
100 cp = strpbrk(p, " \t"); 94 cp = strpbrk(p, " \t");
101 if (cp == NULL) 95 if (cp == NULL)
102 goto again; 96 goto again;
@@ -116,8 +110,11 @@ again:
116 cp++; 110 cp++;
117 continue; 111 continue;
118 } 112 }
119 if (q < &net_aliases[MAXALIASES - 1]) 113 if (q < &net_aliases[MAXALIASES - 1]) {
120 *q++ = cp; 114 *q++ = cp;
115 if (strlen(cp) >= MAXHOSTNAMELEN-1)
116 cp[MAXHOSTNAMELEN-1] = '\0';
117 }
121 cp = strpbrk(cp, " \t"); 118 cp = strpbrk(cp, " \t");
122 if (cp != NULL) 119 if (cp != NULL)
123 *cp++ = '\0'; 120 *cp++ = '\0';