]> git.pld-linux.org Git - packages/glibc.git/blame - glibc-getxxxxinfo.patch
636b4b2b8b07e999d9582aa83f380f3c glibc-new-charsets.patch
[packages/glibc.git] / glibc-getxxxxinfo.patch
CommitLineData
c2f29537
AM
1; From GLIBC pre 2.2.1 CVS Repository
2;
3Index: inet/getnameinfo.c
4===================================================================
5RCS file: /cvs/glibc/libc/inet/getnameinfo.c,v
6retrieving revision 1.21
7retrieving revision 1.23
8diff -u -r1.21 -r1.23
9--- libc/inet/getnameinfo.c 2000/10/28 00:29:47 1.21
10+++ libc/inet/getnameinfo.c 2000/11/10 05:02:55 1.23
11@@ -175,25 +175,28 @@
12 struct hostent th;
13 int ok = 0;
14
15+ if (flags & ~(NI_NUMERICHOST|NI_NUMERICSERV|NI_NOFQDN|NI_NAMEREQD|NI_DGRAM))
16+ return EAI_BADFLAGS;
17+
18 if (sa == NULL || addrlen < sizeof (sa_family_t))
19- return -1;
20+ return EAI_FAMILY;
21
22 switch (sa->sa_family)
23 {
24 case AF_LOCAL:
25 if (addrlen < (socklen_t) (((struct sockaddr_un *) NULL)->sun_path))
26- return -1;
27+ return EAI_FAMILY;
28 break;
29 case AF_INET:
30 if (addrlen < sizeof (struct sockaddr_in))
31- return -1;
32+ return EAI_FAMILY;
33 break;
34 case AF_INET6:
35 if (addrlen < sizeof (struct sockaddr_in6))
36- return -1;
37+ return EAI_FAMILY;
38 break;
39 default:
40- return -1;
41+ return EAI_FAMILY;
42 }
43
44 if (host != NULL && hostlen > 0)
45@@ -224,7 +227,7 @@
46 {
47 __set_h_errno (herrno);
48 __set_errno (serrno);
49- return -1;
50+ return EAI_SYSTEM;
51 }
52 }
53 else
54@@ -255,26 +258,23 @@
55
56 if (h)
57 {
58- if (flags & NI_NOFQDN)
59+ char *c;
60+ if ((flags & NI_NOFQDN) == 0
61+ && (c = nrl_domainname ())
62+ && (c = strstr (h->h_name, c))
63+ && (c != h->h_name) && (*(--c) == '.'))
64+ {
65+ strncpy (host, h->h_name,
66+ min(hostlen, (size_t) (c - h->h_name)));
67+ host[min(hostlen - 1, (size_t) (c - h->h_name))]
68+ = '\0';
69+ ok = 1;
70+ }
71+ else
72 {
73- char *c;
74- if ((c = nrl_domainname ()) && (c = strstr(h->h_name, c))
75- && (c != h->h_name) && (*(--c) == '.'))
76- {
77- strncpy (host, h->h_name,
78- min(hostlen, (size_t) (c - h->h_name)));
79- host[min(hostlen - 1, (size_t) (c - h->h_name))]
80- = '\0';
81- ok = 1;
82- }
83- else
84- {
85- strncpy (host, h->h_name, hostlen);
86- ok = 1;
87- }
88+ strncpy (host, h->h_name, hostlen);
89+ ok = 1;
90 }
91- strncpy (host, h->h_name, hostlen);
92- ok = 1;
93 }
94 }
95
96@@ -283,7 +283,7 @@
97 if (flags & NI_NAMEREQD)
98 {
99 __set_errno (serrno);
100- return -1;
101+ return EAI_NONAME;
102 }
103 else
104 {
105@@ -295,40 +295,43 @@
106
107 c = inet_ntop (AF_INET6,
108 (void *) &sin6p->sin6_addr, host, hostlen);
109- if (addrlen > sizeof (struct sockaddr_in6)
110- && (scopeid = sin6p->sin6_scope_id))
111+ scopeid = sin6p->sin6_scope_id;
112+ if (scopeid != 0)
113 {
114 /* Buffer is >= IFNAMSIZ+1. */
115 char scopebuf[IFNAMSIZ + 1];
116+ char *scopeptr;
117 int ni_numericscope = 0;
118+ size_t real_hostlen = __strnlen (host, hostlen);
119+ size_t scopelen = 0;
120+
121+ scopebuf[0] = SCOPE_DELIMITER;
122+ scopebuf[1] = '\0';
123+ scopeptr = &scopebuf[1];
124
125 if (IN6_IS_ADDR_LINKLOCAL (&sin6p->sin6_addr)
126 || IN6_IS_ADDR_MC_LINKLOCAL (&sin6p->sin6_addr))
127 {
128- if (if_indextoname (scopeid, scopebuf) == NULL)
129+ if (if_indextoname (scopeid, scopeptr) == NULL)
130 ++ni_numericscope;
131+ else
132+ scopelen = strlen (scopebuf);
133 }
134 else
135 ++ni_numericscope;
136
137 if (ni_numericscope)
138- {
139- char *scopeptr = &scopebuf[1];
140- size_t real_hostlen;
141- size_t scopelen;
142-
143- scopebuf[0] = SCOPE_DELIMITER;
144- scopelen = 1 + __snprintf (scopeptr,
145- (scopebuf
146- + sizeof scopebuf
147- - scopeptr),
148- "%u", scopeid);
149-
150- real_hostlen = __strnlen (host, hostlen);
151- if (real_hostlen + scopelen + 1 > hostlen)
152- return -1;
153- memcpy (host + real_hostlen, scopebuf, scopelen);
154- }
155+ scopelen = 1 + __snprintf (scopeptr,
156+ (scopebuf
157+ + sizeof scopebuf
158+ - scopeptr),
159+ "%u", scopeid);
160+
161+ if (real_hostlen + scopelen + 1 > hostlen)
162+ /* XXX We should not fail here. Simply enlarge
163+ the buffer or return with out of memory. */
164+ return EAI_SYSTEM;
165+ memcpy (host + real_hostlen, scopebuf, scopelen + 1);
166 }
167 }
168 else
169@@ -338,7 +341,7 @@
170 if (c == NULL)
171 {
172 __set_errno (serrno);
173- return -1;
174+ return EAI_SYSTEM;
175 }
176 }
177 ok = 1;
178@@ -360,14 +363,14 @@
179 if (flags & NI_NAMEREQD)
180 {
181 __set_errno (serrno);
182- return -1;
183+ return EAI_NONAME;
184 }
185
186 strncpy (host, "localhost", hostlen);
187 break;
188
189 default:
190- return -1;
191+ return EAI_FAMILY;
192 }
193
194 if (serv && (servlen > 0))
195@@ -392,7 +395,7 @@
196 else
197 {
198 __set_errno (serrno);
199- return -1;
200+ return EAI_SYSTEM;
201 }
202 }
203 else
f2bfd795 204Index: getaddrinfo.c
c2f29537
AM
205===================================================================
206RCS file: /cvs/glibc/libc/sysdeps/posix/getaddrinfo.c,v
207retrieving revision 1.32
f2bfd795
AM
208retrieving revision 1.34
209diff -u -r1.32 -r1.34
c2f29537 210--- libc/sysdeps/posix/getaddrinfo.c 2000/09/29 05:27:20 1.32
f2bfd795 211+++ libc/sysdeps/posix/getaddrinfo.c 2000/11/18 08:30:02 1.34
c2f29537
AM
212@@ -99,13 +99,14 @@
213
214 /* Values for `protoflag'. */
215 #define GAI_PROTO_NOSERVICE 1
216+#define GAI_PROTO_PROTOANY 2
217
218 static struct gaih_typeproto gaih_inet_typeproto[] =
219 {
220 { 0, 0, NULL, 0 },
221 { SOCK_STREAM, IPPROTO_TCP, (char *) "tcp", 0 },
222 { SOCK_DGRAM, IPPROTO_UDP, (char *) "udp", 0 },
223- { SOCK_RAW, IPPROTO_RAW, (char *) "raw", GAI_PROTO_NOSERVICE },
224+ { SOCK_RAW, 0, (char *) "raw", GAI_PROTO_PROTOANY|GAI_PROTO_NOSERVICE },
225 { 0, 0, NULL, 0 }
226 };
227
228@@ -150,6 +151,7 @@
229 && ((tp->protoflag & GAI_PROTO_NOSERVICE) != 0
230 || (req->ai_socktype != 0 && req->ai_socktype != tp->socktype)
231 || (req->ai_protocol != 0
232+ && !(tp->protoflag & GAI_PROTO_PROTOANY)
233 && req->ai_protocol != tp->protocol)))
234 ++tp;
235
236@@ -229,7 +231,7 @@
237
238 static int
239 gaih_inet_serv (const char *servicename, struct gaih_typeproto *tp,
240- struct gaih_servtuple *st)
241+ const struct addrinfo *req, struct gaih_servtuple *st)
242 {
243 struct servent *s;
244 size_t tmpbuflen = 1024;
245@@ -255,7 +257,8 @@
246
247 st->next = NULL;
248 st->socktype = tp->socktype;
249- st->protocol = tp->protocol;
250+ st->protocol = ((tp->protoflag & GAI_PROTO_PROTOANY)
251+ ? req->ai_protocol : tp->protocol);
252 st->port = s->s_port;
253
254 return 0;
f2bfd795
AM
255@@ -268,6 +271,7 @@
256 struct hostent th; \
257 char *tmpbuf; \
258 tmpbuflen = 512; \
259+ no_data = 0; \
260 do { \
261 tmpbuflen *= 2; \
262 tmpbuf = __alloca (tmpbuflen); \
263@@ -282,17 +286,18 @@
264 return -EAI_SYSTEM; \
265 } \
266 if (herrno == TRY_AGAIN) \
267- { \
268- __set_h_errno (herrno); \
269- return -EAI_AGAIN; \
270- } \
271+ no_data = EAI_AGAIN; \
272+ else \
273+ no_data = herrno == NO_DATA; \
274 } \
275- if (h != NULL) \
276+ else if (h != NULL) \
c2f29537
AM
277 { \
278 for (i = 0; h->h_addr_list[i]; i++) \
279 { \
280- if (*pat == NULL) \
281+ if (*pat == NULL) { \
282 *pat = __alloca (sizeof(struct gaih_addrtuple)); \
283+ (*pat)->scopeid = 0; \
284+ } \
285 (*pat)->next = NULL; \
286 (*pat)->family = _family; \
287 memcpy ((*pat)->addr, h->h_addr_list[i], \
f2bfd795
AM
288@@ -300,7 +305,6 @@
289 pat = &((*pat)->next); \
290 } \
291 } \
292- no_data = rc != 0 && herrno == NO_DATA; \
293 }
294
295 static int
296@@ -319,6 +323,7 @@
c2f29537
AM
297 while (tp->name != NULL
298 && ((req->ai_socktype != 0 && req->ai_socktype != tp->socktype)
299 || (req->ai_protocol != 0
300+ && !(tp->protoflag & GAI_PROTO_PROTOANY)
301 && req->ai_protocol != tp->protocol)))
302 ++tp;
303
f2bfd795 304@@ -343,7 +348,7 @@
c2f29537
AM
305 st = (struct gaih_servtuple *)
306 __alloca (sizeof (struct gaih_servtuple));
307
308- if ((rc = gaih_inet_serv (service->name, tp, st)))
309+ if ((rc = gaih_inet_serv (service->name, tp, req, st)))
310 return rc;
311 }
312 else
f2bfd795 313@@ -359,11 +364,15 @@
c2f29537
AM
314 if (req->ai_socktype != 0
315 && req->ai_socktype != tp->socktype)
316 continue;
317+ if (req->ai_protocol != 0
318+ && !(tp->protoflag & GAI_PROTO_PROTOANY)
319+ && req->ai_protocol != tp->protocol)
320+ continue;
321
322 newp = (struct gaih_servtuple *)
323 __alloca (sizeof (struct gaih_servtuple));
324
325- if ((rc = gaih_inet_serv (service->name, tp, newp)))
326+ if ((rc = gaih_inet_serv (service->name, tp, req, newp)))
327 {
328 if (rc & GAIH_OKIFUNSPEC)
329 continue;
f2bfd795 330@@ -382,7 +391,8 @@
c2f29537
AM
331 st = __alloca (sizeof (struct gaih_servtuple));
332 st->next = NULL;
333 st->socktype = tp->socktype;
334- st->protocol = tp->protocol;
335+ st->protocol = ((tp->protoflag & GAI_PROTO_PROTOANY)
336+ ? req->ai_protocol : tp->protocol);
337 st->port = htons (service->num);
338 }
339 }
f2bfd795 340@@ -390,8 +400,9 @@
c2f29537
AM
341 {
342 st = __alloca (sizeof (struct gaih_servtuple));
343 st->next = NULL;
344- st->socktype = req->ai_socktype;
345- st->protocol = req->ai_protocol;
346+ st->socktype = tp->socktype;
347+ st->protocol = ((tp->protoflag & GAI_PROTO_PROTOANY)
348+ ? req->ai_protocol : tp->protocol);
349 st->port = 0;
350 }
351 else
f2bfd795
AM
352@@ -498,9 +509,15 @@
353 gethosts (AF_INET, struct in_addr);
354
355 if (no_data != 0 && no_inet6_data != 0)
356- /* We made requests but they turned out no data. The name
357- is known, though. */
358- return (GAIH_OKIFUNSPEC | -EAI_NODATA);
359+ {
360+ /* If both requests timed out report this. */
361+ if (no_data == EAI_AGAIN && no_inet6_data == EAI_AGAIN)
362+ return -EAI_AGAIN;
363+
364+ /* We made requests but they turned out no data. The name
365+ is known, though. */
366+ return (GAIH_OKIFUNSPEC | -EAI_NODATA);
367+ }
368 }
369
370 if (at->family == AF_UNSPEC)
371@@ -542,6 +559,7 @@
c2f29537
AM
372 struct gaih_servtuple *st2;
373 struct gaih_addrtuple *at2 = at;
374 size_t socklen, namelen;
375+ sa_family_t family;
376
377 /*
378 buffer is the size of an unformatted IPv6 address in printable format.
f2bfd795 379@@ -597,9 +615,15 @@
c2f29537
AM
380 namelen = 0;
381
382 if (at2->family == AF_INET6)
383- socklen = sizeof (struct sockaddr_in6);
384+ {
385+ family = AF_INET6;
386+ socklen = sizeof (struct sockaddr_in6);
387+ }
388 else
389- socklen = sizeof (struct sockaddr_in);
390+ {
391+ family = AF_INET;
392+ socklen = sizeof (struct sockaddr_in);
393+ }
394
395 for (st2 = st; st2 != NULL; st2 = st2->next)
396 {
f2bfd795 397@@ -608,7 +632,7 @@
c2f29537
AM
398 return -EAI_MEMORY;
399
400 (*pai)->ai_flags = req->ai_flags;
401- (*pai)->ai_family = at2->family;
402+ (*pai)->ai_family = family;
403 (*pai)->ai_socktype = st2->socktype;
404 (*pai)->ai_protocol = st2->protocol;
405 (*pai)->ai_addrlen = socklen;
f2bfd795 406@@ -616,9 +640,9 @@
c2f29537
AM
407 #if SALEN
408 (*pai)->ai_addr->sa_len = socklen;
409 #endif /* SALEN */
410- (*pai)->ai_addr->sa_family = at2->family;
411+ (*pai)->ai_addr->sa_family = family;
412
413- if (at2->family == AF_INET6)
414+ if (family == AF_INET6)
415 {
416 struct sockaddr_in6 *sin6p =
417 (struct sockaddr_in6 *) (*pai)->ai_addr;
f2bfd795 418@@ -703,7 +727,7 @@
c2f29537
AM
419 else
420 /* Can't specify a numerical socket unless a protocol family was
421 given. */
422- if (hints->ai_socktype == 0)
423+ if (hints->ai_socktype == 0 && hints->ai_protocol == 0)
424 return EAI_SERVICE;
425 pservice = &gaih_service;
426 }
427
This page took 0.084976 seconds and 4 git commands to generate.