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.c52
1 files changed, 23 insertions, 29 deletions
diff --git a/src/lib/libc/net/getnetent.c b/src/lib/libc/net/getnetent.c
index b4e16b8f5d..1bec6fb98c 100644
--- a/src/lib/libc/net/getnetent.c
+++ b/src/lib/libc/net/getnetent.c
@@ -1,5 +1,4 @@
1/* $NetBSD: getnetent.c,v 1.4 1995/02/25 06:20:33 cgd Exp $ */ 1/* $OpenBSD: getnetent.c,v 1.12 2006/01/17 15:37:58 millert 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,15 +28,7 @@
33 * SUCH DAMAGE. 28 * SUCH DAMAGE.
34 */ 29 */
35 30
36#if defined(LIBC_SCCS) && !defined(lint) 31#include <sys/param.h>
37#if 0
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 */
43
44#include <sys/types.h>
45#include <sys/socket.h> 32#include <sys/socket.h>
46#include <netinet/in.h> 33#include <netinet/in.h>
47#include <arpa/inet.h> 34#include <arpa/inet.h>
@@ -58,8 +45,7 @@ static char *net_aliases[MAXALIASES];
58int _net_stayopen; 45int _net_stayopen;
59 46
60void 47void
61setnetent(f) 48setnetent(int f)
62 int f;
63{ 49{
64 if (netf == NULL) 50 if (netf == NULL)
65 netf = fopen(_PATH_NETWORKS, "r" ); 51 netf = fopen(_PATH_NETWORKS, "r" );
@@ -69,7 +55,7 @@ setnetent(f)
69} 55}
70 56
71void 57void
72endnetent() 58endnetent(void)
73{ 59{
74 if (netf) { 60 if (netf) {
75 fclose(netf); 61 fclose(netf);
@@ -79,24 +65,29 @@ endnetent()
79} 65}
80 66
81struct netent * 67struct netent *
82getnetent() 68getnetent(void)
83{ 69{
84 char *p; 70 char *p, *cp, **q;
85 register char *cp, **q; 71 size_t len;
86 72
87 if (netf == NULL && (netf = fopen(_PATH_NETWORKS, "r" )) == NULL) 73 if (netf == NULL && (netf = fopen(_PATH_NETWORKS, "r" )) == NULL)
88 return (NULL); 74 return (NULL);
89again: 75again:
90 p = fgets(line, BUFSIZ, netf); 76 if ((p = fgetln(netf, &len)) == NULL)
91 if (p == NULL)
92 return (NULL); 77 return (NULL);
93 if (*p == '#') 78 if (p[len-1] == '\n')
79 len--;
80 if (len >= sizeof(line) || len == 0)
94 goto again; 81 goto again;
95 cp = strpbrk(p, "#\n"); 82 p = memcpy(line, p, len);
96 if (cp == NULL) 83 line[len] = '\0';
84 if (*p == '#')
97 goto again; 85 goto again;
98 *cp = '\0'; 86 if ((cp = strchr(p, '#')) != NULL)
87 *cp = '\0';
99 net.n_name = p; 88 net.n_name = p;
89 if (strlen(net.n_name) >= MAXHOSTNAMELEN-1)
90 net.n_name[MAXHOSTNAMELEN-1] = '\0';
100 cp = strpbrk(p, " \t"); 91 cp = strpbrk(p, " \t");
101 if (cp == NULL) 92 if (cp == NULL)
102 goto again; 93 goto again;
@@ -116,8 +107,11 @@ again:
116 cp++; 107 cp++;
117 continue; 108 continue;
118 } 109 }
119 if (q < &net_aliases[MAXALIASES - 1]) 110 if (q < &net_aliases[MAXALIASES - 1]) {
120 *q++ = cp; 111 *q++ = cp;
112 if (strlen(cp) >= MAXHOSTNAMELEN-1)
113 cp[MAXHOSTNAMELEN-1] = '\0';
114 }
121 cp = strpbrk(cp, " \t"); 115 cp = strpbrk(cp, " \t");
122 if (cp != NULL) 116 if (cp != NULL)
123 *cp++ = '\0'; 117 *cp++ = '\0';