eai_to_heim_errno.c revision 127808
11541Srgrimes/*
21541Srgrimes * Copyright (c) 2000 - 2001 Kungliga Tekniska H�gskolan
31541Srgrimes * (Royal Institute of Technology, Stockholm, Sweden).
41541Srgrimes * All rights reserved.
5165896Srwatson *
6165896Srwatson * Redistribution and use in source and binary forms, with or without
7165896Srwatson * modification, are permitted provided that the following conditions
81541Srgrimes * are met:
91541Srgrimes *
101541Srgrimes * 1. Redistributions of source code must retain the above copyright
111541Srgrimes *    notice, this list of conditions and the following disclaimer.
121541Srgrimes *
13165896Srwatson * 2. Redistributions in binary form must reproduce the above copyright
14165896Srwatson *    notice, this list of conditions and the following disclaimer in the
15165896Srwatson *    documentation and/or other materials provided with the distribution.
16165896Srwatson *
17165896Srwatson * 3. Neither the name of the Institute nor the names of its contributors
18165896Srwatson *    may be used to endorse or promote products derived from this software
19165896Srwatson *    without specific prior written permission.
20165896Srwatson *
21165896Srwatson * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22165896Srwatson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23165896Srwatson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24165896Srwatson * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25165896Srwatson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26165896Srwatson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27165896Srwatson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28165896Srwatson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29165896Srwatson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30165896Srwatson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31165896Srwatson * SUCH DAMAGE.
32165896Srwatson */
33165896Srwatson
34165896Srwatson#include <krb5_locl.h>
35165896Srwatson
36165896SrwatsonRCSID("$Id: eai_to_heim_errno.c,v 1.3.8.1 2004/02/13 16:15:16 lha Exp $");
37152328Srwatson
38152328Srwatson/*
391541Srgrimes * convert the getaddrinfo error code in `eai_errno' into a
401541Srgrimes * krb5_error_code. `system_error' should have the value of the errno
411541Srgrimes * after the failed call.
421541Srgrimes */
431541Srgrimes
441541Srgrimeskrb5_error_code
451541Srgrimeskrb5_eai_to_heim_errno(int eai_errno, int system_error)
461541Srgrimes{
471541Srgrimes    switch(eai_errno) {
481541Srgrimes    case EAI_NOERROR:
491541Srgrimes	return 0;
501541Srgrimes#ifdef EAI_ADDRFAMILY
511541Srgrimes    case EAI_ADDRFAMILY:
521541Srgrimes	return HEIM_EAI_ADDRFAMILY;
531541Srgrimes#endif
541541Srgrimes    case EAI_AGAIN:
551541Srgrimes	return HEIM_EAI_AGAIN;
561541Srgrimes    case EAI_BADFLAGS:
571541Srgrimes	return HEIM_EAI_BADFLAGS;
581541Srgrimes    case EAI_FAIL:
591541Srgrimes	return HEIM_EAI_FAIL;
601541Srgrimes    case EAI_FAMILY:
611541Srgrimes	return HEIM_EAI_FAMILY;
621541Srgrimes    case EAI_MEMORY:
631541Srgrimes	return HEIM_EAI_MEMORY;
641541Srgrimes#if defined(EAI_NODATA) && EAI_NODATA != EAI_NONAME
651541Srgrimes    case EAI_NODATA:
661541Srgrimes	return HEIM_EAI_NODATA;
673124Sdg#endif
681541Srgrimes    case EAI_NONAME:
691541Srgrimes	return HEIM_EAI_NONAME;
70116182Sobrien    case EAI_SERVICE:
71116182Sobrien	return HEIM_EAI_SERVICE;
72116182Sobrien    case EAI_SOCKTYPE:
73106412Srwatson	return HEIM_EAI_SOCKTYPE;
74106412Srwatson    case EAI_SYSTEM:
751541Srgrimes	return system_error;
762807Sbde    default:
77155262Sjhb	return HEIM_EAI_UNKNOWN; /* XXX */
78155262Sjhb    }
79155262Sjhb}
80155431Sjhb
81172023Sddskrb5_error_code
8276166Smarkmkrb5_h_errno_to_heim_errno(int eai_errno)
83155262Sjhb{
8476166Smarkm    switch(eai_errno) {
85155262Sjhb    case 0:
86164033Srwatson	return 0;
871541Srgrimes    case HOST_NOT_FOUND:
88155262Sjhb	return HEIM_EAI_NONAME;
89155431Sjhb    case TRY_AGAIN:
90152328Srwatson	return HEIM_EAI_AGAIN;
91155262Sjhb    case NO_RECOVERY:
9222521Sdyson	return HEIM_EAI_FAIL;
93155262Sjhb    case NO_DATA:
94155262Sjhb	return HEIM_EAI_NONAME;
953124Sdg    default:
96155262Sjhb	return HEIM_EAI_UNKNOWN; /* XXX */
971541Srgrimes    }
98163606Srwatson}
99163606Srwatson