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