1 /* From openssh 4.3p2 filename openbsd-compat/fake-rfc2553.h */ 2 /* 3 * Copyright (C) 2000-2003 Damien Miller. All rights reserved. 4 * Copyright (C) 1999 WIDE Project. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 3. Neither the name of the project nor the names of its contributors 15 * may be used to endorse or promote products derived from this software 16 * without specific prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * SUCH DAMAGE. 29 */ 30 31 /* 32 * Pseudo-implementation of RFC2553 name / address resolution functions 33 * 34 * But these functions are not implemented correctly. The minimum subset 35 * is implemented for ssh use only. For example, this routine assumes 36 * that ai_family is AF_INET. Don't use it for another purpose. 37 */ 38 39 #ifndef _FAKE_RFC2553_H 40 #define _FAKE_RFC2553_H 41 42 #include <config.h> 43 #include <sys/types.h> 44 #include <sys/socket.h> 45 #include <netdb.h> 46 #include <limits.h> 47 48 /* 49 * First, socket and INET6 related definitions 50 */ 51 #ifndef HAVE_STRUCT_SOCKADDR_STORAGE 52 # define _SS_MAXSIZE 128 /* Implementation specific max size */ 53 # define _SS_PADSIZE (_SS_MAXSIZE - sizeof (struct sockaddr)) 54 struct sockaddr_storage { 55 struct sockaddr ss_sa; 56 char __ss_pad2[_SS_PADSIZE]; 57 }; 58 # define ss_family ss_sa.sa_family 59 #endif /* !HAVE_STRUCT_SOCKADDR_STORAGE */ 60 61 #ifndef IN6_IS_ADDR_LOOPBACK 62 # define IN6_IS_ADDR_LOOPBACK(a) \ 63 (((uint32_t *)(a))[0] == 0 && ((uint32_t *)(a))[1] == 0 && \ 64 ((uint32_t *)(a))[2] == 0 && ((uint32_t *)(a))[3] == htonl(1)) 65 #endif /* !IN6_IS_ADDR_LOOPBACK */ 66 67 #ifndef HAVE_STRUCT_IN6_ADDR 68 struct in6_addr { 69 uint8_t s6_addr[16]; 70 }; 71 #endif /* !HAVE_STRUCT_IN6_ADDR */ 72 73 #ifndef HAVE_STRUCT_SOCKADDR_IN6 74 struct sockaddr_in6 { 75 unsigned short sin6_family; 76 uint16_t sin6_port; 77 uint32_t sin6_flowinfo; 78 struct in6_addr sin6_addr; 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) 93 #endif 94 #ifndef NI_NAMEREQD 95 # define NI_NAMEREQD (1<<1) 96 #endif 97 #ifndef NI_NUMERICSERV 98 # define NI_NUMERICSERV (1<<2) 99 #endif 100 101 #ifndef AI_PASSIVE 102 # define AI_PASSIVE (1) 103 #endif 104 #ifndef AI_CANONNAME 105 # define AI_CANONNAME (1<<1) 106 #endif 107 #ifndef AI_NUMERICHOST 108 # define AI_NUMERICHOST (1<<2) 109 #endif 110 111 #ifndef NI_MAXSERV 112 # define NI_MAXSERV 32 113 #endif /* !NI_MAXSERV */ 114 #ifndef NI_MAXHOST 115 # define NI_MAXHOST 1025 116 #endif /* !NI_MAXHOST */ 117 118 #ifndef INT_MAX 119 #define INT_MAX 0xffffffff 120 #endif 121 122 #ifndef EAI_NODATA 123 # define EAI_NODATA (INT_MAX - 1) 124 #endif 125 #ifndef EAI_MEMORY 126 # define EAI_MEMORY (INT_MAX - 2) 127 #endif 128 #ifndef EAI_NONAME 129 # define EAI_NONAME (INT_MAX - 3) 130 #endif 131 #ifndef EAI_SYSTEM 132 # define EAI_SYSTEM (INT_MAX - 4) 133 #endif 134 135 #ifndef HAVE_STRUCT_ADDRINFO 136 struct addrinfo { 137 int ai_flags; /* AI_PASSIVE, AI_CANONNAME */ 138 int ai_family; /* PF_xxx */ 139 int ai_socktype; /* SOCK_xxx */ 140 int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */ 141 size_t ai_addrlen; /* length of ai_addr */ 142 char *ai_canonname; /* canonical name for hostname */ 143 struct sockaddr *ai_addr; /* binary address */ 144 struct addrinfo *ai_next; /* next structure in linked list */ 145 }; 146 #endif /* !HAVE_STRUCT_ADDRINFO */ 147 148 #ifndef HAVE_GETADDRINFO 149 #ifdef getaddrinfo 150 # undef getaddrinfo 151 #endif 152 #define getaddrinfo(a,b,c,d) (getaddrinfo_unbound(a,b,c,d)) 153 int getaddrinfo(const char *, const char *, 154 const struct addrinfo *, struct addrinfo **); 155 #endif /* !HAVE_GETADDRINFO */ 156 157 #if !defined(HAVE_GAI_STRERROR) && !defined(HAVE_CONST_GAI_STRERROR_PROTO) 158 #define gai_strerror(a) (gai_strerror_unbound(a)) 159 char *gai_strerror(int); 160 #endif /* !HAVE_GAI_STRERROR */ 161 162 #ifndef HAVE_FREEADDRINFO 163 #define freeaddrinfo(a) (freeaddrinfo_unbound(a)) 164 void freeaddrinfo(struct addrinfo *); 165 #endif /* !HAVE_FREEADDRINFO */ 166 167 #ifndef HAVE_GETNAMEINFO 168 #define getnameinfo(a,b,c,d,e,f,g) (getnameinfo_unbound(a,b,c,d,e,f,g)) 169 int getnameinfo(const struct sockaddr *, size_t, char *, size_t, 170 char *, size_t, int); 171 #endif /* !HAVE_GETNAMEINFO */ 172 173 #endif /* !_FAKE_RFC2553_H */ 174 175