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.
24 #include <arpa/inet.h>
27 libc_hidden_proto(fopen)
28 libc_hidden_proto(fclose)
29 libc_hidden_proto(inet_network)
30 libc_hidden_proto(rewind)
31 libc_hidden_proto(fgets)
32 libc_hidden_proto(abort)
33 libc_hidden_proto(__uc_malloc)
36 #include <bits/uClibc_mutex.h>
37 __UCLIBC_MUTEX_STATIC(mylock, PTHREAD_MUTEX_INITIALIZER);
42 static const char NETDB[] = _PATH_NETWORKS;
43 static FILE *netf = NULL;
44 static char *line = NULL;
45 static struct netent net;
46 static char *net_aliases[MAXALIASES];
48 smallint _net_stayopen attribute_hidden;
50 libc_hidden_proto(setnetent)
53 __UCLIBC_MUTEX_LOCK(mylock);
55 netf = fopen(NETDB, "r" );
58 if (f) _net_stayopen = 1;
59 __UCLIBC_MUTEX_UNLOCK(mylock);
62 libc_hidden_def(setnetent)
64 libc_hidden_proto(endnetent)
67 __UCLIBC_MUTEX_LOCK(mylock);
73 __UCLIBC_MUTEX_UNLOCK(mylock);
75 libc_hidden_def(endnetent)
77 static char * any(register char *cp, char *match)
82 for (mp = match; *mp; mp++)
90 libc_hidden_proto(getnetent)
91 struct netent *getnetent(void)
94 register char *cp, **q;
95 struct netent *rv = NULL;
97 __UCLIBC_MUTEX_LOCK(mylock);
98 if (netf == NULL && (netf = fopen(NETDB, "r" )) == NULL) {
104 line = __uc_malloc(BUFSIZ + 1);
107 p = fgets(line, BUFSIZ, netf);
122 while (*cp == ' ' || *cp == '\t')
127 net.n_net = inet_network(cp);
128 net.n_addrtype = AF_INET;
129 q = net.n_aliases = net_aliases;
133 if (*cp == ' ' || *cp == '\t') {
137 if (q < &net_aliases[MAXALIASES - 1])
146 __UCLIBC_MUTEX_UNLOCK(mylock);
149 libc_hidden_def(getnetent)