1481a5ccdes/* From openssh 4.3p2 filename openbsd-compat/fake-rfc2553.h */
2481a5ccdes/*
3481a5ccdes * Copyright (C) 2000-2003 Damien Miller.  All rights reserved.
4481a5ccdes * Copyright (C) 1999 WIDE Project.  All rights reserved.
5481a5ccdes *
6481a5ccdes * Redistribution and use in source and binary forms, with or without
7481a5ccdes * modification, are permitted provided that the following conditions
8481a5ccdes * are met:
9481a5ccdes * 1. Redistributions of source code must retain the above copyright
10481a5ccdes *    notice, this list of conditions and the following disclaimer.
11481a5ccdes * 2. Redistributions in binary form must reproduce the above copyright
12481a5ccdes *    notice, this list of conditions and the following disclaimer in the
13481a5ccdes *    documentation and/or other materials provided with the distribution.
14481a5ccdes * 3. Neither the name of the project nor the names of its contributors
15481a5ccdes *    may be used to endorse or promote products derived from this software
16481a5ccdes *    without specific prior written permission.
17481a5ccdes *
18481a5ccdes * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
19481a5ccdes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20481a5ccdes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21481a5ccdes * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
22481a5ccdes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23481a5ccdes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24481a5ccdes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25481a5ccdes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26481a5ccdes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27481a5ccdes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28481a5ccdes * SUCH DAMAGE.
29481a5ccdes */
30481a5ccdes
31481a5ccdes/*
32481a5ccdes * Pseudo-implementation of RFC2553 name / address resolution functions
33481a5ccdes *
34481a5ccdes * But these functions are not implemented correctly. The minimum subset
35481a5ccdes * is implemented for ssh use only. For example, this routine assumes
36481a5ccdes * that ai_family is AF_INET. Don't use it for another purpose.
37481a5ccdes */
38481a5ccdes
39481a5ccdes#ifndef _FAKE_RFC2553_H
40481a5ccdes#define _FAKE_RFC2553_H
41481a5ccdes
42481a5ccdes#include <sys/types.h>
43481a5ccdes#include <sys/socket.h>
44481a5ccdes#include <netdb.h>
45481a5ccdes#include <limits.h>
46481a5ccdes
47481a5ccdes#ifdef __cplusplus
48481a5ccdesextern "C" {
49481a5ccdes#endif
50481a5ccdes
51481a5ccdes/*
52481a5ccdes * First, socket and INET6 related definitions
53481a5ccdes */
54481a5ccdes#ifndef HAVE_STRUCT_SOCKADDR_STORAGE
55481a5ccdes#ifndef _SS_MAXSIZE
56481a5ccdes# define	_SS_MAXSIZE	128	/* Implementation specific max size */
57481a5ccdes# define       _SS_PADSIZE     (_SS_MAXSIZE - sizeof (struct sockaddr))
58481a5ccdesstruct sockaddr_storage {
59481a5ccdes	struct sockaddr	ss_sa;
60481a5ccdes	char		__ss_pad2[_SS_PADSIZE];
61481a5ccdes};
62481a5ccdes# define ss_family ss_sa.sa_family
63481a5ccdes#endif /* _SS_MAXSIZE */
64481a5ccdes#endif /* !HAVE_STRUCT_SOCKADDR_STORAGE */
65481a5ccdes
66481a5ccdes#ifndef IN6_IS_ADDR_LOOPBACK
67481a5ccdes# define IN6_IS_ADDR_LOOPBACK(a) \
68481a5ccdes	(((uint32_t *)(a))[0] == 0 && ((uint32_t *)(a))[1] == 0 && \
69481a5ccdes	 ((uint32_t *)(a))[2] == 0 && ((uint32_t *)(a))[3] == htonl(1))
70481a5ccdes#endif /* !IN6_IS_ADDR_LOOPBACK */
71481a5ccdes
72481a5ccdes#ifndef HAVE_STRUCT_IN6_ADDR
73481a5ccdesstruct in6_addr {
74481a5ccdes	uint8_t	s6_addr[16];
75481a5ccdes};
76481a5ccdes#endif /* !HAVE_STRUCT_IN6_ADDR */
77481a5ccdes
78481a5ccdes#ifndef HAVE_STRUCT_SOCKADDR_IN6
79481a5ccdesstruct sockaddr_in6 {
80481a5ccdes	unsigned short	sin6_family;
81481a5ccdes	uint16_t	sin6_port;
82481a5ccdes	uint32_t	sin6_flowinfo;
83481a5ccdes	struct in6_addr	sin6_addr;
84481a5ccdes};
85481a5ccdes#endif /* !HAVE_STRUCT_SOCKADDR_IN6 */
86481a5ccdes
87481a5ccdes#ifndef AF_INET6
88481a5ccdes/* Define it to something that should never appear */
89481a5ccdes#define AF_INET6 AF_MAX
90481a5ccdes#endif
91481a5ccdes
92481a5ccdes/*
93481a5ccdes * Next, RFC2553 name / address resolution API
94481a5ccdes */
95481a5ccdes
96481a5ccdes#ifndef NI_NUMERICHOST
97481a5ccdes# define NI_NUMERICHOST    (1)
98481a5ccdes#endif
99481a5ccdes#ifndef NI_NAMEREQD
100481a5ccdes# define NI_NAMEREQD       (1<<1)
101481a5ccdes#endif
102481a5ccdes#ifndef NI_NUMERICSERV
103481a5ccdes# define NI_NUMERICSERV    (1<<2)
104481a5ccdes#endif
105481a5ccdes
106481a5ccdes#ifndef AI_PASSIVE
107481a5ccdes# define AI_PASSIVE		(1)
108481a5ccdes#endif
109481a5ccdes#ifndef AI_CANONNAME
110481a5ccdes# define AI_CANONNAME		(1<<1)
111481a5ccdes#endif
112481a5ccdes#ifndef AI_NUMERICHOST
113481a5ccdes# define AI_NUMERICHOST		(1<<2)
114481a5ccdes#endif
115481a5ccdes
116481a5ccdes#ifndef NI_MAXSERV
117481a5ccdes# define NI_MAXSERV 32
118481a5ccdes#endif /* !NI_MAXSERV */
119481a5ccdes#ifndef NI_MAXHOST
120481a5ccdes# define NI_MAXHOST 1025
121481a5ccdes#endif /* !NI_MAXHOST */
122481a5ccdes
123481a5ccdes#ifndef INT_MAX
124481a5ccdes#define INT_MAX		0xffffffff
125481a5ccdes#endif
126481a5ccdes
127481a5ccdes#ifndef EAI_NODATA
128481a5ccdes# define EAI_NODATA	(INT_MAX - 1)
129481a5ccdes#endif
130481a5ccdes#ifndef EAI_MEMORY
131481a5ccdes# define EAI_MEMORY	(INT_MAX - 2)
132481a5ccdes#endif
133481a5ccdes#ifndef EAI_NONAME
134481a5ccdes# define EAI_NONAME	(INT_MAX - 3)
135481a5ccdes#endif
136481a5ccdes#ifndef EAI_SYSTEM
137481a5ccdes# define EAI_SYSTEM	(INT_MAX - 4)
138481a5ccdes#endif
139481a5ccdes
140481a5ccdes#ifndef HAVE_STRUCT_ADDRINFO
141481a5ccdesstruct addrinfo {
142481a5ccdes	int	ai_flags;	/* AI_PASSIVE, AI_CANONNAME */
143481a5ccdes	int	ai_family;	/* PF_xxx */
144481a5ccdes	int	ai_socktype;	/* SOCK_xxx */
145481a5ccdes	int	ai_protocol;	/* 0 or IPPROTO_xxx for IPv4 and IPv6 */
146481a5ccdes	size_t	ai_addrlen;	/* length of ai_addr */
147481a5ccdes	char	*ai_canonname;	/* canonical name for hostname */
148481a5ccdes	struct sockaddr *ai_addr;	/* binary address */
149481a5ccdes	struct addrinfo *ai_next;	/* next structure in linked list */
150481a5ccdes};
151481a5ccdes#endif /* !HAVE_STRUCT_ADDRINFO */
152481a5ccdes
153481a5ccdes#ifndef HAVE_GETADDRINFO
154481a5ccdes#ifdef getaddrinfo
155481a5ccdes# undef getaddrinfo
156481a5ccdes#endif
157481a5ccdes#define getaddrinfo(a,b,c,d)	(ssh_getaddrinfo(a,b,c,d))
158481a5ccdesint getaddrinfo(const char *, const char *,
159481a5ccdes    const struct addrinfo *, struct addrinfo **);
160481a5ccdes#endif /* !HAVE_GETADDRINFO */
161481a5ccdes
162481a5ccdes#if !defined(HAVE_GAI_STRERROR) && !defined(HAVE_CONST_GAI_STRERROR_PROTO)
163481a5ccdes#define gai_strerror(a)		(ssh_gai_strerror(a))
164481a5ccdeschar *gai_strerror(int);
165481a5ccdes#endif /* !HAVE_GAI_STRERROR */
166481a5ccdes
167481a5ccdes#ifndef HAVE_FREEADDRINFO
168481a5ccdes#define freeaddrinfo(a)		(ssh_freeaddrinfo(a))
169481a5ccdesvoid freeaddrinfo(struct addrinfo *);
170481a5ccdes#endif /* !HAVE_FREEADDRINFO */
171481a5ccdes
172481a5ccdes#ifndef HAVE_GETNAMEINFO
173481a5ccdes#define getnameinfo(a,b,c,d,e,f,g) (ssh_getnameinfo(a,b,c,d,e,f,g))
174481a5ccdesint getnameinfo(const struct sockaddr *, size_t, char *, size_t,
175481a5ccdes    char *, size_t, int);
176481a5ccdes#endif /* !HAVE_GETNAMEINFO */
177481a5ccdes
178481a5ccdes#ifdef __cplusplus
179481a5ccdes}
180481a5ccdes#endif
181481a5ccdes
182481a5ccdes#endif /* !_FAKE_RFC2553_H */
183481a5ccdes
184