1666aa9cdes/*
2666aa9cdes * Copyright (C) 2000-2003 Damien Miller.  All rights reserved.
3666aa9cdes * Copyright (C) 1999 WIDE Project.  All rights reserved.
4914a57cdes *
5666aa9cdes * Redistribution and use in source and binary forms, with or without
6666aa9cdes * modification, are permitted provided that the following conditions
7666aa9cdes * are met:
8666aa9cdes * 1. Redistributions of source code must retain the above copyright
9666aa9cdes *    notice, this list of conditions and the following disclaimer.
10666aa9cdes * 2. Redistributions in binary form must reproduce the above copyright
11666aa9cdes *    notice, this list of conditions and the following disclaimer in the
12666aa9cdes *    documentation and/or other materials provided with the distribution.
13666aa9cdes * 3. Neither the name of the project nor the names of its contributors
14666aa9cdes *    may be used to endorse or promote products derived from this software
15666aa9cdes *    without specific prior written permission.
16914a57cdes *
17666aa9cdes * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
18666aa9cdes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19666aa9cdes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20666aa9cdes * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
21666aa9cdes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22666aa9cdes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23666aa9cdes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24666aa9cdes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25666aa9cdes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26666aa9cdes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27666aa9cdes * SUCH DAMAGE.
28666aa9cdes */
29666aa9cdes
30666aa9cdes/*
31666aa9cdes * Pseudo-implementation of RFC2553 name / address resolution functions
32666aa9cdes *
33666aa9cdes * But these functions are not implemented correctly. The minimum subset
34666aa9cdes * is implemented for ssh use only. For example, this routine assumes
35666aa9cdes * that ai_family is AF_INET. Don't use it for another purpose.
36666aa9cdes */
37666aa9cdes
38666aa9cdes#ifndef _FAKE_RFC2553_H
39666aa9cdes#define _FAKE_RFC2553_H
40666aa9cdes
41666aa9cdes#include "includes.h"
42666aa9cdes#include <sys/types.h>
43666aa9cdes#if defined(HAVE_NETDB_H)
44666aa9cdes# include <netdb.h>
45666aa9cdes#endif
46666aa9cdes
47666aa9cdes/*
48914a57cdes * First, socket and INET6 related definitions
49666aa9cdes */
50666aa9cdes#ifndef HAVE_STRUCT_SOCKADDR_STORAGE
51666aa9cdes# define	_SS_MAXSIZE	128	/* Implementation specific max size */
52666aa9cdes# define       _SS_PADSIZE     (_SS_MAXSIZE - sizeof (struct sockaddr))
53666aa9cdesstruct sockaddr_storage {
54666aa9cdes	struct sockaddr	ss_sa;
55666aa9cdes	char		__ss_pad2[_SS_PADSIZE];
56666aa9cdes};
57666aa9cdes# define ss_family ss_sa.sa_family
58666aa9cdes#endif /* !HAVE_STRUCT_SOCKADDR_STORAGE */
59666aa9cdes
60666aa9cdes#ifndef IN6_IS_ADDR_LOOPBACK
61666aa9cdes# define IN6_IS_ADDR_LOOPBACK(a) \
62666aa9cdes	(((u_int32_t *)(a))[0] == 0 && ((u_int32_t *)(a))[1] == 0 && \
63666aa9cdes	 ((u_int32_t *)(a))[2] == 0 && ((u_int32_t *)(a))[3] == htonl(1))
64666aa9cdes#endif /* !IN6_IS_ADDR_LOOPBACK */
65666aa9cdes
66666aa9cdes#ifndef HAVE_STRUCT_IN6_ADDR
67666aa9cdesstruct in6_addr {
68666aa9cdes	u_int8_t	s6_addr[16];
69666aa9cdes};
70666aa9cdes#endif /* !HAVE_STRUCT_IN6_ADDR */
71666aa9cdes
72666aa9cdes#ifndef HAVE_STRUCT_SOCKADDR_IN6
73666aa9cdesstruct sockaddr_in6 {
74666aa9cdes	unsigned short	sin6_family;
75666aa9cdes	u_int16_t	sin6_port;
76666aa9cdes	u_int32_t	sin6_flowinfo;
77666aa9cdes	struct in6_addr	sin6_addr;
78f3e1deddes	u_int32_t	sin6_scope_id;
79666aa9cdes};
80666aa9cdes#endif /* !HAVE_STRUCT_SOCKADDR_IN6 */
81666aa9cdes
82666aa9cdes#ifndef AF_INET6
83666aa9cdes/* Define it to something that should never appear */
84666aa9cdes#define AF_INET6 AF_MAX
85666aa9cdes#endif
86666aa9cdes
87666aa9cdes/*
88666aa9cdes * Next, RFC2553 name / address resolution API
89666aa9cdes */
90666aa9cdes
91666aa9cdes#ifndef NI_NUMERICHOST
92666aa9cdes# define NI_NUMERICHOST    (1)
93666aa9cdes#endif
94666aa9cdes#ifndef NI_NAMEREQD
95666aa9cdes# define NI_NAMEREQD       (1<<1)
96666aa9cdes#endif
97666aa9cdes#ifndef NI_NUMERICSERV
98666aa9cdes# define NI_NUMERICSERV    (1<<2)
99666aa9cdes#endif
100666aa9cdes
101666aa9cdes#ifndef AI_PASSIVE
102666aa9cdes# define AI_PASSIVE		(1)
103666aa9cdes#endif
104666aa9cdes#ifndef AI_CANONNAME
105666aa9cdes# define AI_CANONNAME		(1<<1)
106666aa9cdes#endif
107666aa9cdes#ifndef AI_NUMERICHOST
108666aa9cdes# define AI_NUMERICHOST		(1<<2)
109666aa9cdes#endif
110928d872des#ifndef AI_NUMERICSERV
111928d872des# define AI_NUMERICSERV		(1<<3)
112928d872des#endif
113666aa9cdes
114666aa9cdes#ifndef NI_MAXSERV
115666aa9cdes# define NI_MAXSERV 32
116666aa9cdes#endif /* !NI_MAXSERV */
117666aa9cdes#ifndef NI_MAXHOST
118666aa9cdes# define NI_MAXHOST 1025
119666aa9cdes#endif /* !NI_MAXHOST */
120666aa9cdes
121666aa9cdes#ifndef EAI_NODATA
122666aa9cdes# define EAI_NODATA	(INT_MAX - 1)
123666aa9cdes#endif
124666aa9cdes#ifndef EAI_MEMORY
125666aa9cdes# define EAI_MEMORY	(INT_MAX - 2)
126666aa9cdes#endif
127666aa9cdes#ifndef EAI_NONAME
128666aa9cdes# define EAI_NONAME	(INT_MAX - 3)
129666aa9cdes#endif
130666aa9cdes#ifndef EAI_SYSTEM
131666aa9cdes# define EAI_SYSTEM	(INT_MAX - 4)
132666aa9cdes#endif
133f3e1deddes#ifndef EAI_FAMILY
134f3e1deddes# define EAI_FAMILY	(INT_MAX - 5)
135f3e1deddes#endif
136666aa9cdes
137666aa9cdes#ifndef HAVE_STRUCT_ADDRINFO
138666aa9cdesstruct addrinfo {
139666aa9cdes	int	ai_flags;	/* AI_PASSIVE, AI_CANONNAME */
140666aa9cdes	int	ai_family;	/* PF_xxx */
141666aa9cdes	int	ai_socktype;	/* SOCK_xxx */
142666aa9cdes	int	ai_protocol;	/* 0 or IPPROTO_xxx for IPv4 and IPv6 */
143666aa9cdes	size_t	ai_addrlen;	/* length of ai_addr */
144666aa9cdes	char	*ai_canonname;	/* canonical name for hostname */
145666aa9cdes	struct sockaddr *ai_addr;	/* binary address */
146666aa9cdes	struct addrinfo *ai_next;	/* next structure in linked list */
147666aa9cdes};
148666aa9cdes#endif /* !HAVE_STRUCT_ADDRINFO */
149666aa9cdes
150666aa9cdes#ifndef HAVE_GETADDRINFO
151666aa9cdes#ifdef getaddrinfo
152666aa9cdes# undef getaddrinfo
153666aa9cdes#endif
154666aa9cdes#define getaddrinfo(a,b,c,d)	(ssh_getaddrinfo(a,b,c,d))
155914a57cdesint getaddrinfo(const char *, const char *,
156666aa9cdes    const struct addrinfo *, struct addrinfo **);
157666aa9cdes#endif /* !HAVE_GETADDRINFO */
158666aa9cdes
159666aa9cdes#if !defined(HAVE_GAI_STRERROR) && !defined(HAVE_CONST_GAI_STRERROR_PROTO)
16058ec145des#define gai_strerror(a)		(_ssh_compat_gai_strerror(a))
161666aa9cdeschar *gai_strerror(int);
162666aa9cdes#endif /* !HAVE_GAI_STRERROR */
163666aa9cdes
164666aa9cdes#ifndef HAVE_FREEADDRINFO
165666aa9cdes#define freeaddrinfo(a)		(ssh_freeaddrinfo(a))
166666aa9cdesvoid freeaddrinfo(struct addrinfo *);
167666aa9cdes#endif /* !HAVE_FREEADDRINFO */
168666aa9cdes
169666aa9cdes#ifndef HAVE_GETNAMEINFO
170666aa9cdes#define getnameinfo(a,b,c,d,e,f,g) (ssh_getnameinfo(a,b,c,d,e,f,g))
171914a57cdesint getnameinfo(const struct sockaddr *, size_t, char *, size_t,
172666aa9cdes    char *, size_t, int);
173666aa9cdes#endif /* !HAVE_GETNAMEINFO */
174666aa9cdes
175666aa9cdes#endif /* !_FAKE_RFC2553_H */
176666aa9cdes
177