Initial import from FreeBSD RELENG_4:
[games.git] / contrib / isc-dhcp / omapip / toisc.c
1 /* toisc.c
2
3    Convert non-ISC result codes to ISC result codes. */
4
5 /*
6  * Copyright (c) 2001 Internet Software Consortium.
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. Neither the name of The Internet Software Consortium nor the names
19  *    of its contributors may be used to endorse or promote products derived
20  *    from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE INTERNET SOFTWARE CONSORTIUM AND
23  * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
24  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26  * DISCLAIMED.  IN NO EVENT SHALL THE INTERNET SOFTWARE CONSORTIUM OR
27  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
30  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
33  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34  * SUCH DAMAGE.
35  *
36  * This software has been written for the Internet Software Consortium
37  * by Ted Lemon in cooperation with Vixie Enterprises and Nominum, Inc.
38  * To learn more about the Internet Software Consortium, see
39  * ``http://www.isc.org/''.  To learn more about Vixie Enterprises,
40  * see ``http://www.vix.com''.   To learn more about Nominum, Inc., see
41  * ``http://www.nominum.com''.
42  */
43
44 #include <omapip/omapip_p.h>
45 #include "arpa/nameser.h"
46 #include "minires/minires.h"
47
48 isc_result_t ns_rcode_to_isc (int nsr)
49 {
50         switch (nsr) {
51               case ns_r_noerror:
52                 return ISC_R_SUCCESS;
53
54               case ns_r_formerr:
55                 return ISC_R_FORMERR;
56
57               case ns_r_servfail:
58                 return ISC_R_SERVFAIL;
59
60               case ns_r_nxdomain:
61                 return ISC_R_NXDOMAIN;
62
63               case ns_r_notimpl:
64                 return ISC_R_NOTIMPL;
65
66               case ns_r_refused:
67                 return ISC_R_REFUSED;
68
69               case ns_r_yxdomain:
70                 return ISC_R_YXDOMAIN;
71
72               case ns_r_yxrrset:
73                 return ISC_R_YXRRSET;
74
75               case ns_r_nxrrset:
76                 return ISC_R_NXRRSET;
77
78               case ns_r_notauth:
79                 return ISC_R_NOTAUTH;
80
81               case ns_r_notzone:
82                 return ISC_R_NOTZONE;
83
84               case ns_r_badsig:
85                 return ISC_R_BADSIG;
86
87               case ns_r_badkey:
88                 return ISC_R_BADKEY;
89
90               case ns_r_badtime:
91                 return ISC_R_BADTIME;
92
93               default:
94                 ;
95         }
96         return ISC_R_UNEXPECTED;
97 }
98
99 isc_result_t uerr2isc (int err)
100 {
101         switch (err) {
102               case EPERM:
103                 return ISC_R_NOPERM;
104
105               case ENOENT:
106                 return ISC_R_NOTFOUND;
107
108               case ESRCH:
109                 return ISC_R_NOTFOUND;
110
111               case EIO:
112                 return ISC_R_IOERROR;
113
114               case ENXIO:
115                 return ISC_R_NOTFOUND;
116
117               case E2BIG:
118                 return ISC_R_NOSPACE;
119
120               case ENOEXEC:
121                 return ISC_R_FORMERR;
122
123               case ECHILD:
124                 return ISC_R_NOTFOUND;
125
126               case ENOMEM:
127                 return ISC_R_NOMEMORY;
128
129               case EACCES:
130                 return ISC_R_NOPERM;
131
132               case EFAULT:
133                 return ISC_R_INVALIDARG;
134
135               case EEXIST:
136                 return ISC_R_EXISTS;
137
138               case EINVAL:
139                 return ISC_R_INVALIDARG;
140
141               case ENOTTY:
142                 return ISC_R_INVALIDARG;
143
144               case EFBIG:
145                 return ISC_R_NOSPACE;
146
147               case ENOSPC:
148                 return ISC_R_NOSPACE;
149
150               case EROFS:
151                 return ISC_R_NOPERM;
152
153               case EMLINK:
154                 return ISC_R_NOSPACE;
155
156               case EPIPE:
157                 return ISC_R_NOTCONNECTED;
158
159               case EINPROGRESS:
160                 return ISC_R_ALREADYRUNNING;
161
162               case EALREADY:
163                 return ISC_R_ALREADYRUNNING;
164
165               case ENOTSOCK:
166                 return ISC_R_INVALIDFILE;
167
168               case EDESTADDRREQ:
169                 return ISC_R_DESTADDRREQ;
170
171               case EMSGSIZE:
172                 return ISC_R_NOSPACE;
173
174               case EPROTOTYPE:
175                 return ISC_R_INVALIDARG;
176
177               case ENOPROTOOPT:
178                 return ISC_R_NOTIMPLEMENTED;
179
180               case EPROTONOSUPPORT:
181                 return ISC_R_NOTIMPLEMENTED;
182
183               case ESOCKTNOSUPPORT:
184                 return ISC_R_NOTIMPLEMENTED;
185
186               case EOPNOTSUPP:
187                 return ISC_R_NOTIMPLEMENTED;
188
189               case EPFNOSUPPORT:
190                 return ISC_R_NOTIMPLEMENTED;
191
192               case EAFNOSUPPORT:
193                 return ISC_R_NOTIMPLEMENTED;
194
195               case EADDRINUSE:
196                 return ISC_R_ADDRINUSE;
197
198               case EADDRNOTAVAIL:
199                 return ISC_R_ADDRNOTAVAIL;
200
201               case ENETDOWN:
202                 return ISC_R_NETDOWN;
203
204               case ENETUNREACH:
205                 return ISC_R_NETUNREACH;
206
207               case ECONNABORTED:
208                 return ISC_R_TIMEDOUT;
209
210               case ECONNRESET:
211                 return ISC_R_CONNRESET;
212
213               case ENOBUFS:
214                 return ISC_R_NOSPACE;
215
216               case EISCONN:
217                 return ISC_R_ALREADYRUNNING;
218
219               case ENOTCONN:
220                 return ISC_R_NOTCONNECTED;
221
222               case ESHUTDOWN:
223                 return ISC_R_SHUTTINGDOWN;
224
225               case ETIMEDOUT:
226                 return ISC_R_TIMEDOUT;
227
228               case ECONNREFUSED:
229                 return ISC_R_CONNREFUSED;
230
231               case EHOSTDOWN:
232                 return ISC_R_HOSTDOWN;
233
234               case EHOSTUNREACH:
235                 return ISC_R_HOSTUNREACH;
236
237 #ifdef EDQUOT
238               case EDQUOT:
239                 return ISC_R_QUOTA;
240 #endif
241
242 #ifdef EBADRPC
243               case EBADRPC:
244                 return ISC_R_NOTIMPLEMENTED;
245 #endif
246
247 #ifdef ERPCMISMATCH
248               case ERPCMISMATCH:
249                 return ISC_R_VERSIONMISMATCH;
250 #endif
251
252 #ifdef EPROGMISMATCH
253               case EPROGMISMATCH:
254                 return ISC_R_VERSIONMISMATCH;
255 #endif
256
257 #ifdef EAUTH
258               case EAUTH:
259                 return ISC_R_NOTAUTH;
260 #endif
261
262 #ifdef ENEEDAUTH
263               case ENEEDAUTH:
264                 return ISC_R_NOTAUTH;
265 #endif
266
267 #ifdef EOVERFLOW
268               case EOVERFLOW:
269                 return ISC_R_NOSPACE;
270 #endif
271         }
272         return ISC_R_UNEXPECTED;
273 }
274
275 ns_rcode isc_rcode_to_ns (isc_result_t isc)
276 {
277         switch (isc) {
278               case ISC_R_SUCCESS:
279                 return ns_r_noerror;
280
281               case ISC_R_FORMERR:
282                 return ns_r_formerr;
283
284               case ISC_R_SERVFAIL:
285                 return ns_r_servfail;
286
287               case ISC_R_NXDOMAIN:
288                 return ns_r_nxdomain;
289
290               case ISC_R_NOTIMPL:
291                 return ns_r_notimpl;
292
293               case ISC_R_REFUSED:
294                 return ns_r_refused;
295
296               case ISC_R_YXDOMAIN:
297                 return ns_r_yxdomain;
298
299               case ISC_R_YXRRSET:
300                 return ns_r_yxrrset;
301
302               case ISC_R_NXRRSET:
303                 return ns_r_nxrrset;
304
305               case ISC_R_NOTAUTH:
306                 return ns_r_notauth;
307
308               case ISC_R_NOTZONE:
309                 return ns_r_notzone;
310
311               case ISC_R_BADSIG:
312                 return ns_r_badsig;
313
314               case ISC_R_BADKEY:
315                 return ns_r_badkey;
316
317               case ISC_R_BADTIME:
318                 return ns_r_badtime;
319
320               default:
321                 ;
322         }
323         return ns_r_servfail;
324 }