00001 /* 00002 * Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project. 00003 * All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions 00007 * are met: 00008 * 1. Redistributions of source code must retain the above copyright 00009 * notice, this list of conditions and the following disclaimer. 00010 * 2. Redistributions in binary form must reproduce the above copyright 00011 * notice, this list of conditions and the following disclaimer in the 00012 * documentation and/or other materials provided with the distribution. 00013 * 3. Neither the name of the project nor the names of its contributors 00014 * may be used to endorse or promote products derived from this software 00015 * without specific prior written permission. 00016 * 00017 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 00018 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00019 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00020 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 00021 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00022 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 00023 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00024 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00025 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00026 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00027 * SUCH DAMAGE. 00028 */ 00029 00030 #ifndef SU_ADDRINFO_H 00031 /* Defined when <sofia-sip/su_addrinfo.h> has been included */ 00032 #define SU_ADDRINFO_H 00033 00034 #ifndef SU_TYPES_H 00035 #include <sofia-sip/su_types.h> 00036 #endif 00037 00038 SOFIA_BEGIN_DECLS 00039 00040 #if !SU_HAVE_ADDRINFO 00041 /* 00042 * Error return codes from getaddrinfo() 00043 */ 00044 #ifndef EAI_ADDRFAMILY 00045 #define EAI_ADDRFAMILY 1 /* address family for hostname not supported */ 00046 #define EAI_AGAIN 2 /* temporary failure in name resolution */ 00047 #define EAI_BADFLAGS 3 /* invalid value for ai_flags */ 00048 #define EAI_FAIL 4 /* non-recoverable failure in name resolution */ 00049 #define EAI_FAMILY 5 /* ai_family not supported */ 00050 #define EAI_MEMORY 6 /* memory allocation failure */ 00051 #define EAI_NODATA 7 /* no address associated with hostname */ 00052 #define EAI_NONAME 8 /* hostname nor servname provided, or not known */ 00053 #define EAI_SERVICE 9 /* servname not supported for ai_socktype */ 00054 #define EAI_SOCKTYPE 10 /* ai_socktype not supported */ 00055 #define EAI_SYSTEM 11 /* system error returned in errno */ 00056 #define EAI_BADHINTS 12 00057 #define EAI_PROTOCOL 13 00058 #define EAI_MAX 14 00059 #endif 00060 00061 /* 00062 * Flag values for getaddrinfo() 00063 */ 00064 #ifndef AI_PASSIVE 00065 #define AI_PASSIVE 0x00000001 /* get address to use bind() */ 00066 #define AI_CANONNAME 0x00000002 /* fill ai_canonname */ 00067 #define AI_NUMERICHOST 0x00000004 /* prevent name resolution */ 00068 /* valid flags for addrinfo */ 00069 #define AI_MASK (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST) 00070 00071 #define AI_ALL 0x00000100 /* IPv6 and IPv4-mapped (with AI_V4MAPPED) */ 00072 #define AI_V4MAPPED_CFG 0x00000200 /* accept IPv4-mapped if kernel supports */ 00073 #define AI_ADDRCONFIG 0x00000400 /* only if any address is assigned */ 00074 #define AI_V4MAPPED 0x00000800 /* accept IPv4-mapped IPv6 address */ 00075 /* special recommended flags for getipnodebyname */ 00076 #define AI_DEFAULT (AI_V4MAPPED_CFG | AI_ADDRCONFIG) 00077 #endif 00078 00079 /* 00080 * Constants for getnameinfo() 00081 */ 00082 #ifndef NI_MAXHOST 00083 #define NI_MAXHOST 1025 00084 #define NI_MAXSERV 32 00085 #endif 00086 00087 /* 00088 * Flag values for getnameinfo() 00089 */ 00090 #ifndef NI_NOFQDN 00091 #define NI_NOFQDN 0x00000001 00092 #define NI_NUMERICHOST 0x00000002 00093 #define NI_NAMEREQD 0x00000004 00094 #define NI_NUMERICSERV 0x00000008 00095 #define NI_DGRAM 0x00000010 00096 #endif 00097 00098 struct addrinfo { 00099 int ai_flags; /* AI_PASSIVE, AI_CANONNAME */ 00100 int ai_family; /* PF_xxx */ 00101 int ai_socktype; /* SOCK_xxx */ 00102 int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */ 00103 size_t ai_addrlen; /* length of ai_addr */ 00104 char *ai_canonname; /* canonical name for hostname */ 00105 struct sockaddr *ai_addr; /* binary address */ 00106 struct addrinfo *ai_next; /* next structure in linked list */ 00107 }; 00108 #endif /* SU_WITH_GETADDRINFO */ 00109 00110 #ifndef EAI_BADHINTS 00111 #define EAI_BADHINTS 10012 00112 #endif 00113 #ifndef EAI_PROTOCOL 00114 #define EAI_PROTOCOL 10013 00115 #endif 00116 00117 #ifndef AI_MASK 00118 #define AI_MASK (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST) 00119 #endif 00120 00122 typedef struct addrinfo su_addrinfo_t; 00123 00125 SOFIAPUBFUN 00126 int su_getaddrinfo(char const *node, char const *service, 00127 su_addrinfo_t const *hints, 00128 su_addrinfo_t **res); 00130 SOFIAPUBFUN void su_freeaddrinfo(su_addrinfo_t *res); 00131 00133 SOFIAPUBFUN char const *su_gai_strerror(int errcode); 00134 00135 union su_sockaddr_u; 00136 00137 SOFIAPUBFUN 00138 int su_getnameinfo(const union su_sockaddr_u *su, size_t sulen, 00139 char *host, size_t hostlen, 00140 char *serv, size_t servlen, 00141 int flags); 00142 00143 SOFIA_END_DECLS 00144 00145 #endif /* !defined(SU_ADDRINFO_H) */