2 * Copyright (c) 1983 Regents of the University of California.
5 * Redistribution and use in source and binary forms are permitted
6 * provided that the above copyright notice and this paragraph are
7 * duplicated in all such forms and that any documentation,
8 * advertising materials, and other materials related to such
9 * distribution and use acknowledge that the software was developed
10 * by the University of California, Berkeley. The name of the
11 * University may not be used to endorse or promote products derived
12 * from this software without specific prior written permission.
13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
23 #include <arpa/inet.h>
26 /* libc_hidden_proto(fopen) */
27 /* libc_hidden_proto(fclose) */
28 /* libc_hidden_proto(inet_network) */
29 /* libc_hidden_proto(rewind) */
30 /* libc_hidden_proto(fgets) */
31 /* libc_hidden_proto(abort) */
33 #include <bits/uClibc_mutex.h>
34 __UCLIBC_MUTEX_STATIC(mylock, PTHREAD_MUTEX_INITIALIZER);
39 static const char NETDB[] = _PATH_NETWORKS;
40 static FILE *netf = NULL;
41 static char *line = NULL;
42 static struct netent net;
43 static char *net_aliases[MAXALIASES];
45 smallint _net_stayopen attribute_hidden;
47 /* libc_hidden_proto(setnetent) */
50 __UCLIBC_MUTEX_LOCK(mylock);
52 netf = fopen(NETDB, "r" );
55 if (f) _net_stayopen = 1;
56 __UCLIBC_MUTEX_UNLOCK(mylock);
59 libc_hidden_def(setnetent)
61 /* libc_hidden_proto(endnetent) */
64 __UCLIBC_MUTEX_LOCK(mylock);
70 __UCLIBC_MUTEX_UNLOCK(mylock);
72 libc_hidden_def(endnetent)
74 static char * any(register char *cp, char *match)
79 for (mp = match; *mp; mp++)
87 /* libc_hidden_proto(getnetent) */
88 struct netent *getnetent(void)
91 register char *cp, **q;
92 struct netent *rv = NULL;
94 __UCLIBC_MUTEX_LOCK(mylock);
95 if (netf == NULL && (netf = fopen(NETDB, "r" )) == NULL) {
101 line = malloc(BUFSIZ + 1);
106 p = fgets(line, BUFSIZ, netf);
121 while (*cp == ' ' || *cp == '\t')
126 net.n_net = inet_network(cp);
127 net.n_addrtype = AF_INET;
128 q = net.n_aliases = net_aliases;
132 if (*cp == ' ' || *cp == '\t') {
136 if (q < &net_aliases[MAXALIASES - 1])
145 __UCLIBC_MUTEX_UNLOCK(mylock);
148 libc_hidden_def(getnetent)