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 getservent_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_servent(struct servent
*, struct servent
*, SERV_R_COPY_ARGS
);
37 getservbyname_r(const char *name
, const char *proto
,
38 struct servent
*sptr
, SERV_R_ARGS
) {
39 struct servent
*se
= getservbyname(name
, proto
);
40 #ifdef SERV_R_SETANSWER
43 if (se
== NULL
|| (n
= copy_servent(se
, sptr
, SERV_R_COPY
)) != 0)
53 return (copy_servent(se
, sptr
, SERV_R_COPY
));
58 getservbyport_r(int port
, const char *proto
,
59 struct servent
*sptr
, SERV_R_ARGS
) {
60 struct servent
*se
= getservbyport(port
, proto
);
61 #ifdef SERV_R_SETANSWER
64 if (se
== NULL
|| (n
= copy_servent(se
, sptr
, SERV_R_COPY
)) != 0)
74 return (copy_servent(se
, sptr
, SERV_R_COPY
));
79 * These assume a single context is in operation per thread.
80 * If this is not the case we will need to call irs directly
81 * rather than through the base functions.
85 getservent_r(struct servent
*sptr
, SERV_R_ARGS
) {
86 struct servent
*se
= getservent();
87 #ifdef SERV_R_SETANSWER
90 if (se
== NULL
|| (n
= copy_servent(se
, sptr
, SERV_R_COPY
)) != 0)
100 return (copy_servent(se
, sptr
, SERV_R_COPY
));
105 #ifdef SERV_R_ENT_ARGS
106 setservent_r(int stay_open
, SERV_R_ENT_ARGS
)
108 setservent_r(int stay_open
)
111 #ifdef SERV_R_ENT_UNUSED
114 setservent(stay_open
);
115 #ifdef SERV_R_SET_RESULT
116 return (SERV_R_SET_RESULT
);
121 #ifdef SERV_R_ENT_ARGS
122 endservent_r(SERV_R_ENT_ARGS
)
127 #ifdef SERV_R_ENT_UNUSED
131 SERV_R_END_RESULT(SERV_R_OK
);
138 copy_servent(struct servent
*se
, struct servent
*sptr
, SERV_R_COPY_ARGS
) {
143 /* Find out the amount of space required to store the answer. */
144 numptr
= 1; /*%< NULL ptr */
145 len
= (char *)ALIGN(buf
) - buf
;
146 for (i
= 0; se
->s_aliases
[i
]; i
++, numptr
++) {
147 len
+= strlen(se
->s_aliases
[i
]) + 1;
149 len
+= strlen(se
->s_name
) + 1;
150 len
+= strlen(se
->s_proto
) + 1;
151 len
+= numptr
* sizeof(char*);
153 if (len
> (int)buflen
) {
158 /* copy port value */
159 sptr
->s_port
= se
->s_port
;
161 cp
= (char *)ALIGN(buf
) + numptr
* sizeof(char *);
163 /* copy official name */
164 n
= strlen(se
->s_name
) + 1;
165 strcpy(cp
, se
->s_name
);
170 sptr
->s_aliases
= (char **)ALIGN(buf
);
171 for (i
= 0 ; se
->s_aliases
[i
]; i
++) {
172 n
= strlen(se
->s_aliases
[i
]) + 1;
173 strcpy(cp
, se
->s_aliases
[i
]);
174 sptr
->s_aliases
[i
] = cp
;
177 sptr
->s_aliases
[i
] = NULL
;
180 n
= strlen(se
->s_proto
) + 1;
181 strcpy(cp
, se
->s_proto
);
187 #else /* !SERVENT_DATA */
189 copy_servent(struct servent
*se
, struct servent
*sptr
, SERV_R_COPY_ARGS
) {
193 /* copy port value */
194 sptr
->s_port
= se
->s_port
;
196 /* copy official name */
198 eob
= sdptr
->line
+ sizeof(sdptr
->line
);
199 if ((n
= strlen(se
->s_name
) + 1) < (eob
- cp
)) {
200 strcpy(cp
, se
->s_name
);
209 sptr
->s_aliases
= sdptr
->serv_aliases
;
210 while (se
->s_aliases
[i
] && i
< (_MAXALIASES
-1)) {
211 if ((n
= strlen(se
->s_aliases
[i
]) + 1) < (eob
- cp
)) {
212 strcpy(cp
, se
->s_aliases
[i
]);
213 sptr
->s_aliases
[i
] = cp
;
220 sptr
->s_aliases
[i
] = NULL
;
223 if ((n
= strlen(se
->s_proto
) + 1) < (eob
- cp
)) {
224 strcpy(cp
, se
->s_proto
);
233 #endif /* !SERVENT_DATA */
234 #else /*SERV_R_RETURN */
235 static int getservent_r_unknown_system
= 0;
236 #endif /*SERV_R_RETURN */
237 #endif /* !defined(DO_PTHREADS) */