Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-ports
Path: blob/main/japanese/FreeWnn-lib/files/patch-Wnn-etc-fake-rfc2553.c
18157 views
1
Index: Wnn/etc/fake-rfc2553.c
2
===================================================================
3
RCS file: Wnn/etc/fake-rfc2553.c
4
diff -N Wnn/etc/fake-rfc2553.c
5
--- /dev/null 1 Jan 1970 00:00:00 -0000
6
+++ Wnn/etc/fake-rfc2553.c 2 Jan 2009 21:09:34 -0000 1.1
7
@@ -0,0 +1,229 @@
8
+/*
9
+ * Copyright (C) 2000-2003 Damien Miller. All rights reserved.
10
+ * Copyright (C) 1999 WIDE Project. All rights reserved.
11
+ *
12
+ * Redistribution and use in source and binary forms, with or without
13
+ * modification, are permitted provided that the following conditions
14
+ * are met:
15
+ * 1. Redistributions of source code must retain the above copyright
16
+ * notice, this list of conditions and the following disclaimer.
17
+ * 2. Redistributions in binary form must reproduce the above copyright
18
+ * notice, this list of conditions and the following disclaimer in the
19
+ * documentation and/or other materials provided with the distribution.
20
+ * 3. Neither the name of the project nor the names of its contributors
21
+ * may be used to endorse or promote products derived from this software
22
+ * without specific prior written permission.
23
+ *
24
+ * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
25
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
28
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34
+ * SUCH DAMAGE.
35
+ */
36
+
37
+/*
38
+ * Pseudo-implementation of RFC2553 name / address resolution functions
39
+ *
40
+ * But these functions are not implemented correctly. The minimum subset
41
+ * is implemented for ssh use only. For example, this routine assumes
42
+ * that ai_family is AF_INET. Don't use it for another purpose.
43
+ */
44
+
45
+#include <stdlib.h>
46
+#include <string.h>
47
+
48
+#include <netinet/in.h>
49
+#include <arpa/inet.h>
50
+
51
+#include "config.h"
52
+#include "fake-rfc2553.h"
53
+
54
+#ifndef HAVE_GETNAMEINFO
55
+int getnameinfo(const struct sockaddr *sa, size_t salen, char *host,
56
+ size_t hostlen, char *serv, size_t servlen, int flags)
57
+{
58
+ struct sockaddr_in *sin = (struct sockaddr_in *)sa;
59
+ struct hostent *hp;
60
+ char tmpserv[16];
61
+
62
+ if (serv != NULL) {
63
+ snprintf(tmpserv, sizeof(tmpserv), "%d", ntohs(sin->sin_port));
64
+ if (strlcpy(serv, tmpserv, servlen) >= servlen)
65
+ return (EAI_MEMORY);
66
+ }
67
+
68
+ if (host != NULL) {
69
+ if (flags & NI_NUMERICHOST) {
70
+ if (strlcpy(host, inet_ntoa(sin->sin_addr),
71
+ hostlen) >= hostlen)
72
+ return (EAI_MEMORY);
73
+ else
74
+ return (0);
75
+ } else {
76
+ hp = gethostbyaddr((char *)&sin->sin_addr,
77
+ sizeof(struct in_addr), AF_INET);
78
+ if (hp == NULL)
79
+ return (EAI_NODATA);
80
+
81
+ if (strlcpy(host, hp->h_name, hostlen) >= hostlen)
82
+ return (EAI_MEMORY);
83
+ else
84
+ return (0);
85
+ }
86
+ }
87
+ return (0);
88
+}
89
+#endif /* !HAVE_GETNAMEINFO */
90
+
91
+#ifndef HAVE_GAI_STRERROR
92
+#ifdef HAVE_CONST_GAI_STRERROR_PROTO
93
+const char *
94
+#else
95
+char *
96
+#endif
97
+gai_strerror(int err)
98
+{
99
+ switch (err) {
100
+ case EAI_NODATA:
101
+ return ("no address associated with name");
102
+ case EAI_MEMORY:
103
+ return ("memory allocation failure.");
104
+ case EAI_NONAME:
105
+ return ("nodename nor servname provided, or not known");
106
+ default:
107
+ return ("unknown/invalid error.");
108
+ }
109
+}
110
+#endif /* !HAVE_GAI_STRERROR */
111
+
112
+#ifndef HAVE_FREEADDRINFO
113
+void
114
+freeaddrinfo(struct addrinfo *ai)
115
+{
116
+ struct addrinfo *next;
117
+
118
+ for(; ai != NULL;) {
119
+ next = ai->ai_next;
120
+ free(ai);
121
+ ai = next;
122
+ }
123
+}
124
+#endif /* !HAVE_FREEADDRINFO */
125
+
126
+#ifndef HAVE_GETADDRINFO
127
+static struct
128
+addrinfo *malloc_ai(int port, u_long addr, const struct addrinfo *hints)
129
+{
130
+ struct addrinfo *ai;
131
+
132
+ ai = malloc(sizeof(*ai) + sizeof(struct sockaddr_in));
133
+ if (ai == NULL)
134
+ return (NULL);
135
+
136
+ memset(ai, '\0', sizeof(*ai) + sizeof(struct sockaddr_in));
137
+
138
+ ai->ai_addr = (struct sockaddr *)(ai + 1);
139
+ /* XXX -- ssh doesn't use sa_len */
140
+ ai->ai_addrlen = sizeof(struct sockaddr_in);
141
+ ai->ai_addr->sa_family = ai->ai_family = AF_INET;
142
+
143
+ ((struct sockaddr_in *)(ai)->ai_addr)->sin_port = port;
144
+ ((struct sockaddr_in *)(ai)->ai_addr)->sin_addr.s_addr = addr;
145
+
146
+ /* XXX: the following is not generally correct, but does what we want */
147
+ if (hints->ai_socktype)
148
+ ai->ai_socktype = hints->ai_socktype;
149
+ else
150
+ ai->ai_socktype = SOCK_STREAM;
151
+
152
+ if (hints->ai_protocol)
153
+ ai->ai_protocol = hints->ai_protocol;
154
+
155
+ return (ai);
156
+}
157
+
158
+int
159
+getaddrinfo(const char *hostname, const char *servname,
160
+ const struct addrinfo *hints, struct addrinfo **res)
161
+{
162
+ struct hostent *hp;
163
+ struct servent *sp;
164
+ struct in_addr in;
165
+ int i;
166
+ long int port;
167
+ u_long addr;
168
+
169
+ port = 0;
170
+ if (servname != NULL) {
171
+ char *cp;
172
+
173
+ port = strtol(servname, &cp, 10);
174
+ if (port > 0 && port <= 65535 && *cp == '\0')
175
+ port = htons(port);
176
+ else if ((sp = getservbyname(servname, NULL)) != NULL)
177
+ port = sp->s_port;
178
+ else
179
+ port = 0;
180
+ }
181
+
182
+ if (hints && hints->ai_flags & AI_PASSIVE) {
183
+ addr = htonl(0x00000000);
184
+ if (hostname && inet_aton(hostname, &in) != 0)
185
+ addr = in.s_addr;
186
+ *res = malloc_ai(port, addr, hints);
187
+ if (*res == NULL)
188
+ return (EAI_MEMORY);
189
+ return (0);
190
+ }
191
+
192
+ if (!hostname) {
193
+ *res = malloc_ai(port, htonl(0x7f000001), hints);
194
+ if (*res == NULL)
195
+ return (EAI_MEMORY);
196
+ return (0);
197
+ }
198
+
199
+ if (inet_aton(hostname, &in)) {
200
+ *res = malloc_ai(port, in.s_addr, hints);
201
+ if (*res == NULL)
202
+ return (EAI_MEMORY);
203
+ return (0);
204
+ }
205
+
206
+ /* Don't try DNS if AI_NUMERICHOST is set */
207
+ if (hints && hints->ai_flags & AI_NUMERICHOST)
208
+ return (EAI_NONAME);
209
+
210
+ hp = gethostbyname(hostname);
211
+ if (hp && hp->h_name && hp->h_name[0] && hp->h_addr_list[0]) {
212
+ struct addrinfo *cur, *prev;
213
+
214
+ cur = prev = *res = NULL;
215
+ for (i = 0; hp->h_addr_list[i]; i++) {
216
+ struct in_addr *in = (struct in_addr *)hp->h_addr_list[i];
217
+
218
+ cur = malloc_ai(port, in->s_addr, hints);
219
+ if (cur == NULL) {
220
+ if (*res != NULL)
221
+ freeaddrinfo(*res);
222
+ return (EAI_MEMORY);
223
+ }
224
+ if (prev)
225
+ prev->ai_next = cur;
226
+ else
227
+ *res = cur;
228
+
229
+ prev = cur;
230
+ }
231
+ return (0);
232
+ }
233
+
234
+ return (EAI_NODATA);
235
+}
236
+#endif /* !HAVE_GETADDRINFO */
237
238