2 * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
3 * Portions Copyright (c) 1996 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"
21 #include <sys/types.h>
33 #include <isc/memcluster.h>
34 #include <isc/irpmarshall.h>
40 #include "port_after.h"
48 struct irp_p
*girpdata
;
50 struct protoent proto
;
55 static void pr_close(struct irs_pr
*);
56 static struct protoent
* pr_next(struct irs_pr
*);
57 static struct protoent
* pr_byname(struct irs_pr
*, const char *);
58 static struct protoent
* pr_bynumber(struct irs_pr
*, int);
59 static void pr_rewind(struct irs_pr
*);
60 static void pr_minimize(struct irs_pr
*);
62 static void free_proto(struct protoent
*pr
);
67 * struct irs_pr * irs_irp_pr(struct irs_acc *this)
72 irs_irp_pr(struct irs_acc
*this) {
76 if (!(pr
= memget(sizeof *pr
))) {
80 memset(pr
, 0x0, sizeof *pr
);
82 if (!(pvt
= memget(sizeof *pvt
))) {
83 memput(pr
, sizeof *pr
);
87 memset(pvt
, 0, sizeof *pvt
);
88 pvt
->girpdata
= this->private;
92 pr
->byname
= pr_byname
;
93 pr
->bynumber
= pr_bynumber
;
95 pr
->rewind
= pr_rewind
;
96 pr
->minimize
= pr_minimize
;
103 * void pr_close(struct irs_pr *this)
108 pr_close(struct irs_pr
*this) {
109 struct pvt
*pvt
= (struct pvt
*)this->private;
113 free_proto(&pvt
->proto
);
115 memput(pvt
, sizeof *pvt
);
116 memput(this, sizeof *this);
120 * struct protoent * pr_byname(struct irs_pr *this, const char *name)
124 static struct protoent
*
125 pr_byname(struct irs_pr
*this, const char *name
) {
126 struct pvt
*pvt
= (struct pvt
*)this->private;
127 struct protoent
*pr
= &pvt
->proto
;
134 if (pr
->p_name
!= NULL
&& strcmp(name
, pr
->p_name
) == 0) {
138 if (irs_irp_connection_setup(pvt
->girpdata
, &pvt
->warned
) != 0) {
142 i
= irs_irp_send_command(pvt
->girpdata
, "getprotobyname %s", name
);
146 if (irs_irp_get_full_response(pvt
->girpdata
, &code
,
148 &body
, &bodylen
) != 0) {
152 if (code
== IRPD_GETPROTO_OK
) {
154 if (irp_unmarshall_pr(pr
, body
) != 0) {
162 memput(body
, bodylen
);
169 * struct protoent * pr_bynumber(struct irs_pr *this, int proto)
173 static struct protoent
*
174 pr_bynumber(struct irs_pr
*this, int proto
) {
175 struct pvt
*pvt
= (struct pvt
*)this->private;
176 struct protoent
*pr
= &pvt
->proto
;
183 if (pr
->p_name
!= NULL
&& proto
== pr
->p_proto
) {
187 if (irs_irp_connection_setup(pvt
->girpdata
, &pvt
->warned
) != 0) {
191 i
= irs_irp_send_command(pvt
->girpdata
, "getprotobynumber %d", proto
);
195 if (irs_irp_get_full_response(pvt
->girpdata
, &code
,
197 &body
, &bodylen
) != 0) {
201 if (code
== IRPD_GETPROTO_OK
) {
203 if (irp_unmarshall_pr(pr
, body
) != 0) {
211 memput(body
, bodylen
);
218 * void pr_rewind(struct irs_pr *this)
223 pr_rewind(struct irs_pr
*this) {
224 struct pvt
*pvt
= (struct pvt
*)this->private;
228 if (irs_irp_connection_setup(pvt
->girpdata
, &pvt
->warned
) != 0) {
232 if (irs_irp_send_command(pvt
->girpdata
, "setprotoent") != 0) {
236 code
= irs_irp_read_response(pvt
->girpdata
, text
, sizeof text
);
237 if (code
!= IRPD_GETPROTO_SETOK
) {
238 if (irp_log_errors
) {
239 syslog(LOG_WARNING
, "setprotoent failed: %s", text
);
247 * Prepares the cache if necessary and returns the next item in it.
251 static struct protoent
*
252 pr_next(struct irs_pr
*this) {
253 struct pvt
*pvt
= (struct pvt
*)this->private;
254 struct protoent
*pr
= &pvt
->proto
;
260 if (irs_irp_connection_setup(pvt
->girpdata
, &pvt
->warned
) != 0) {
264 if (irs_irp_send_command(pvt
->girpdata
, "getprotoent") != 0) {
268 if (irs_irp_get_full_response(pvt
->girpdata
, &code
,
270 &body
, &bodylen
) != 0) {
274 if (code
== IRPD_GETPROTO_OK
) {
276 if (irp_unmarshall_pr(pr
, body
) != 0) {
284 memput(body
, bodylen
);
291 * void pr_minimize(struct irs_pr *this)
296 pr_minimize(struct irs_pr
*this) {
297 struct pvt
*pvt
= (struct pvt
*)this->private;
299 irs_irp_disconnect(pvt
->girpdata
);
303 * Deallocate all the memory irp_unmarshall_pr allocated.
308 free_proto(struct protoent
*pr
) {
316 for (p
= pr
->p_aliases
; p
!= NULL
&& *p
!= NULL
; p
++)