eai_to_heim_errno.c revision 78527
1238104Sdes/*
2238104Sdes * Copyright (c) 2000 - 2001 Kungliga Tekniska H�gskolan
3238104Sdes * (Royal Institute of Technology, Stockholm, Sweden).
4238104Sdes * All rights reserved.
5269257Sdes *
6238104Sdes * Redistribution and use in source and binary forms, with or without
7238104Sdes * modification, are permitted provided that the following conditions
8238104Sdes * are met:
9238104Sdes *
10238104Sdes * 1. Redistributions of source code must retain the above copyright
11238104Sdes *    notice, this list of conditions and the following disclaimer.
12238104Sdes *
13238104Sdes * 2. Redistributions in binary form must reproduce the above copyright
14238104Sdes *    notice, this list of conditions and the following disclaimer in the
15238104Sdes *    documentation and/or other materials provided with the distribution.
16269257Sdes *
17269257Sdes * 3. Neither the name of the Institute nor the names of its contributors
18269257Sdes *    may be used to endorse or promote products derived from this software
19269257Sdes *    without specific prior written permission.
20238104Sdes *
21238104Sdes * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22238104Sdes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23238104Sdes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24238104Sdes * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25238104Sdes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26238104Sdes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27238104Sdes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28246854Sdes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29238104Sdes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30238104Sdes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31238104Sdes * SUCH DAMAGE.
32238104Sdes */
33238104Sdes
34238104Sdes#include <krb5_locl.h>
35238104Sdes
36238104SdesRCSID("$Id: eai_to_heim_errno.c,v 1.3 2001/05/14 22:48:33 assar Exp $");
37238104Sdes
38238104Sdes/*
39238104Sdes * convert the getaddrinfo error code in `eai_errno' into a
40238104Sdes * krb5_error_code. `system_error' should have the value of the errno
41238104Sdes * after the failed call.
42238104Sdes */
43238104Sdes
44238104Sdeskrb5_error_code
45238104Sdeskrb5_eai_to_heim_errno(int eai_errno, int system_error)
46238104Sdes{
47246854Sdes    switch(eai_errno) {
48238104Sdes    case EAI_NOERROR:
49238104Sdes	return 0;
50238104Sdes    case EAI_ADDRFAMILY:
51238104Sdes	return HEIM_EAI_ADDRFAMILY;
52238104Sdes    case EAI_AGAIN:
53238104Sdes	return HEIM_EAI_AGAIN;
54238104Sdes    case EAI_BADFLAGS:
55238104Sdes	return HEIM_EAI_BADFLAGS;
56238104Sdes    case EAI_FAIL:
57238104Sdes	return HEIM_EAI_FAIL;
58238104Sdes    case EAI_FAMILY:
59238104Sdes	return HEIM_EAI_FAMILY;
60238104Sdes    case EAI_MEMORY:
61238104Sdes	return HEIM_EAI_MEMORY;
62269257Sdes    case EAI_NODATA:
63269257Sdes	return HEIM_EAI_NODATA;
64238104Sdes    case EAI_NONAME:
65238104Sdes	return HEIM_EAI_NONAME;
66238104Sdes    case EAI_SERVICE:
67238104Sdes	return HEIM_EAI_SERVICE;
68238104Sdes    case EAI_SOCKTYPE:
69269257Sdes	return HEIM_EAI_SOCKTYPE;
70238104Sdes    case EAI_SYSTEM:
71238104Sdes	return system_error;
72238104Sdes    default:
73238104Sdes	return HEIM_EAI_UNKNOWN; /* XXX */
74269257Sdes    }
75238104Sdes}
76238104Sdes
77238104Sdeskrb5_error_code
78238104Sdeskrb5_h_errno_to_heim_errno(int eai_errno)
79238104Sdes{
80238104Sdes    switch(eai_errno) {
81238104Sdes    case 0:
82246854Sdes	return 0;
83238104Sdes    case HOST_NOT_FOUND:
84246854Sdes	return HEIM_EAI_NONAME;
85246854Sdes    case TRY_AGAIN:
86238104Sdes	return HEIM_EAI_AGAIN;
87238104Sdes    case NO_RECOVERY:
88238104Sdes	return HEIM_EAI_FAIL;
89238104Sdes    case NO_DATA:
90246854Sdes	return HEIM_EAI_NONAME;
91246854Sdes    default:
92238104Sdes	return HEIM_EAI_UNKNOWN; /* XXX */
93238104Sdes    }
94238104Sdes}
95238104Sdes