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(DO_PTHREADS)
20 static int getprotoent_r_not_required
= 0;
25 #include <sys/types.h>
26 #include <netinet/in.h>
28 #include <port_after.h>
33 copy_protoent(struct protoent
*, struct protoent
*, PROTO_R_COPY_ARGS
);
36 getprotobyname_r(const char *name
, struct protoent
*pptr
, PROTO_R_ARGS
) {
37 struct protoent
*pe
= getprotobyname(name
);
38 #ifdef PROTO_R_SETANSWER
41 if (pe
== NULL
|| (n
= copy_protoent(pe
, pptr
, PROTO_R_COPY
)) != 0)
51 return (copy_protoent(pe
, pptr
, PROTO_R_COPY
));
56 getprotobynumber_r(int proto
, struct protoent
*pptr
, PROTO_R_ARGS
) {
57 struct protoent
*pe
= getprotobynumber(proto
);
58 #ifdef PROTO_R_SETANSWER
61 if (pe
== NULL
|| (n
= copy_protoent(pe
, pptr
, PROTO_R_COPY
)) != 0)
71 return (copy_protoent(pe
, pptr
, PROTO_R_COPY
));
76 * These assume a single context is in operation per thread.
77 * If this is not the case we will need to call irs directly
78 * rather than through the base functions.
82 getprotoent_r(struct protoent
*pptr
, PROTO_R_ARGS
) {
83 struct protoent
*pe
= getprotoent();
84 #ifdef PROTO_R_SETANSWER
87 if (pe
== NULL
|| (n
= copy_protoent(pe
, pptr
, PROTO_R_COPY
)) != 0)
97 return (copy_protoent(pe
, pptr
, PROTO_R_COPY
));
102 #ifdef PROTO_R_ENT_ARGS
103 setprotoent_r(int stay_open
, PROTO_R_ENT_ARGS
)
105 setprotoent_r(int stay_open
)
108 #ifdef PROTO_R_ENT_UNUSED
111 setprotoent(stay_open
);
112 #ifdef PROTO_R_SET_RESULT
113 return (PROTO_R_SET_RESULT
);
118 #ifdef PROTO_R_ENT_ARGS
119 endprotoent_r(PROTO_R_ENT_ARGS
)
124 #ifdef PROTO_R_ENT_UNUSED
128 PROTO_R_END_RESULT(PROTO_R_OK
);
133 #ifndef PROTOENT_DATA
134 static PROTO_R_RETURN
135 copy_protoent(struct protoent
*pe
, struct protoent
*pptr
, PROTO_R_COPY_ARGS
) {
140 /* Find out the amount of space required to store the answer. */
141 numptr
= 1; /*%< NULL ptr */
142 len
= (char *)ALIGN(buf
) - buf
;
143 for (i
= 0; pe
->p_aliases
[i
]; i
++, numptr
++) {
144 len
+= strlen(pe
->p_aliases
[i
]) + 1;
146 len
+= strlen(pe
->p_name
) + 1;
147 len
+= numptr
* sizeof(char*);
149 if (len
> (int)buflen
) {
151 return (PROTO_R_BAD
);
154 /* copy protocol value*/
155 pptr
->p_proto
= pe
->p_proto
;
157 cp
= (char *)ALIGN(buf
) + numptr
* sizeof(char *);
159 /* copy official name */
160 n
= strlen(pe
->p_name
) + 1;
161 strcpy(cp
, pe
->p_name
);
166 pptr
->p_aliases
= (char **)ALIGN(buf
);
167 for (i
= 0 ; pe
->p_aliases
[i
]; i
++) {
168 n
= strlen(pe
->p_aliases
[i
]) + 1;
169 strcpy(cp
, pe
->p_aliases
[i
]);
170 pptr
->p_aliases
[i
] = cp
;
173 pptr
->p_aliases
[i
] = NULL
;
177 #else /* !PROTOENT_DATA */
179 copy_protoent(struct protoent
*pe
, struct protoent
*pptr
, PROTO_R_COPY_ARGS
) {
183 /* copy protocol value */
184 pptr
->p_proto
= pe
->p_proto
;
186 /* copy official name */
188 eob
= pdptr
->line
+ sizeof(pdptr
->line
);
189 if ((n
= strlen(pe
->p_name
) + 1) < (eob
- cp
)) {
190 strcpy(cp
, pe
->p_name
);
199 pptr
->p_aliases
= pdptr
->proto_aliases
;
200 while (pe
->p_aliases
[i
] && i
< (_MAXALIASES
-1)) {
201 if ((n
= strlen(pe
->p_aliases
[i
]) + 1) < (eob
- cp
)) {
202 strcpy(cp
, pe
->p_aliases
[i
]);
203 pptr
->p_aliases
[i
] = cp
;
210 pptr
->p_aliases
[i
] = NULL
;
214 #endif /* PROTOENT_DATA */
215 #else /* PROTO_R_RETURN */
216 static int getprotoent_r_unknown_system
= 0;
217 #endif /* PROTO_R_RETURN */
218 #endif /* !defined(DO_PTHREADS) */