1 /** @file 2 Copyright (c) 2011, Intel Corporation. All rights reserved.<BR> 3 This program and the accompanying materials are licensed and made available under 4 the terms and conditions of the BSD License that accompanies this distribution. 5 The full text of the license may be found at 6 http://opensource.org/licenses/bsd-license. 7 8 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 9 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 10 11 * Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project. 12 * All rights reserved. 13 * 14 * Redistribution and use in source and binary forms, with or without 15 * modification, are permitted provided that the following conditions 16 * are met: 17 * 1. Redistributions of source code must retain the above copyright 18 * notice, this list of conditions and the following disclaimer. 19 * 2. Redistributions in binary form must reproduce the above copyright 20 * notice, this list of conditions and the following disclaimer in the 21 * documentation and/or other materials provided with the distribution. 22 * 3. Neither the name of the project nor the names of its contributors 23 * may be used to endorse or promote products derived from this software 24 * without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 * SUCH DAMAGE. 37 **/ 38 39 #ifndef HAVE_GETADDRINFO 40 41 /* 42 * Error return codes from getaddrinfo() 43 */ 44 #ifdef EAI_ADDRFAMILY 45 /* If this is defined, there is a conflicting implementation 46 in the C library, which can't be used for some reason. 47 Make sure it won't interfere with this emulation. */ 48 49 #undef EAI_ADDRFAMILY 50 #undef EAI_AGAIN 51 #undef EAI_BADFLAGS 52 #undef EAI_FAIL 53 #undef EAI_FAMILY 54 #undef EAI_MEMORY 55 #undef EAI_NODATA 56 #undef EAI_NONAME 57 #undef EAI_SERVICE 58 #undef EAI_SOCKTYPE 59 #undef EAI_SYSTEM 60 #undef EAI_BADHINTS 61 #undef EAI_PROTOCOL 62 #undef EAI_MAX 63 #undef getaddrinfo 64 #define getaddrinfo fake_getaddrinfo 65 #endif /* EAI_ADDRFAMILY */ 66 67 #define EAI_ADDRFAMILY 1 /* address family for hostname not supported */ 68 #define EAI_AGAIN 2 /* temporary failure in name resolution */ 69 #define EAI_BADFLAGS 3 /* invalid value for ai_flags */ 70 #define EAI_FAIL 4 /* non-recoverable failure in name resolution */ 71 #define EAI_FAMILY 5 /* ai_family not supported */ 72 #define EAI_MEMORY 6 /* memory allocation failure */ 73 #define EAI_NODATA 7 /* no address associated with hostname */ 74 #define EAI_NONAME 8 /* hostname nor servname provided, or not known */ 75 #define EAI_SERVICE 9 /* servname not supported for ai_socktype */ 76 #define EAI_SOCKTYPE 10 /* ai_socktype not supported */ 77 #define EAI_SYSTEM 11 /* system error returned in errno */ 78 #define EAI_BADHINTS 12 79 #define EAI_PROTOCOL 13 80 #define EAI_MAX 14 81 82 /* 83 * Flag values for getaddrinfo() 84 */ 85 #ifdef AI_PASSIVE 86 #undef AI_PASSIVE 87 #undef AI_CANONNAME 88 #undef AI_NUMERICHOST 89 #undef AI_MASK 90 #undef AI_ALL 91 #undef AI_V4MAPPED_CFG 92 #undef AI_ADDRCONFIG 93 #undef AI_V4MAPPED 94 #undef AI_DEFAULT 95 #endif /* AI_PASSIVE */ 96 97 #define AI_PASSIVE 0x00000001 /* get address to use bind() */ 98 #define AI_CANONNAME 0x00000002 /* fill ai_canonname */ 99 #define AI_NUMERICHOST 0x00000004 /* prevent name resolution */ 100 /* valid flags for addrinfo */ 101 #define AI_MASK (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST) 102 103 #define AI_ALL 0x00000100 /* IPv6 and IPv4-mapped (with AI_V4MAPPED) */ 104 #define AI_V4MAPPED_CFG 0x00000200 /* accept IPv4-mapped if kernel supports */ 105 #define AI_ADDRCONFIG 0x00000400 /* only if any address is assigned */ 106 #define AI_V4MAPPED 0x00000800 /* accept IPv4-mapped IPv6 address */ 107 /* special recommended flags for getipnodebyname */ 108 #define AI_DEFAULT (AI_V4MAPPED_CFG | AI_ADDRCONFIG) 109 110 #endif /* !HAVE_GETADDRINFO */ 111 112 #ifndef HAVE_GETNAMEINFO 113 114 /* 115 * Constants for getnameinfo() 116 */ 117 #ifndef NI_MAXHOST 118 #define NI_MAXHOST 1025 119 #define NI_MAXSERV 32 120 #endif /* !NI_MAXHOST */ 121 122 /* 123 * Flag values for getnameinfo() 124 */ 125 #ifndef NI_NOFQDN 126 #define NI_NOFQDN 0x00000001 127 #define NI_NUMERICHOST 0x00000002 128 #define NI_NAMEREQD 0x00000004 129 #define NI_NUMERICSERV 0x00000008 130 #define NI_DGRAM 0x00000010 131 #endif /* !NI_NOFQDN */ 132 133 #endif /* !HAVE_GETNAMEINFO */ 134 135 #ifndef _SYS_SOCKET_H_ 136 #ifndef HAVE_ADDRINFO 137 struct addrinfo { 138 int ai_flags; /* AI_PASSIVE, AI_CANONNAME */ 139 int ai_family; /* PF_xxx */ 140 int ai_socktype; /* SOCK_xxx */ 141 int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */ 142 size_t ai_addrlen; /* length of ai_addr */ 143 char *ai_canonname; /* canonical name for hostname */ 144 struct sockaddr *ai_addr; /* binary address */ 145 struct addrinfo *ai_next; /* next structure in linked list */ 146 }; 147 #endif /* !HAVE_ADDRINFO */ 148 149 #ifndef HAVE_SOCKADDR_STORAGE 150 /* 151 * RFC 2553: protocol-independent placeholder for socket addresses 152 */ 153 #define _SS_MAXSIZE 128 154 #ifdef HAVE_LONG_LONG 155 #define _SS_ALIGNSIZE (sizeof(PY_LONG_LONG)) 156 #else 157 #define _SS_ALIGNSIZE (sizeof(double)) 158 #endif /* HAVE_LONG_LONG */ 159 #define _SS_PAD1SIZE (_SS_ALIGNSIZE - sizeof(u_char) * 2) 160 #define _SS_PAD2SIZE (_SS_MAXSIZE - sizeof(u_char) * 2 - \ 161 _SS_PAD1SIZE - _SS_ALIGNSIZE) 162 163 struct sockaddr_storage { 164 #ifdef HAVE_SOCKADDR_SA_LEN 165 unsigned char ss_len; /* address length */ 166 unsigned char ss_family; /* address family */ 167 #else 168 unsigned short ss_family; /* address family */ 169 #endif /* HAVE_SOCKADDR_SA_LEN */ 170 char __ss_pad1[_SS_PAD1SIZE]; 171 #ifdef HAVE_LONG_LONG 172 PY_LONG_LONG __ss_align; /* force desired structure storage alignment */ 173 #else 174 double __ss_align; /* force desired structure storage alignment */ 175 #endif /* HAVE_LONG_LONG */ 176 char __ss_pad2[_SS_PAD2SIZE]; 177 }; 178 #endif /* !HAVE_SOCKADDR_STORAGE */ 179 #endif /* _SYS_SOCKET_H_ */ 180 181 #ifdef __cplusplus 182 extern "C" { 183 #endif 184 extern void freehostent Py_PROTO((struct hostent *)); 185 #ifdef __cplusplus 186 } 187 #endif 188