2 * Copyright (c) 1996 by Internet Software Consortium.
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
9 * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
10 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
11 * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
12 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
13 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
14 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
18 #if !defined(LINT) && !defined(CODECENTER)
19 static char rcsid[] = "$Id: gen_nw.c,v 1.8 1997/12/04 04:57:50 halley Exp $";
24 #include "port_before.h"
26 #include <sys/types.h>
34 #include "port_after.h"
42 struct irs_rule * rules;
43 struct irs_rule * rule;
48 static void nw_close(struct irs_nw*);
49 static struct nwent * nw_next(struct irs_nw *);
50 static struct nwent * nw_byname(struct irs_nw *, const char *, int);
51 static struct nwent * nw_byaddr(struct irs_nw *, void *, int, int);
52 static void nw_rewind(struct irs_nw *);
53 static void nw_minimize(struct irs_nw *);
58 irs_gen_nw(struct irs_acc *this) {
59 struct gen_p *accpvt = (struct gen_p *)this->private;
63 if (!(nw = (struct irs_nw *)malloc(sizeof *nw))) {
67 memset(nw, 0x5e, sizeof *nw);
68 if (!(pvt = (struct pvt *)malloc(sizeof *pvt))) {
73 memset(pvt, 0, sizeof *pvt);
74 pvt->rules = accpvt->map_rules[irs_nw];
75 pvt->rule = pvt->rules;
79 nw->byname = nw_byname;
80 nw->byaddr = nw_byaddr;
81 nw->rewind = nw_rewind;
82 nw->minimize = nw_minimize;
89 nw_close(struct irs_nw *this) {
90 struct pvt *pvt = (struct pvt *)this->private;
97 nw_next(struct irs_nw *this) {
98 struct pvt *pvt = (struct pvt *)this->private;
103 nw = pvt->rule->inst->nw;
104 rval = (*nw->next)(nw);
107 if (!(pvt->rules->flags & IRS_CONTINUE))
109 pvt->rule = pvt->rule->next;
111 nw = pvt->rule->inst->nw;
118 static struct nwent *
119 nw_byname(struct irs_nw *this, const char *name, int type) {
120 struct pvt *pvt = (struct pvt *)this->private;
121 struct irs_rule *rule;
125 for (rule = pvt->rules; rule; rule = rule->next) {
127 h_errno = NETDB_INTERNAL;
128 rval = (*nw->byname)(nw, name, type);
131 if (h_errno != TRY_AGAIN && !(rule->flags & IRS_CONTINUE))
137 static struct nwent *
138 nw_byaddr(struct irs_nw *this, void *net, int length, int type) {
139 struct pvt *pvt = (struct pvt *)this->private;
140 struct irs_rule *rule;
144 for (rule = pvt->rules; rule; rule = rule->next) {
146 h_errno = NETDB_INTERNAL;
147 rval = (*nw->byaddr)(nw, net, length, type);
150 if (h_errno != TRY_AGAIN && !(rule->flags & IRS_CONTINUE))
157 nw_rewind(struct irs_nw *this) {
158 struct pvt *pvt = (struct pvt *)this->private;
161 pvt->rule = pvt->rules;
163 nw = pvt->rule->inst->nw;
169 nw_minimize(struct irs_nw *this) {
170 struct pvt *pvt = (struct pvt *)this->private;
171 struct irs_rule *rule;
173 for (rule = pvt->rules; rule != NULL; rule = rule->next) {
174 struct irs_nw *nw = rule->inst->nw;