1 ; From GLIBC pre 2.2.1 CVS Repository
3 Index: inet/getnameinfo.c
4 ===================================================================
5 RCS file: /cvs/glibc/libc/inet/getnameinfo.c,v
6 retrieving revision 1.21
7 retrieving revision 1.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
15 + if (flags & ~(NI_NUMERICHOST|NI_NUMERICSERV|NI_NOFQDN|NI_NAMEREQD|NI_DGRAM))
16 + return EAI_BADFLAGS;
18 if (sa == NULL || addrlen < sizeof (sa_family_t))
22 switch (sa->sa_family)
25 if (addrlen < (socklen_t) (((struct sockaddr_un *) NULL)->sun_path))
30 if (addrlen < sizeof (struct sockaddr_in))
35 if (addrlen < sizeof (struct sockaddr_in6))
44 if (host != NULL && hostlen > 0)
47 __set_h_errno (herrno);
58 - if (flags & NI_NOFQDN)
60 + if ((flags & NI_NOFQDN) == 0
61 + && (c = nrl_domainname ())
62 + && (c = strstr (h->h_name, c))
63 + && (c != h->h_name) && (*(--c) == '.'))
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))]
74 - if ((c = nrl_domainname ()) && (c = strstr(h->h_name, c))
75 - && (c != h->h_name) && (*(--c) == '.'))
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))]
85 - strncpy (host, h->h_name, hostlen);
88 + strncpy (host, h->h_name, hostlen);
91 - strncpy (host, h->h_name, hostlen);
97 if (flags & NI_NAMEREQD)
105 @@ -295,40 +295,43 @@
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;
114 /* Buffer is >= IFNAMSIZ+1. */
115 char scopebuf[IFNAMSIZ + 1];
117 int ni_numericscope = 0;
118 + size_t real_hostlen = __strnlen (host, hostlen);
119 + size_t scopelen = 0;
121 + scopebuf[0] = SCOPE_DELIMITER;
122 + scopebuf[1] = '\0';
123 + scopeptr = &scopebuf[1];
125 if (IN6_IS_ADDR_LINKLOCAL (&sin6p->sin6_addr)
126 || IN6_IS_ADDR_MC_LINKLOCAL (&sin6p->sin6_addr))
128 - if (if_indextoname (scopeid, scopebuf) == NULL)
129 + if (if_indextoname (scopeid, scopeptr) == NULL)
132 + scopelen = strlen (scopebuf);
139 - char *scopeptr = &scopebuf[1];
140 - size_t real_hostlen;
143 - scopebuf[0] = SCOPE_DELIMITER;
144 - scopelen = 1 + __snprintf (scopeptr,
150 - real_hostlen = __strnlen (host, hostlen);
151 - if (real_hostlen + scopelen + 1 > hostlen)
153 - memcpy (host + real_hostlen, scopebuf, scopelen);
155 + scopelen = 1 + __snprintf (scopeptr,
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. */
165 + memcpy (host + real_hostlen, scopebuf, scopelen + 1);
172 __set_errno (serrno);
178 @@ -360,14 +363,14 @@
179 if (flags & NI_NAMEREQD)
181 __set_errno (serrno);
186 strncpy (host, "localhost", hostlen);
194 if (serv && (servlen > 0))
198 __set_errno (serrno);
205 ===================================================================
206 RCS file: /cvs/glibc/libc/sysdeps/posix/getaddrinfo.c,v
207 retrieving revision 1.32
208 retrieving revision 1.34
209 diff -u -r1.32 -r1.34
210 --- libc/sysdeps/posix/getaddrinfo.c 2000/09/29 05:27:20 1.32
211 +++ libc/sysdeps/posix/getaddrinfo.c 2000/11/18 08:30:02 1.34
214 /* Values for `protoflag'. */
215 #define GAI_PROTO_NOSERVICE 1
216 +#define GAI_PROTO_PROTOANY 2
218 static struct gaih_typeproto gaih_inet_typeproto[] =
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 },
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)))
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)
244 size_t tmpbuflen = 1024;
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;
262 tmpbuf = __alloca (tmpbuflen); \
263 @@ -282,17 +286,18 @@
264 return -EAI_SYSTEM; \
266 if (herrno == TRY_AGAIN) \
268 - __set_h_errno (herrno); \
269 - return -EAI_AGAIN; \
271 + no_data = EAI_AGAIN; \
273 + no_data = herrno == NO_DATA; \
276 + else if (h != NULL) \
278 for (i = 0; h->h_addr_list[i]; i++) \
280 - if (*pat == NULL) \
281 + if (*pat == NULL) { \
282 *pat = __alloca (sizeof(struct gaih_addrtuple)); \
283 + (*pat)->scopeid = 0; \
285 (*pat)->next = NULL; \
286 (*pat)->family = _family; \
287 memcpy ((*pat)->addr, h->h_addr_list[i], \
289 pat = &((*pat)->next); \
292 - no_data = rc != 0 && herrno == NO_DATA; \
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)))
305 st = (struct gaih_servtuple *)
306 __alloca (sizeof (struct gaih_servtuple));
308 - if ((rc = gaih_inet_serv (service->name, tp, st)))
309 + if ((rc = gaih_inet_serv (service->name, tp, req, st)))
313 @@ -359,11 +364,15 @@
314 if (req->ai_socktype != 0
315 && req->ai_socktype != tp->socktype)
317 + if (req->ai_protocol != 0
318 + && !(tp->protoflag & GAI_PROTO_PROTOANY)
319 + && req->ai_protocol != tp->protocol)
322 newp = (struct gaih_servtuple *)
323 __alloca (sizeof (struct gaih_servtuple));
325 - if ((rc = gaih_inet_serv (service->name, tp, newp)))
326 + if ((rc = gaih_inet_serv (service->name, tp, req, newp)))
328 if (rc & GAIH_OKIFUNSPEC)
331 st = __alloca (sizeof (struct gaih_servtuple));
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);
342 st = __alloca (sizeof (struct gaih_servtuple));
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);
353 gethosts (AF_INET, struct in_addr);
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);
360 + /* If both requests timed out report this. */
361 + if (no_data == EAI_AGAIN && no_inet6_data == EAI_AGAIN)
364 + /* We made requests but they turned out no data. The name
365 + is known, though. */
366 + return (GAIH_OKIFUNSPEC | -EAI_NODATA);
370 if (at->family == AF_UNSPEC)
372 struct gaih_servtuple *st2;
373 struct gaih_addrtuple *at2 = at;
374 size_t socklen, namelen;
375 + sa_family_t family;
378 buffer is the size of an unformatted IPv6 address in printable format.
382 if (at2->family == AF_INET6)
383 - socklen = sizeof (struct sockaddr_in6);
386 + socklen = sizeof (struct sockaddr_in6);
389 - socklen = sizeof (struct sockaddr_in);
392 + socklen = sizeof (struct sockaddr_in);
395 for (st2 = st; st2 != NULL; st2 = st2->next)
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;
408 (*pai)->ai_addr->sa_len = socklen;
410 - (*pai)->ai_addr->sa_family = at2->family;
411 + (*pai)->ai_addr->sa_family = family;
413 - if (at2->family == AF_INET6)
414 + if (family == AF_INET6)
416 struct sockaddr_in6 *sin6p =
417 (struct sockaddr_in6 *) (*pai)->ai_addr;
420 /* Can't specify a numerical socket unless a protocol family was
422 - if (hints->ai_socktype == 0)
423 + if (hints->ai_socktype == 0 && hints->ai_protocol == 0)
425 pservice = &gaih_service;