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 #if defined(LIBC_SCCS) && !defined(lint)
19 static const char rcsid
[] = "$Id: getprotoent_r.c,v 1.3.2.1 2004/03/09 09:17:30 marka Exp $";
20 #endif /* LIBC_SCCS and not lint */
22 #include <port_before.h>
23 #if !defined(_REENTRANT) || !defined(DO_PTHREADS)
24 static int getprotoent_r_not_required
= 0;
29 #include <sys/types.h>
30 #include <netinet/in.h>
32 #include <port_after.h>
37 copy_protoent(struct protoent
*, struct protoent
*, PROTO_R_COPY_ARGS
);
40 getprotobyname_r(const char *name
, struct protoent
*pptr
, PROTO_R_ARGS
) {
41 struct protoent
*pe
= getprotobyname(name
);
42 #ifdef PROTO_R_SETANSWER
45 if (pe
== NULL
|| (n
= copy_protoent(pe
, pptr
, PROTO_R_COPY
)) != 0)
55 return (copy_protoent(pe
, pptr
, PROTO_R_COPY
));
60 getprotobynumber_r(int proto
, struct protoent
*pptr
, PROTO_R_ARGS
) {
61 struct protoent
*pe
= getprotobynumber(proto
);
62 #ifdef PROTO_R_SETANSWER
65 if (pe
== NULL
|| (n
= copy_protoent(pe
, pptr
, PROTO_R_COPY
)) != 0)
75 return (copy_protoent(pe
, pptr
, PROTO_R_COPY
));
80 * These assume a single context is in operation per thread.
81 * If this is not the case we will need to call irs directly
82 * rather than through the base functions.
86 getprotoent_r(struct protoent
*pptr
, PROTO_R_ARGS
) {
87 struct protoent
*pe
= getprotoent();
88 #ifdef PROTO_R_SETANSWER
91 if (pe
== NULL
|| (n
= copy_protoent(pe
, pptr
, PROTO_R_COPY
)) != 0)
101 return (copy_protoent(pe
, pptr
, PROTO_R_COPY
));
106 #ifdef PROTO_R_ENT_ARGS
107 setprotoent_r(int stay_open
, PROTO_R_ENT_ARGS
)
109 setprotoent_r(int stay_open
)
112 setprotoent(stay_open
);
113 #ifdef PROTO_R_SET_RESULT
114 return (PROTO_R_SET_RESULT
);
119 #ifdef PROTO_R_ENT_ARGS
120 endprotoent_r(PROTO_R_ENT_ARGS
)
126 PROTO_R_END_RESULT(PROTO_R_OK
);
131 #ifndef PROTOENT_DATA
132 static PROTO_R_RETURN
133 copy_protoent(struct protoent
*pe
, struct protoent
*pptr
, PROTO_R_COPY_ARGS
) {
138 /* Find out the amount of space required to store the answer. */
139 numptr
= 1; /* NULL ptr */
140 len
= (char *)ALIGN(buf
) - buf
;
141 for (i
= 0; pe
->p_aliases
[i
]; i
++, numptr
++) {
142 len
+= strlen(pe
->p_aliases
[i
]) + 1;
144 len
+= strlen(pe
->p_name
) + 1;
145 len
+= numptr
* sizeof(char*);
147 if (len
> (int)buflen
) {
149 return (PROTO_R_BAD
);
152 /* copy protocol value*/
153 pptr
->p_proto
= pe
->p_proto
;
155 cp
= (char *)ALIGN(buf
) + numptr
* sizeof(char *);
157 /* copy official name */
158 n
= strlen(pe
->p_name
) + 1;
159 strcpy(cp
, pe
->p_name
);
164 pptr
->p_aliases
= (char **)ALIGN(buf
);
165 for (i
= 0 ; pe
->p_aliases
[i
]; i
++) {
166 n
= strlen(pe
->p_aliases
[i
]) + 1;
167 strcpy(cp
, pe
->p_aliases
[i
]);
168 pptr
->p_aliases
[i
] = cp
;
171 pptr
->p_aliases
[i
] = NULL
;
175 #else /* !PROTOENT_DATA */
177 copy_protoent(struct protoent
*pe
, struct protoent
*pptr
, PROTO_R_COPY_ARGS
) {
181 /* copy protocol value */
182 pptr
->p_proto
= pe
->p_proto
;
184 /* copy official name */
186 eob
= pdptr
->line
+ sizeof(pdptr
->line
);
187 if ((n
= strlen(pe
->p_name
) + 1) < (eob
- cp
)) {
188 strcpy(cp
, pe
->p_name
);
197 pptr
->p_aliases
= pdptr
->proto_aliases
;
198 while (pe
->p_aliases
[i
] && i
< (_MAXALIASES
-1)) {
199 if ((n
= strlen(pe
->p_aliases
[i
]) + 1) < (eob
- cp
)) {
200 strcpy(cp
, pe
->p_aliases
[i
]);
201 pptr
->p_aliases
[i
] = cp
;
208 pptr
->p_aliases
[i
] = NULL
;
212 #endif /* PROTOENT_DATA */
213 #else /* PROTO_R_RETURN */
214 static int getprotoent_r_unknown_system
= 0;
215 #endif /* PROTO_R_RETURN */
216 #endif /* !defined(_REENTRANT) || !defined(DO_PTHREADS) */