getnameinfo/getaddrinfo nits
Roland McGrath
roland@frob.com
Fri Mar 24 11:15:00 GMT 2000
I needed these changes to compile 2.2 happily today.
Thanks,
Roland
2000-03-24 Roland McGrath <roland@baalperazim.frob.com>
* sysdeps/posix/getaddrinfo.c: Include <net/if.h> for if_nametoindex.
(gaih_inet): Remove unused duplicate variable.
* inet/getnameinfo.c (getnameinfo): Use IFNAMSIZ, not MAXHOSTNAMELEN.
Don't use __libc_sa_len, which only exists for Linux. Just handle
AF_INET and AF_INET6 directly as well as AF_LOCAL, since those are the
only flavors supported by this function anyway.
Index: sysdeps/posix/getaddrinfo.c
===================================================================
RCS file: /cvs/glibc/libc/sysdeps/posix/getaddrinfo.c,v
retrieving revision 1.26
diff -u -r1.26 getaddrinfo.c
--- sysdeps/posix/getaddrinfo.c 2000/03/23 21:21:39 1.26
+++ sysdeps/posix/getaddrinfo.c 2000/03/24 19:14:15
@@ -55,6 +55,7 @@
#include <sys/types.h>
#include <sys/un.h>
#include <sys/utsname.h>
+#include <net/if.h>
#define GAIH_OKIFUNSPEC 0x0100
#define GAIH_EAI ~(GAIH_OKIFUNSPEC)
@@ -392,8 +393,6 @@
if (inet_pton (AF_INET6, namebuf, at->addr) > 0)
{
- int try_numericscope = 0;
-
if (req->ai_family == AF_UNSPEC || req->ai_family == AF_INET6)
at->family = AF_INET6;
else
Index: inet/getnameinfo.c
===================================================================
RCS file: /cvs/glibc/libc/inet/getnameinfo.c,v
retrieving revision 1.17
diff -u -r1.17 getnameinfo.c
--- inet/getnameinfo.c 2000/03/23 21:27:49 1.17
+++ inet/getnameinfo.c 2000/03/24 19:14:14
@@ -173,7 +173,6 @@
int herrno;
char *tmpbuf = alloca (tmpbuflen);
struct hostent th;
- socklen_t min_addrlen = 0;
int ok = 0;
if (sa == NULL || addrlen < sizeof (sa_family_t))
@@ -182,16 +181,23 @@
switch (sa->sa_family)
{
case AF_LOCAL:
- min_addrlen = (socklen_t) (((struct sockaddr_un *) NULL)->sun_path);
+ if (addrlen < (socklen_t) (((struct sockaddr_un *) NULL)->sun_path))
+ return -1;
break;
+ case AF_INET:
+ if (addrlen < sizeof (struct sockaddr_in))
+ return -1;
+ break;
+ case AF_INET6:
+ if (addrlen < sizeof (struct sockaddr_in6))
+ return -1;
+ break;
default:
- min_addrlen = __libc_sa_len (sa->sa_family);
+ return -1;
}
- if (addrlen < min_addrlen)
- return -1;
if (host != NULL && hostlen > 0)
- switch(sa->sa_family)
+ switch (sa->sa_family)
{
case AF_INET:
case AF_INET6:
@@ -293,7 +299,7 @@
&& (scopeid = sin6p->sin6_scope_id))
{
/* Buffer is >= IFNAMSIZ+1. */
- char scopebuf[MAXHOSTNAMELEN + 1];
+ char scopebuf[IFNAMSIZ + 1];
int ni_numericscope = 0;
if (IN6_IS_ADDR_LINKLOCAL (&sin6p->sin6_addr)
@@ -365,7 +371,7 @@
}
if (serv && (servlen > 0))
- switch(sa->sa_family)
+ switch (sa->sa_family)
{
case AF_INET:
case AF_INET6:
More information about the Libc-hacker
mailing list