Debian Codegraph @

nbcompat/netdb.h

raw
1 /* $Id: netdb.h,v 1.1 2008/10/06 12:36:20 joerg Exp $ */
2
3 /*
4 * 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 /*
33 * Pseudo-implementation of RFC2553 name / address resolution functions
34 *
35 * But these functions are not implemented correctly. The minimum subset
36 * is implemented for ssh use only. For example, this routine assumes
37 * that ai_family is AF_INET. Don't use it for another purpose.
38 */
39
40 #ifndef _NBCOMPAT_NETDB_H
41 #define _NBCOMPAT_NETDB_H
42
43 #include <sys/types.h>
44 #if defined(HAVE_NETDB_H)
45 # include <netdb.h>
46 #endif
47 #if defined(HAVE_SYS_SOCKET_H)
48 # include <sys/socket.h>
49 #endif
50
51 /*
52 * First, socket and INET6 related definitions
53 */
54 #ifndef HAVE_STRUCT_SOCKADDR_STORAGE
55 # define _SS_MAXSIZE 128 /* Implementation specific max size */
56 # define _SS_PADSIZE (_SS_MAXSIZE - sizeof (struct sockaddr))
57 struct sockaddr_storage {
58 struct sockaddr ss_sa;
59 char __ss_pad2[_SS_PADSIZE];
60 };
61 # define ss_family ss_sa.sa_family
62 #endif /* !HAVE_STRUCT_SOCKADDR_STORAGE */
63
64 #ifndef IN6_IS_ADDR_LOOPBACK
65 # define IN6_IS_ADDR_LOOPBACK(a) \
66 (((uint32_t *)(a))[0] == 0 && ((uint32_t *)(a))[1] == 0 && \
67 ((uint32_t *)(a))[2] == 0 && ((uint32_t *)(a))[3] == htonl(1))
68 #endif /* !IN6_IS_ADDR_LOOPBACK */
69
70 #ifndef IN6_IS_ADDR_V4MAPPED
71 #define IN6_IS_ADDR_V4MAPPED(a) \
72 (((uint32_t *)(a))[0] == 0 && ((uint32_t *)(a))[1] == 0 && \
73 ((uint32_t *)(a))[2] == ntohl(0x0000ffff))
74 #endif
75
76 #ifndef INET6_ADDRSTRLEN
77 #define INET6_ADDRSTRLEN 46
78 #endif
79
80 #ifndef HAVE_SOCKLEN_T
81 typedef unsigned int socklen_t;
82 #endif
83
84 #ifndef HAVE_STRUCT_IN6_ADDR
85 struct in6_addr {
86 uint8_t s6_addr[16];
87 };
88 #endif /* !HAVE_STRUCT_IN6_ADDR */
89
90 #ifndef HAVE_STRUCT_SOCKADDR_IN6
91 struct sockaddr_in6 {
92 unsigned short sin6_family;
93 uint16_t sin6_port;
94 uint32_t sin6_flowinfo;
95 struct in6_addr sin6_addr;
96 uint32_t sin6_scope_id;
97 };
98 #endif /* !HAVE_STRUCT_SOCKADDR_IN6 */
99
100 #ifndef AF_INET6
101 /* Define it to something that should never appear */
102 #define AF_INET6 AF_MAX
103 #endif
104
105 /*
106 * Next, RFC2553 name / address resolution API
107 */
108
109 #ifndef NI_NUMERICHOST
110 # define NI_NUMERICHOST (1)
111 #endif
112 #ifndef NI_NAMEREQD
113 # define NI_NAMEREQD (1<<1)
114 #endif
115 #ifndef NI_NUMERICSERV
116 # define NI_NUMERICSERV (1<<2)
117 #endif
118
119 #ifndef AI_PASSIVE
120 # define AI_PASSIVE (1)
121 #endif
122 #ifndef AI_CANONNAME
123 # define AI_CANONNAME (1<<1)
124 #endif
125 #ifndef AI_NUMERICHOST
126 # define AI_NUMERICHOST (1<<2)
127 #endif
128
129 #ifndef NI_MAXSERV
130 # define NI_MAXSERV 32
131 #endif /* !NI_MAXSERV */
132 #ifndef NI_MAXHOST
133 # define NI_MAXHOST 1025
134 #endif /* !NI_MAXHOST */
135
136 #ifndef EAI_NODATA
137 # define EAI_NODATA (INT_MAX - 1)
138 #endif
139 #ifndef EAI_MEMORY
140 # define EAI_MEMORY (INT_MAX - 2)
141 #endif
142 #ifndef EAI_NONAME
143 # define EAI_NONAME (INT_MAX - 3)
144 #endif
145 #ifndef EAI_SYSTEM
146 # define EAI_SYSTEM (INT_MAX - 4)
147 #endif
148 #ifndef EAI_FAMILY
149 # define EAI_FAMILY (INT_MAX - 5)
150 #endif
151 #ifndef EAI_AGAIN
152 # define EAI_AGAIN (INT_MAX - 6)
153 #endif
154 #ifndef EAI_FAIL
155 # define EAI_FAIL (INT_MAX - 7)
156 #endif
157
158 #ifndef HAVE_STRUCT_ADDRINFO
159 struct addrinfo {
160 int ai_flags; /* AI_PASSIVE, AI_CANONNAME */
161 int ai_family; /* PF_xxx */
162 int ai_socktype; /* SOCK_xxx */
163 int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */
164 size_t ai_addrlen; /* length of ai_addr */
165 char *ai_canonname; /* canonical name for hostname */
166 struct sockaddr *ai_addr; /* binary address */
167 struct addrinfo *ai_next; /* next structure in linked list */
168 };
169 #endif /* !HAVE_STRUCT_ADDRINFO */
170
171 #ifndef HAVE_GETADDRINFO
172 void freeaddrinfo(struct addrinfo *);
173 int getaddrinfo(const char *, const char *,
174 const struct addrinfo *, struct addrinfo **);
175 #endif /* !HAVE_GETADDRINFO */
176
177 #if !defined(HAVE_GAI_STRERROR)
178 char *gai_strerror(int);
179 #endif /* !HAVE_GAI_STRERROR */
180
181 #ifndef HAVE_GETNAMEINFO
182 int getnameinfo(const struct sockaddr *, size_t, char *, size_t,
183 char *, size_t, int);
184 #endif /* !HAVE_GETNAMEINFO */
185
186 #endif /* !_FAKE_RFC2553_H */
187