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