1181111Sdes/* $Id: fake-rfc2553.h,v 1.16 2008/07/14 11:37:37 djm Exp $ */ 2124208Sdes 3124208Sdes/* 4124208Sdes * Copyright (C) 2000-2003 Damien Miller. All rights reserved. 5124208Sdes * Copyright (C) 1999 WIDE Project. All rights reserved. 6124208Sdes * 7124208Sdes * Redistribution and use in source and binary forms, with or without 8124208Sdes * modification, are permitted provided that the following conditions 9124208Sdes * are met: 10124208Sdes * 1. Redistributions of source code must retain the above copyright 11124208Sdes * notice, this list of conditions and the following disclaimer. 12124208Sdes * 2. Redistributions in binary form must reproduce the above copyright 13124208Sdes * notice, this list of conditions and the following disclaimer in the 14124208Sdes * documentation and/or other materials provided with the distribution. 15124208Sdes * 3. Neither the name of the project nor the names of its contributors 16124208Sdes * may be used to endorse or promote products derived from this software 17124208Sdes * without specific prior written permission. 18124208Sdes * 19124208Sdes * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 20124208Sdes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21124208Sdes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22124208Sdes * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 23124208Sdes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24124208Sdes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25124208Sdes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26124208Sdes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27124208Sdes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28124208Sdes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29124208Sdes * SUCH DAMAGE. 30124208Sdes */ 31124208Sdes 32124208Sdes/* 33124208Sdes * Pseudo-implementation of RFC2553 name / address resolution functions 34124208Sdes * 35124208Sdes * But these functions are not implemented correctly. The minimum subset 36124208Sdes * is implemented for ssh use only. For example, this routine assumes 37124208Sdes * that ai_family is AF_INET. Don't use it for another purpose. 38124208Sdes */ 39124208Sdes 40124208Sdes#ifndef _FAKE_RFC2553_H 41124208Sdes#define _FAKE_RFC2553_H 42124208Sdes 43124208Sdes#include "includes.h" 44162856Sdes#include <sys/types.h> 45162856Sdes#if defined(HAVE_NETDB_H) 46162856Sdes# include <netdb.h> 47162856Sdes#endif 48124208Sdes 49124208Sdes/* 50124208Sdes * First, socket and INET6 related definitions 51124208Sdes */ 52124208Sdes#ifndef HAVE_STRUCT_SOCKADDR_STORAGE 53124208Sdes# define _SS_MAXSIZE 128 /* Implementation specific max size */ 54124208Sdes# define _SS_PADSIZE (_SS_MAXSIZE - sizeof (struct sockaddr)) 55124208Sdesstruct sockaddr_storage { 56124208Sdes struct sockaddr ss_sa; 57124208Sdes char __ss_pad2[_SS_PADSIZE]; 58124208Sdes}; 59124208Sdes# define ss_family ss_sa.sa_family 60124208Sdes#endif /* !HAVE_STRUCT_SOCKADDR_STORAGE */ 61124208Sdes 62124208Sdes#ifndef IN6_IS_ADDR_LOOPBACK 63124208Sdes# define IN6_IS_ADDR_LOOPBACK(a) \ 64124208Sdes (((u_int32_t *)(a))[0] == 0 && ((u_int32_t *)(a))[1] == 0 && \ 65124208Sdes ((u_int32_t *)(a))[2] == 0 && ((u_int32_t *)(a))[3] == htonl(1)) 66124208Sdes#endif /* !IN6_IS_ADDR_LOOPBACK */ 67124208Sdes 68124208Sdes#ifndef HAVE_STRUCT_IN6_ADDR 69124208Sdesstruct in6_addr { 70124208Sdes u_int8_t s6_addr[16]; 71124208Sdes}; 72124208Sdes#endif /* !HAVE_STRUCT_IN6_ADDR */ 73124208Sdes 74124208Sdes#ifndef HAVE_STRUCT_SOCKADDR_IN6 75124208Sdesstruct sockaddr_in6 { 76124208Sdes unsigned short sin6_family; 77124208Sdes u_int16_t sin6_port; 78124208Sdes u_int32_t sin6_flowinfo; 79124208Sdes struct in6_addr sin6_addr; 80181111Sdes u_int32_t sin6_scope_id; 81124208Sdes}; 82124208Sdes#endif /* !HAVE_STRUCT_SOCKADDR_IN6 */ 83124208Sdes 84124208Sdes#ifndef AF_INET6 85124208Sdes/* Define it to something that should never appear */ 86124208Sdes#define AF_INET6 AF_MAX 87124208Sdes#endif 88124208Sdes 89124208Sdes/* 90124208Sdes * Next, RFC2553 name / address resolution API 91124208Sdes */ 92124208Sdes 93124208Sdes#ifndef NI_NUMERICHOST 94124208Sdes# define NI_NUMERICHOST (1) 95124208Sdes#endif 96124208Sdes#ifndef NI_NAMEREQD 97124208Sdes# define NI_NAMEREQD (1<<1) 98124208Sdes#endif 99124208Sdes#ifndef NI_NUMERICSERV 100124208Sdes# define NI_NUMERICSERV (1<<2) 101124208Sdes#endif 102124208Sdes 103124208Sdes#ifndef AI_PASSIVE 104124208Sdes# define AI_PASSIVE (1) 105124208Sdes#endif 106124208Sdes#ifndef AI_CANONNAME 107124208Sdes# define AI_CANONNAME (1<<1) 108124208Sdes#endif 109124208Sdes#ifndef AI_NUMERICHOST 110124208Sdes# define AI_NUMERICHOST (1<<2) 111124208Sdes#endif 112124208Sdes 113124208Sdes#ifndef NI_MAXSERV 114124208Sdes# define NI_MAXSERV 32 115124208Sdes#endif /* !NI_MAXSERV */ 116124208Sdes#ifndef NI_MAXHOST 117124208Sdes# define NI_MAXHOST 1025 118124208Sdes#endif /* !NI_MAXHOST */ 119124208Sdes 120149753Sdes#ifndef EAI_NODATA 121149753Sdes# define EAI_NODATA (INT_MAX - 1) 122149753Sdes#endif 123149753Sdes#ifndef EAI_MEMORY 124149753Sdes# define EAI_MEMORY (INT_MAX - 2) 125149753Sdes#endif 126124696Sdes#ifndef EAI_NONAME 127149753Sdes# define EAI_NONAME (INT_MAX - 3) 128124208Sdes#endif 129149753Sdes#ifndef EAI_SYSTEM 130149753Sdes# define EAI_SYSTEM (INT_MAX - 4) 131149753Sdes#endif 132181111Sdes#ifndef EAI_FAMILY 133181111Sdes# define EAI_FAMILY (INT_MAX - 5) 134181111Sdes#endif 135124208Sdes 136124208Sdes#ifndef HAVE_STRUCT_ADDRINFO 137124208Sdesstruct addrinfo { 138124208Sdes int ai_flags; /* AI_PASSIVE, AI_CANONNAME */ 139124208Sdes int ai_family; /* PF_xxx */ 140124208Sdes int ai_socktype; /* SOCK_xxx */ 141124208Sdes int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */ 142124208Sdes size_t ai_addrlen; /* length of ai_addr */ 143124208Sdes char *ai_canonname; /* canonical name for hostname */ 144124208Sdes struct sockaddr *ai_addr; /* binary address */ 145124208Sdes struct addrinfo *ai_next; /* next structure in linked list */ 146124208Sdes}; 147124208Sdes#endif /* !HAVE_STRUCT_ADDRINFO */ 148124208Sdes 149124208Sdes#ifndef HAVE_GETADDRINFO 150128460Sdes#ifdef getaddrinfo 151128460Sdes# undef getaddrinfo 152128460Sdes#endif 153126277Sdes#define getaddrinfo(a,b,c,d) (ssh_getaddrinfo(a,b,c,d)) 154124208Sdesint getaddrinfo(const char *, const char *, 155124208Sdes const struct addrinfo *, struct addrinfo **); 156124208Sdes#endif /* !HAVE_GETADDRINFO */ 157124208Sdes 158124208Sdes#if !defined(HAVE_GAI_STRERROR) && !defined(HAVE_CONST_GAI_STRERROR_PROTO) 159181111Sdes#define gai_strerror(a) (_ssh_compat_gai_strerror(a)) 160124208Sdeschar *gai_strerror(int); 161124208Sdes#endif /* !HAVE_GAI_STRERROR */ 162124208Sdes 163124208Sdes#ifndef HAVE_FREEADDRINFO 164126277Sdes#define freeaddrinfo(a) (ssh_freeaddrinfo(a)) 165124208Sdesvoid freeaddrinfo(struct addrinfo *); 166124208Sdes#endif /* !HAVE_FREEADDRINFO */ 167124208Sdes 168124208Sdes#ifndef HAVE_GETNAMEINFO 169126277Sdes#define getnameinfo(a,b,c,d,e,f,g) (ssh_getnameinfo(a,b,c,d,e,f,g)) 170124208Sdesint getnameinfo(const struct sockaddr *, size_t, char *, size_t, 171124208Sdes char *, size_t, int); 172124208Sdes#endif /* !HAVE_GETNAMEINFO */ 173124208Sdes 174124208Sdes#endif /* !_FAKE_RFC2553_H */ 175124208Sdes 176