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>
27 #include <bits/uClibc_mutex.h>
28 __UCLIBC_MUTEX_STATIC(mylock, PTHREAD_MUTEX_INITIALIZER);
33 static const char NETDB[] = _PATH_NETWORKS;
34 static FILE *netf = NULL;
35 static char *line = NULL;
36 static struct netent net;
37 static char *net_aliases[MAXALIASES];
39 smallint _net_stayopen attribute_hidden;
43 __UCLIBC_MUTEX_LOCK(mylock);
45 netf = fopen(NETDB, "r" );
48 if (f) _net_stayopen = 1;
49 __UCLIBC_MUTEX_UNLOCK(mylock);
52 libc_hidden_def(setnetent)
56 __UCLIBC_MUTEX_LOCK(mylock);
62 __UCLIBC_MUTEX_UNLOCK(mylock);
64 libc_hidden_def(endnetent)
66 static char * any(register char *cp, char *match)
71 for (mp = match; *mp; mp++)
79 struct netent *getnetent(void)
82 register char *cp, **q;
83 struct netent *rv = NULL;
85 __UCLIBC_MUTEX_LOCK(mylock);
86 if (netf == NULL && (netf = fopen(NETDB, "r" )) == NULL) {
92 line = malloc(BUFSIZ + 1);
97 p = fgets(line, BUFSIZ, netf);
112 while (*cp == ' ' || *cp == '\t')
117 net.n_net = inet_network(cp);
118 net.n_addrtype = AF_INET;
119 q = net.n_aliases = net_aliases;
123 if (*cp == ' ' || *cp == '\t') {
127 if (q < &net_aliases[MAXALIASES - 1])
136 __UCLIBC_MUTEX_UNLOCK(mylock);
139 libc_hidden_def(getnetent)