Damien Miller | c28e38d | 2003-06-05 18:52:47 +1000 | [diff] [blame] | 1 | /* |
Damien Miller | 53950b6 | 2003-06-14 08:43:22 +1000 | [diff] [blame] | 2 | * Copyright (C) 2000-2003 Damien Miller. All rights reserved. |
| 3 | * Copyright (C) 1999 WIDE Project. All rights reserved. |
Darren Tucker | c20dccb | 2016-08-02 09:44:25 +1000 | [diff] [blame] | 4 | * |
Damien Miller | 53950b6 | 2003-06-14 08:43:22 +1000 | [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. |
Darren Tucker | c20dccb | 2016-08-02 09:44:25 +1000 | [diff] [blame] | 16 | * |
Damien Miller | 53950b6 | 2003-06-14 08:43:22 +1000 | [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 | /* |
Damien Miller | c28e38d | 2003-06-05 18:52:47 +1000 | [diff] [blame] | 31 | * Pseudo-implementation of RFC2553 name / address resolution functions |
| 32 | * |
| 33 | * But these functions are not implemented correctly. The minimum subset |
Darren Tucker | bc976f9 | 2003-06-11 23:56:41 +1000 | [diff] [blame] | 34 | * is implemented for ssh use only. For example, this routine assumes |
Damien Miller | c28e38d | 2003-06-05 18:52:47 +1000 | [diff] [blame] | 35 | * that ai_family is AF_INET. Don't use it for another purpose. |
| 36 | */ |
| 37 | |
Damien Miller | c28e38d | 2003-06-05 18:52:47 +1000 | [diff] [blame] | 38 | #ifndef _FAKE_RFC2553_H |
| 39 | #define _FAKE_RFC2553_H |
| 40 | |
| 41 | #include "includes.h" |
Damien Miller | be43ebf | 2006-07-24 13:51:51 +1000 | [diff] [blame] | 42 | #include <sys/types.h> |
| 43 | #if defined(HAVE_NETDB_H) |
| 44 | # include <netdb.h> |
| 45 | #endif |
Damien Miller | c28e38d | 2003-06-05 18:52:47 +1000 | [diff] [blame] | 46 | |
| 47 | /* |
Darren Tucker | c20dccb | 2016-08-02 09:44:25 +1000 | [diff] [blame] | 48 | * First, socket and INET6 related definitions |
Damien Miller | c28e38d | 2003-06-05 18:52:47 +1000 | [diff] [blame] | 49 | */ |
| 50 | #ifndef HAVE_STRUCT_SOCKADDR_STORAGE |
| 51 | # define _SS_MAXSIZE 128 /* Implementation specific max size */ |
| 52 | # define _SS_PADSIZE (_SS_MAXSIZE - sizeof (struct sockaddr)) |
| 53 | struct sockaddr_storage { |
| 54 | struct sockaddr ss_sa; |
| 55 | char __ss_pad2[_SS_PADSIZE]; |
| 56 | }; |
| 57 | # define ss_family ss_sa.sa_family |
| 58 | #endif /* !HAVE_STRUCT_SOCKADDR_STORAGE */ |
| 59 | |
| 60 | #ifndef IN6_IS_ADDR_LOOPBACK |
| 61 | # define IN6_IS_ADDR_LOOPBACK(a) \ |
| 62 | (((u_int32_t *)(a))[0] == 0 && ((u_int32_t *)(a))[1] == 0 && \ |
| 63 | ((u_int32_t *)(a))[2] == 0 && ((u_int32_t *)(a))[3] == htonl(1)) |
| 64 | #endif /* !IN6_IS_ADDR_LOOPBACK */ |
| 65 | |
| 66 | #ifndef HAVE_STRUCT_IN6_ADDR |
| 67 | struct in6_addr { |
| 68 | u_int8_t s6_addr[16]; |
| 69 | }; |
| 70 | #endif /* !HAVE_STRUCT_IN6_ADDR */ |
| 71 | |
| 72 | #ifndef HAVE_STRUCT_SOCKADDR_IN6 |
| 73 | struct sockaddr_in6 { |
| 74 | unsigned short sin6_family; |
| 75 | u_int16_t sin6_port; |
| 76 | u_int32_t sin6_flowinfo; |
| 77 | struct in6_addr sin6_addr; |
Darren Tucker | 9d3739d | 2008-06-10 23:52:51 +1000 | [diff] [blame] | 78 | u_int32_t sin6_scope_id; |
Damien Miller | c28e38d | 2003-06-05 18:52:47 +1000 | [diff] [blame] | 79 | }; |
| 80 | #endif /* !HAVE_STRUCT_SOCKADDR_IN6 */ |
| 81 | |
| 82 | #ifndef AF_INET6 |
| 83 | /* Define it to something that should never appear */ |
| 84 | #define AF_INET6 AF_MAX |
| 85 | #endif |
| 86 | |
| 87 | /* |
| 88 | * Next, RFC2553 name / address resolution API |
| 89 | */ |
| 90 | |
| 91 | #ifndef NI_NUMERICHOST |
| 92 | # define NI_NUMERICHOST (1) |
Darren Tucker | 65914f1 | 2003-08-08 12:15:11 +1000 | [diff] [blame] | 93 | #endif |
| 94 | #ifndef NI_NAMEREQD |
Damien Miller | c28e38d | 2003-06-05 18:52:47 +1000 | [diff] [blame] | 95 | # define NI_NAMEREQD (1<<1) |
Darren Tucker | 65914f1 | 2003-08-08 12:15:11 +1000 | [diff] [blame] | 96 | #endif |
| 97 | #ifndef NI_NUMERICSERV |
Damien Miller | c28e38d | 2003-06-05 18:52:47 +1000 | [diff] [blame] | 98 | # define NI_NUMERICSERV (1<<2) |
| 99 | #endif |
Darren Tucker | 65914f1 | 2003-08-08 12:15:11 +1000 | [diff] [blame] | 100 | |
Damien Miller | c28e38d | 2003-06-05 18:52:47 +1000 | [diff] [blame] | 101 | #ifndef AI_PASSIVE |
| 102 | # define AI_PASSIVE (1) |
Darren Tucker | 65914f1 | 2003-08-08 12:15:11 +1000 | [diff] [blame] | 103 | #endif |
| 104 | #ifndef AI_CANONNAME |
Damien Miller | c28e38d | 2003-06-05 18:52:47 +1000 | [diff] [blame] | 105 | # define AI_CANONNAME (1<<1) |
Darren Tucker | 65914f1 | 2003-08-08 12:15:11 +1000 | [diff] [blame] | 106 | #endif |
| 107 | #ifndef AI_NUMERICHOST |
Damien Miller | c28e38d | 2003-06-05 18:52:47 +1000 | [diff] [blame] | 108 | # define AI_NUMERICHOST (1<<2) |
| 109 | #endif |
Darren Tucker | c9c8835 | 2015-02-24 13:43:57 +1100 | [diff] [blame] | 110 | #ifndef AI_NUMERICSERV |
| 111 | # define AI_NUMERICSERV (1<<3) |
| 112 | #endif |
Damien Miller | c28e38d | 2003-06-05 18:52:47 +1000 | [diff] [blame] | 113 | |
| 114 | #ifndef NI_MAXSERV |
| 115 | # define NI_MAXSERV 32 |
| 116 | #endif /* !NI_MAXSERV */ |
| 117 | #ifndef NI_MAXHOST |
| 118 | # define NI_MAXHOST 1025 |
| 119 | #endif /* !NI_MAXHOST */ |
| 120 | |
| 121 | #ifndef EAI_NODATA |
Darren Tucker | 9825697 | 2005-08-03 15:36:21 +1000 | [diff] [blame] | 122 | # define EAI_NODATA (INT_MAX - 1) |
Darren Tucker | 212cfc4 | 2005-08-03 10:57:15 +1000 | [diff] [blame] | 123 | #endif |
| 124 | #ifndef EAI_MEMORY |
Darren Tucker | 9825697 | 2005-08-03 15:36:21 +1000 | [diff] [blame] | 125 | # define EAI_MEMORY (INT_MAX - 2) |
Darren Tucker | 212cfc4 | 2005-08-03 10:57:15 +1000 | [diff] [blame] | 126 | #endif |
| 127 | #ifndef EAI_NONAME |
Darren Tucker | 9825697 | 2005-08-03 15:36:21 +1000 | [diff] [blame] | 128 | # define EAI_NONAME (INT_MAX - 3) |
Darren Tucker | 212cfc4 | 2005-08-03 10:57:15 +1000 | [diff] [blame] | 129 | #endif |
| 130 | #ifndef EAI_SYSTEM |
Darren Tucker | 9825697 | 2005-08-03 15:36:21 +1000 | [diff] [blame] | 131 | # define EAI_SYSTEM (INT_MAX - 4) |
Damien Miller | c28e38d | 2003-06-05 18:52:47 +1000 | [diff] [blame] | 132 | #endif |
Damien Miller | c4657ef | 2008-07-14 21:37:36 +1000 | [diff] [blame] | 133 | #ifndef EAI_FAMILY |
| 134 | # define EAI_FAMILY (INT_MAX - 5) |
| 135 | #endif |
Damien Miller | c28e38d | 2003-06-05 18:52:47 +1000 | [diff] [blame] | 136 | |
| 137 | #ifndef HAVE_STRUCT_ADDRINFO |
| 138 | struct addrinfo { |
| 139 | int ai_flags; /* AI_PASSIVE, AI_CANONNAME */ |
| 140 | int ai_family; /* PF_xxx */ |
| 141 | int ai_socktype; /* SOCK_xxx */ |
| 142 | int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */ |
| 143 | size_t ai_addrlen; /* length of ai_addr */ |
| 144 | char *ai_canonname; /* canonical name for hostname */ |
| 145 | struct sockaddr *ai_addr; /* binary address */ |
| 146 | struct addrinfo *ai_next; /* next structure in linked list */ |
| 147 | }; |
| 148 | #endif /* !HAVE_STRUCT_ADDRINFO */ |
| 149 | |
| 150 | #ifndef HAVE_GETADDRINFO |
Darren Tucker | 7c991ab | 2004-03-10 21:06:32 +1100 | [diff] [blame] | 151 | #ifdef getaddrinfo |
| 152 | # undef getaddrinfo |
| 153 | #endif |
Darren Tucker | ffae532 | 2004-02-10 13:05:40 +1100 | [diff] [blame] | 154 | #define getaddrinfo(a,b,c,d) (ssh_getaddrinfo(a,b,c,d)) |
Darren Tucker | c20dccb | 2016-08-02 09:44:25 +1000 | [diff] [blame] | 155 | int getaddrinfo(const char *, const char *, |
Damien Miller | c28e38d | 2003-06-05 18:52:47 +1000 | [diff] [blame] | 156 | const struct addrinfo *, struct addrinfo **); |
| 157 | #endif /* !HAVE_GETADDRINFO */ |
| 158 | |
Darren Tucker | d5e082f | 2003-09-22 12:08:23 +1000 | [diff] [blame] | 159 | #if !defined(HAVE_GAI_STRERROR) && !defined(HAVE_CONST_GAI_STRERROR_PROTO) |
Darren Tucker | 2c2ac03 | 2008-02-25 20:21:20 +1100 | [diff] [blame] | 160 | #define gai_strerror(a) (_ssh_compat_gai_strerror(a)) |
Damien Miller | c28e38d | 2003-06-05 18:52:47 +1000 | [diff] [blame] | 161 | char *gai_strerror(int); |
| 162 | #endif /* !HAVE_GAI_STRERROR */ |
| 163 | |
| 164 | #ifndef HAVE_FREEADDRINFO |
Darren Tucker | ffae532 | 2004-02-10 13:05:40 +1100 | [diff] [blame] | 165 | #define freeaddrinfo(a) (ssh_freeaddrinfo(a)) |
Damien Miller | c28e38d | 2003-06-05 18:52:47 +1000 | [diff] [blame] | 166 | void freeaddrinfo(struct addrinfo *); |
| 167 | #endif /* !HAVE_FREEADDRINFO */ |
| 168 | |
| 169 | #ifndef HAVE_GETNAMEINFO |
Darren Tucker | ffae532 | 2004-02-10 13:05:40 +1100 | [diff] [blame] | 170 | #define getnameinfo(a,b,c,d,e,f,g) (ssh_getnameinfo(a,b,c,d,e,f,g)) |
Darren Tucker | c20dccb | 2016-08-02 09:44:25 +1000 | [diff] [blame] | 171 | int getnameinfo(const struct sockaddr *, size_t, char *, size_t, |
Damien Miller | c28e38d | 2003-06-05 18:52:47 +1000 | [diff] [blame] | 172 | char *, size_t, int); |
| 173 | #endif /* !HAVE_GETNAMEINFO */ |
| 174 | |
| 175 | #endif /* !_FAKE_RFC2553_H */ |
| 176 | |