4 * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (c) 1996-1999 by Internet Software Consortium.
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
17 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 #if !defined(LINT) && !defined(CODECENTER)
21 static const char rcsid
[] = "Id: lcl.c,v 1.4 2005/04/27 04:56:30 sra Exp";
26 #include "port_before.h"
32 #include <sys/types.h>
33 #include <netinet/in.h>
34 #include <arpa/nameser.h>
37 #include <isc/memcluster.h>
41 #include "port_after.h"
48 static void lcl_close(struct irs_acc
*);
49 static struct __res_state
* lcl_res_get(struct irs_acc
*);
50 static void lcl_res_set(struct irs_acc
*, struct __res_state
*,
56 irs_lcl_acc(const char *options
) {
62 if (!(acc
= memget(sizeof *acc
))) {
66 memset(acc
, 0x5e, sizeof *acc
);
67 if (!(lcl
= memget(sizeof *lcl
))) {
72 memset(lcl
, 0x5e, sizeof *lcl
);
77 acc
->gr_map
= irs_lcl_gr
;
82 acc
->pw_map
= irs_lcl_pw
;
86 acc
->sv_map
= irs_lcl_sv
;
87 acc
->pr_map
= irs_lcl_pr
;
88 acc
->ho_map
= irs_lcl_ho
;
89 acc
->nw_map
= irs_lcl_nw
;
90 acc
->ng_map
= irs_lcl_ng
;
91 acc
->res_get
= lcl_res_get
;
92 acc
->res_set
= lcl_res_set
;
93 acc
->close
= lcl_close
;
98 static struct __res_state
*
99 lcl_res_get(struct irs_acc
*this) {
100 struct lcl_p
*lcl
= (struct lcl_p
*)this->private;
102 if (lcl
->res
== NULL
) {
103 struct __res_state
*res
;
104 res
= (struct __res_state
*)malloc(sizeof *res
);
107 memset(res
, 0, sizeof *res
);
108 lcl_res_set(this, res
, free
);
111 if ((lcl
->res
->options
& RES_INIT
) == 0U &&
112 res_ninit(lcl
->res
) < 0)
119 lcl_res_set(struct irs_acc
*this, struct __res_state
*res
,
120 void (*free_res
)(void *)) {
121 struct lcl_p
*lcl
= (struct lcl_p
*)this->private;
123 if (lcl
->res
&& lcl
->free_res
) {
124 res_nclose(lcl
->res
);
125 (*lcl
->free_res
)(lcl
->res
);
129 lcl
->free_res
= free_res
;
133 lcl_close(struct irs_acc
*this) {
134 struct lcl_p
*lcl
= (struct lcl_p
*)this->private;
138 (*lcl
->free_res
)(lcl
->res
);
139 memput(lcl
, sizeof *lcl
);
141 memput(this, sizeof *this);