2 * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (c) 1996-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"
24 #include <sys/types.h>
25 #include <netinet/in.h>
26 #include <arpa/nameser.h>
29 #include <isc/memcluster.h>
33 #include "port_after.h"
40 static void lcl_close(struct irs_acc
*);
41 static struct __res_state
* lcl_res_get(struct irs_acc
*);
42 static void lcl_res_set(struct irs_acc
*, struct __res_state
*,
48 irs_lcl_acc(const char *options
) {
54 if (!(acc
= memget(sizeof *acc
))) {
58 memset(acc
, 0x5e, sizeof *acc
);
59 if (!(lcl
= memget(sizeof *lcl
))) {
64 memset(lcl
, 0x5e, sizeof *lcl
);
69 acc
->gr_map
= irs_lcl_gr
;
74 acc
->pw_map
= irs_lcl_pw
;
78 acc
->sv_map
= irs_lcl_sv
;
79 acc
->pr_map
= irs_lcl_pr
;
80 acc
->ho_map
= irs_lcl_ho
;
81 acc
->nw_map
= irs_lcl_nw
;
82 acc
->ng_map
= irs_lcl_ng
;
83 acc
->res_get
= lcl_res_get
;
84 acc
->res_set
= lcl_res_set
;
85 acc
->close
= lcl_close
;
90 static struct __res_state
*
91 lcl_res_get(struct irs_acc
*this) {
92 struct lcl_p
*lcl
= (struct lcl_p
*)this->private;
94 if (lcl
->res
== NULL
) {
95 struct __res_state
*res
;
96 res
= (struct __res_state
*)malloc(sizeof *res
);
99 memset(res
, 0, sizeof *res
);
100 lcl_res_set(this, res
, free
);
103 if ((lcl
->res
->options
& RES_INIT
) == 0U &&
104 res_ninit(lcl
->res
) < 0)
111 lcl_res_set(struct irs_acc
*this, struct __res_state
*res
,
112 void (*free_res
)(void *)) {
113 struct lcl_p
*lcl
= (struct lcl_p
*)this->private;
115 if (lcl
->res
&& lcl
->free_res
) {
116 res_nclose(lcl
->res
);
117 (*lcl
->free_res
)(lcl
->res
);
121 lcl
->free_res
= free_res
;
125 lcl_close(struct irs_acc
*this) {
126 struct lcl_p
*lcl
= (struct lcl_p
*)this->private;
130 (*lcl
->free_res
)(lcl
->res
);
131 memput(lcl
, sizeof *lcl
);
133 memput(this, sizeof *this);