2 * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (c) 1998-1999 by Internet Software Consortium.
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
15 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 #include <port_before.h>
19 #if !defined(_REENTRANT) || !defined(DO_PTHREADS)
20 static int getnetent_r_not_required
= 0;
25 #include <sys/types.h>
26 #include <netinet/in.h>
28 #include <sys/param.h>
29 #include <port_after.h>
34 copy_netent(struct netent
*, struct netent
*, NET_R_COPY_ARGS
);
37 getnetbyname_r(const char *name
, struct netent
*nptr
, NET_R_ARGS
) {
38 struct netent
*ne
= getnetbyname(name
);
39 #ifdef NET_R_SETANSWER
42 if (ne
== NULL
|| (n
= copy_netent(ne
, nptr
, NET_R_COPY
)) != 0)
53 return (copy_netent(ne
, nptr
, NET_R_COPY
));
57 #ifndef GETNETBYADDR_ADDR_T
58 #define GETNETBYADDR_ADDR_T long
61 getnetbyaddr_r(GETNETBYADDR_ADDR_T addr
, int type
, struct netent
*nptr
, NET_R_ARGS
) {
62 struct netent
*ne
= getnetbyaddr(addr
, type
);
63 #ifdef NET_R_SETANSWER
66 if (ne
== NULL
|| (n
= copy_netent(ne
, nptr
, NET_R_COPY
)) != 0)
78 return (copy_netent(ne
, nptr
, NET_R_COPY
));
83 * These assume a single context is in operation per thread.
84 * If this is not the case we will need to call irs directly
85 * rather than through the base functions.
89 getnetent_r(struct netent
*nptr
, NET_R_ARGS
) {
90 struct netent
*ne
= getnetent();
91 #ifdef NET_R_SETANSWER
94 if (ne
== NULL
|| (n
= copy_netent(ne
, nptr
, NET_R_COPY
)) != 0)
106 return (copy_netent(ne
, nptr
, NET_R_COPY
));
111 #ifdef NET_R_ENT_ARGS
112 setnetent_r(int stay_open
, NET_R_ENT_ARGS
)
114 setnetent_r(int stay_open
)
117 #ifdef NET_R_ENT_ARGS
120 setnetent(stay_open
);
121 #ifdef NET_R_SET_RESULT
122 return (NET_R_SET_RESULT
);
127 #ifdef NET_R_ENT_ARGS
128 endnetent_r(NET_R_ENT_ARGS
)
133 #ifdef NET_R_ENT_ARGS
137 NET_R_END_RESULT(NET_R_OK
);
144 copy_netent(struct netent
*ne
, struct netent
*nptr
, NET_R_COPY_ARGS
) {
149 /* Find out the amount of space required to store the answer. */
150 numptr
= 1; /*%< NULL ptr */
151 len
= (char *)ALIGN(buf
) - buf
;
152 for (i
= 0; ne
->n_aliases
[i
]; i
++, numptr
++) {
153 len
+= strlen(ne
->n_aliases
[i
]) + 1;
155 len
+= strlen(ne
->n_name
) + 1;
156 len
+= numptr
* sizeof(char*);
158 if (len
> (int)buflen
) {
163 /* copy net value and type */
164 nptr
->n_addrtype
= ne
->n_addrtype
;
165 nptr
->n_net
= ne
->n_net
;
167 cp
= (char *)ALIGN(buf
) + numptr
* sizeof(char *);
169 /* copy official name */
170 n
= strlen(ne
->n_name
) + 1;
171 strcpy(cp
, ne
->n_name
);
176 nptr
->n_aliases
= (char **)ALIGN(buf
);
177 for (i
= 0 ; ne
->n_aliases
[i
]; i
++) {
178 n
= strlen(ne
->n_aliases
[i
]) + 1;
179 strcpy(cp
, ne
->n_aliases
[i
]);
180 nptr
->n_aliases
[i
] = cp
;
183 nptr
->n_aliases
[i
] = NULL
;
187 #else /* !NETENT_DATA */
189 copy_netent(struct netent
*ne
, struct netent
*nptr
, NET_R_COPY_ARGS
) {
193 /* copy net value and type */
194 nptr
->n_addrtype
= ne
->n_addrtype
;
195 nptr
->n_net
= ne
->n_net
;
197 /* copy official name */
199 eob
= ndptr
->line
+ sizeof(ndptr
->line
);
200 if ((n
= strlen(ne
->n_name
) + 1) < (eob
- cp
)) {
201 strcpy(cp
, ne
->n_name
);
210 nptr
->n_aliases
= ndptr
->net_aliases
;
211 while (ne
->n_aliases
[i
] && i
< (_MAXALIASES
-1)) {
212 if ((n
= strlen(ne
->n_aliases
[i
]) + 1) < (eob
- cp
)) {
213 strcpy(cp
, ne
->n_aliases
[i
]);
214 nptr
->n_aliases
[i
] = cp
;
221 nptr
->n_aliases
[i
] = NULL
;
225 #endif /* !NETENT_DATA */
226 #else /* NET_R_RETURN */
227 static int getnetent_r_unknown_system
= 0;
228 #endif /* NET_R_RETURN */
229 #endif /* !defined(_REENTRANT) || !defined(DO_PTHREADS) */