summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorschwarze <>2018-04-28 15:05:40 +0000
committerschwarze <>2018-04-28 15:05:40 +0000
commit576e1262a2eeb01aa82b8346754026420b6143b7 (patch)
treee62167e37b20a4ed7673c86842da13d18a1ee836 /src/lib
parent3cea2322ceb21eb9865410e66501a89edc3bbf08 (diff)
downloadopenbsd-576e1262a2eeb01aa82b8346754026420b6143b7.tar.gz
openbsd-576e1262a2eeb01aa82b8346754026420b6143b7.tar.bz2
openbsd-576e1262a2eeb01aa82b8346754026420b6143b7.zip
To allow us to get rid of /etc/networks, make setnetent(3),
getnetent(3), and endnetent(3) do nothing, just like sethostent(3), gethostent(3), and endhostent(3) years ago. OK deraadt@ guenther@
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/libc/net/getnetent.c79
1 files changed, 4 insertions, 75 deletions
diff --git a/src/lib/libc/net/getnetent.c b/src/lib/libc/net/getnetent.c
index b16575b64d..b93e442fa9 100644
--- a/src/lib/libc/net/getnetent.c
+++ b/src/lib/libc/net/getnetent.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: getnetent.c,v 1.17 2015/01/16 18:20:14 millert Exp $ */ 1/* $OpenBSD: getnetent.c,v 1.18 2018/04/28 15:05:40 schwarze Exp $ */
2/* 2/*
3 * Copyright (c) 1983, 1993 3 * Copyright (c) 1983, 1993
4 * The Regents of the University of California. All rights reserved. 4 * The Regents of the University of California. All rights reserved.
@@ -28,93 +28,22 @@
28 * SUCH DAMAGE. 28 * SUCH DAMAGE.
29 */ 29 */
30 30
31#include <sys/socket.h>
32#include <netinet/in.h>
33#include <arpa/inet.h>
34#include <netdb.h> 31#include <netdb.h>
35#include <stdio.h> 32#include <stddef.h>
36#include <string.h>
37#include <limits.h>
38
39#define MAXALIASES 35
40
41static FILE *netf;
42static char line[BUFSIZ+1];
43static struct netent net;
44static char *net_aliases[MAXALIASES];
45int _net_stayopen;
46 33
47void 34void
48setnetent(int f) 35setnetent(int f)
49{ 36{
50 if (netf == NULL)
51 netf = fopen(_PATH_NETWORKS, "re" );
52 else
53 rewind(netf);
54 _net_stayopen |= f;
55} 37}
56 38
57void 39void
58endnetent(void) 40endnetent(void)
59{ 41{
60 if (netf) {
61 fclose(netf);
62 netf = NULL;
63 }
64 _net_stayopen = 0;
65} 42}
66 43
67struct netent * 44struct netent *
68getnetent(void) 45getnetent(void)
69{ 46{
70 char *p, *cp, **q; 47 h_errno = NETDB_INTERNAL;
71 size_t len; 48 return NULL;
72
73 if (netf == NULL && (netf = fopen(_PATH_NETWORKS, "re" )) == NULL)
74 return (NULL);
75again:
76 if ((p = fgetln(netf, &len)) == NULL)
77 return (NULL);
78 if (p[len-1] == '\n')
79 len--;
80 if (len >= sizeof(line) || len == 0)
81 goto again;
82 p = memcpy(line, p, len);
83 line[len] = '\0';
84 if (*p == '#')
85 goto again;
86 if ((cp = strchr(p, '#')) != NULL)
87 *cp = '\0';
88 net.n_name = p;
89 if (strlen(net.n_name) > HOST_NAME_MAX)
90 net.n_name[HOST_NAME_MAX] = '\0';
91 cp = strpbrk(p, " \t");
92 if (cp == NULL)
93 goto again;
94 *cp++ = '\0';
95 while (*cp == ' ' || *cp == '\t')
96 cp++;
97 p = strpbrk(cp, " \t");
98 if (p != NULL)
99 *p++ = '\0';
100 net.n_net = inet_network(cp);
101 net.n_addrtype = AF_INET;
102 q = net.n_aliases = net_aliases;
103 cp = p;
104 while (cp && *cp) {
105 if (*cp == ' ' || *cp == '\t') {
106 cp++;
107 continue;
108 }
109 if (q < &net_aliases[MAXALIASES - 1]) {
110 *q++ = cp;
111 if (strlen(cp) > HOST_NAME_MAX)
112 cp[HOST_NAME_MAX] = '\0';
113 }
114 cp = strpbrk(cp, " \t");
115 if (cp != NULL)
116 *cp++ = '\0';
117 }
118 *q = NULL;
119 return (&net);
120} 49}