blob: 6426f7bf6441ed965b82de42f33221fc5aeffd28 [file] [log] [blame]
Damien Millerc4657ef2008-07-14 21:37:36 +10001/* $Id: fake-rfc2553.h,v 1.16 2008/07/14 11:37:37 djm Exp $ */
Ben Lindstrom515d0f92003-08-29 16:59:52 +00002
Damien Millerc28e38d2003-06-05 18:52:47 +10003/*
Damien Miller53950b62003-06-14 08:43:22 +10004 * Copyright (C) 2000-2003 Damien Miller. All rights reserved.
5 * Copyright (C) 1999 WIDE Project. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the project nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31
32/*
Damien Millerc28e38d2003-06-05 18:52:47 +100033 * Pseudo-implementation of RFC2553 name / address resolution functions
34 *
35 * But these functions are not implemented correctly. The minimum subset
Darren Tuckerbc976f92003-06-11 23:56:41 +100036 * is implemented for ssh use only. For example, this routine assumes
Damien Millerc28e38d2003-06-05 18:52:47 +100037 * that ai_family is AF_INET. Don't use it for another purpose.
38 */
39
Damien Millerc28e38d2003-06-05 18:52:47 +100040#ifndef _FAKE_RFC2553_H
41#define _FAKE_RFC2553_H
42
43#include "includes.h"
Damien Millerbe43ebf2006-07-24 13:51:51 +100044#include <sys/types.h>
45#if defined(HAVE_NETDB_H)
46# include <netdb.h>
47#endif
Damien Millerc28e38d2003-06-05 18:52:47 +100048
49/*
50 * First, socket and INET6 related definitions
51 */
52#ifndef HAVE_STRUCT_SOCKADDR_STORAGE
53# define _SS_MAXSIZE 128 /* Implementation specific max size */
54# define _SS_PADSIZE (_SS_MAXSIZE - sizeof (struct sockaddr))
55struct sockaddr_storage {
56 struct sockaddr ss_sa;
57 char __ss_pad2[_SS_PADSIZE];
58};
59# define ss_family ss_sa.sa_family
60#endif /* !HAVE_STRUCT_SOCKADDR_STORAGE */
61
62#ifndef IN6_IS_ADDR_LOOPBACK
63# define IN6_IS_ADDR_LOOPBACK(a) \
64 (((u_int32_t *)(a))[0] == 0 && ((u_int32_t *)(a))[1] == 0 && \
65 ((u_int32_t *)(a))[2] == 0 && ((u_int32_t *)(a))[3] == htonl(1))
66#endif /* !IN6_IS_ADDR_LOOPBACK */
67
68#ifndef HAVE_STRUCT_IN6_ADDR
69struct in6_addr {
70 u_int8_t s6_addr[16];
71};
72#endif /* !HAVE_STRUCT_IN6_ADDR */
73
74#ifndef HAVE_STRUCT_SOCKADDR_IN6
75struct sockaddr_in6 {
76 unsigned short sin6_family;
77 u_int16_t sin6_port;
78 u_int32_t sin6_flowinfo;
79 struct in6_addr sin6_addr;
Darren Tucker9d3739d2008-06-10 23:52:51 +100080 u_int32_t sin6_scope_id;
Damien Millerc28e38d2003-06-05 18:52:47 +100081};
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)
Darren Tucker65914f12003-08-08 12:15:11 +100095#endif
96#ifndef NI_NAMEREQD
Damien Millerc28e38d2003-06-05 18:52:47 +100097# define NI_NAMEREQD (1<<1)
Darren Tucker65914f12003-08-08 12:15:11 +100098#endif
99#ifndef NI_NUMERICSERV
Damien Millerc28e38d2003-06-05 18:52:47 +1000100# define NI_NUMERICSERV (1<<2)
101#endif
Darren Tucker65914f12003-08-08 12:15:11 +1000102
Damien Millerc28e38d2003-06-05 18:52:47 +1000103#ifndef AI_PASSIVE
104# define AI_PASSIVE (1)
Darren Tucker65914f12003-08-08 12:15:11 +1000105#endif
106#ifndef AI_CANONNAME
Damien Millerc28e38d2003-06-05 18:52:47 +1000107# define AI_CANONNAME (1<<1)
Darren Tucker65914f12003-08-08 12:15:11 +1000108#endif
109#ifndef AI_NUMERICHOST
Damien Millerc28e38d2003-06-05 18:52:47 +1000110# define AI_NUMERICHOST (1<<2)
111#endif
Darren Tuckerc9c88352015-02-24 13:43:57 +1100112#ifndef AI_NUMERICSERV
113# define AI_NUMERICSERV (1<<3)
114#endif
Damien Millerc28e38d2003-06-05 18:52:47 +1000115
116#ifndef NI_MAXSERV
117# define NI_MAXSERV 32
118#endif /* !NI_MAXSERV */
119#ifndef NI_MAXHOST
120# define NI_MAXHOST 1025
121#endif /* !NI_MAXHOST */
122
123#ifndef EAI_NODATA
Darren Tucker98256972005-08-03 15:36:21 +1000124# define EAI_NODATA (INT_MAX - 1)
Darren Tucker212cfc42005-08-03 10:57:15 +1000125#endif
126#ifndef EAI_MEMORY
Darren Tucker98256972005-08-03 15:36:21 +1000127# define EAI_MEMORY (INT_MAX - 2)
Darren Tucker212cfc42005-08-03 10:57:15 +1000128#endif
129#ifndef EAI_NONAME
Darren Tucker98256972005-08-03 15:36:21 +1000130# define EAI_NONAME (INT_MAX - 3)
Darren Tucker212cfc42005-08-03 10:57:15 +1000131#endif
132#ifndef EAI_SYSTEM
Darren Tucker98256972005-08-03 15:36:21 +1000133# define EAI_SYSTEM (INT_MAX - 4)
Damien Millerc28e38d2003-06-05 18:52:47 +1000134#endif
Damien Millerc4657ef2008-07-14 21:37:36 +1000135#ifndef EAI_FAMILY
136# define EAI_FAMILY (INT_MAX - 5)
137#endif
Damien Millerc28e38d2003-06-05 18:52:47 +1000138
139#ifndef HAVE_STRUCT_ADDRINFO
140struct addrinfo {
141 int ai_flags; /* AI_PASSIVE, AI_CANONNAME */
142 int ai_family; /* PF_xxx */
143 int ai_socktype; /* SOCK_xxx */
144 int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */
145 size_t ai_addrlen; /* length of ai_addr */
146 char *ai_canonname; /* canonical name for hostname */
147 struct sockaddr *ai_addr; /* binary address */
148 struct addrinfo *ai_next; /* next structure in linked list */
149};
150#endif /* !HAVE_STRUCT_ADDRINFO */
151
152#ifndef HAVE_GETADDRINFO
Darren Tucker7c991ab2004-03-10 21:06:32 +1100153#ifdef getaddrinfo
154# undef getaddrinfo
155#endif
Darren Tuckerffae5322004-02-10 13:05:40 +1100156#define getaddrinfo(a,b,c,d) (ssh_getaddrinfo(a,b,c,d))
Damien Millerc28e38d2003-06-05 18:52:47 +1000157int getaddrinfo(const char *, const char *,
158 const struct addrinfo *, struct addrinfo **);
159#endif /* !HAVE_GETADDRINFO */
160
Darren Tuckerd5e082f2003-09-22 12:08:23 +1000161#if !defined(HAVE_GAI_STRERROR) && !defined(HAVE_CONST_GAI_STRERROR_PROTO)
Darren Tucker2c2ac032008-02-25 20:21:20 +1100162#define gai_strerror(a) (_ssh_compat_gai_strerror(a))
Damien Millerc28e38d2003-06-05 18:52:47 +1000163char *gai_strerror(int);
164#endif /* !HAVE_GAI_STRERROR */
165
166#ifndef HAVE_FREEADDRINFO
Darren Tuckerffae5322004-02-10 13:05:40 +1100167#define freeaddrinfo(a) (ssh_freeaddrinfo(a))
Damien Millerc28e38d2003-06-05 18:52:47 +1000168void freeaddrinfo(struct addrinfo *);
169#endif /* !HAVE_FREEADDRINFO */
170
171#ifndef HAVE_GETNAMEINFO
Darren Tuckerffae5322004-02-10 13:05:40 +1100172#define getnameinfo(a,b,c,d,e,f,g) (ssh_getnameinfo(a,b,c,d,e,f,g))
Damien Millerc28e38d2003-06-05 18:52:47 +1000173int getnameinfo(const struct sockaddr *, size_t, char *, size_t,
174 char *, size_t, int);
175#endif /* !HAVE_GETNAMEINFO */
176
177#endif /* !_FAKE_RFC2553_H */
178