diff options
author | Ulrich Drepper <drepper@redhat.com> | 2002-10-17 21:51:21 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 2002-10-17 21:51:21 +0000 |
commit | 0420d8885a4889dca3b874c934fd5f42f2e99e5f (patch) | |
tree | dd8aecefe9a5f21d26df11cbc7f9c1dc6f2f5fd9 /resolv/gethnamaddr.c | |
parent | d025fe269abcab6903b3973d193a8678228301e8 (diff) | |
download | glibc-0420d8885a4889dca3b874c934fd5f42f2e99e5f.tar.gz glibc-0420d8885a4889dca3b874c934fd5f42f2e99e5f.tar.xz glibc-0420d8885a4889dca3b874c934fd5f42f2e99e5f.zip |
Update.
2002-10-15 Jakub Jelinek <jakub@redhat.com> * include/resolv.h (__libc_res_nquery, __libc_res_nsearch, __libc_res_nsend): New prototypes. * resolv/res_query.c (QUERYSIZE): Define. (__libc_res_nquery): Renamed from res_nquery. Added answerp argument. Allocate only QUERYSIZE bytes first, if res_nmkquery fails use MAXPACKET buffer. Call __libc_res_nsend instead of res_nsend, pass answerp. (res_nquery): Changed into wrapper around __libc_res_nquery. (__libc_res_nsearch): Renamed from res_nsearch. Added answerp argument. Call __libc_res_nquerydomain and __libc_res_nquery instead of the non-__libc_ variants, pass them answerp. (res_nsearch): Changed into wrapper around __libc_res_nsearch. (__libc_res_nquerydomain): Renamed from res_nquerydomain. Added answerp argument. Call __libc_res_nquery instead of res_nquery, pass answerp. (res_nquerydomain): Changed into wrapper around __libc_res_nquerydomain. * resolv/res_send.c: Include sys/ioctl.h. (MAXPACKET): Define. (send_vc): Change arguments. Reallocate answer buffer if it is too small. (send_dg): Likewise. (__libc_res_nsend): Renamed from res_nsend. Added ansp argument. Reallocate answer buffer if it is too small and hooks are in use. Adjust calls to send_vc and send_dg. (res_nsend): Changed into wrapper around __libc_res_nsend. * resolv/nss_dns/dns-host.c (_nss_dns_gethostbyname2_r): Allocate just 1K answer buffer on the stack, use __libc_res_nsearch instead of res_nsearch. (_nss_dns_gethostbyaddr_r): Similarly with __libc_res_nquery. * resolv/nss_dns/dns-network.c (_nss_dns_getnetbyaddr_r): Likewise. (_nss_dns_getnetbyname_r): Similarly with __libc_res_nsearch. * resolv/gethnamaddr.c (gethostbyname2): Likewise. (gethostbyaddr): Similarly with __libc_res_nquery. * resolv/Versions (libresolv): Export __libc_res_nquery and __libc_res_nsearch at GLIBC_PRIVATE.
Diffstat (limited to 'resolv/gethnamaddr.c')
-rw-r--r-- | resolv/gethnamaddr.c | 46 |
1 files changed, 18 insertions, 28 deletions
diff --git a/resolv/gethnamaddr.c b/resolv/gethnamaddr.c index 797af94874..e941b5c1ac 100644 --- a/resolv/gethnamaddr.c +++ b/resolv/gethnamaddr.c @@ -510,10 +510,10 @@ gethostbyname2(name, af) const char *name; int af; { - querybuf *buf; + querybuf *buf, *origbuf; register const char *cp; char *bp; - int n, size, type, len, use_malloc = 0; + int n, size, type, len; struct hostent *ret; extern struct hostent *_gethtbyname2(); @@ -616,24 +616,19 @@ gethostbyname2(name, af) break; } - if (!__libc_use_alloca (MAXPACKET)) { - buf = (querybuf *) malloc (sizeof (*buf)); - if (buf == NULL) { - __set_h_errno (NETDB_INTERNAL); - return NULL; - } - use_malloc = 1; - } else - buf = (querybuf *) alloca (sizeof (*buf)); + buf = origbuf = (querybuf *) alloca (1024); - if ((n = res_nsearch(&_res, name, C_IN, type, buf->buf, sizeof(buf->buf))) < 0) { + if ((n = __libc_res_nsearch(&_res, name, C_IN, type, buf->buf, 1024, + (u_char **) &buf)) < 0) { + if (buf != origbuf) + free (buf); dprintf("res_nsearch failed (%d)\n", n); if (errno == ECONNREFUSED) return (_gethtbyname2(name, af)); return (NULL); } ret = getanswer(buf, n, name, type); - if (use_malloc) + if (buf != origbuf) free (buf); return ret; } @@ -647,9 +642,9 @@ gethostbyaddr(addr, len, af) const u_char *uaddr = (const u_char *)addr; static const u_char mapped[] = { 0,0, 0,0, 0,0, 0,0, 0,0, 0xff,0xff }; static const u_char tunnelled[] = { 0,0, 0,0, 0,0, 0,0, 0,0, 0,0 }; - int n, use_malloc = 0; + int n; socklen_t size; - querybuf *buf; + querybuf *buf, *orig_buf; register struct hostent *hp; char qbuf[MAXDNAME+1], *qp = NULL; #ifdef SUNSECURITY @@ -711,23 +706,18 @@ gethostbyaddr(addr, len, af) abort(); } - if (!__libc_use_alloca (MAXPACKET)) { - buf = (querybuf *) malloc (sizeof (*buf)); - if (buf == NULL) { - __set_h_errno (NETDB_INTERNAL); - return NULL; - } - use_malloc = 1; - } else - buf = (querybuf *) alloca (sizeof (*buf)); + buf = orig_buf = (querybuf *) alloca (1024); - n = res_nquery(&_res, qbuf, C_IN, T_PTR, buf->buf, sizeof buf->buf); + n = __libc_res_nquery(&_res, qbuf, C_IN, T_PTR, buf->buf, 1024, + (u_char **) &buf); if (n < 0 && af == AF_INET6) { strcpy(qp, "ip6.int"); - n = res_nquery(&_res, qbuf, C_IN, T_PTR, buf->buf, sizeof buf->buf); + n = __libc_res_nquery(&_res, qbuf, C_IN, T_PTR, buf->buf, + buf != orig_buf ? MAXPACKET : 1024, + (u_char **) &buf); } if (n < 0) { - if (use_malloc) + if (buf != orig_buf) free (buf); dprintf("res_nquery failed (%d)\n", n); if (errno == ECONNREFUSED) @@ -735,7 +725,7 @@ gethostbyaddr(addr, len, af) return (NULL); } hp = getanswer(buf, n, qbuf, T_PTR); - if (use_malloc) + if (buf != orig_buf) free (buf); if (!hp) return (NULL); /* h_errno was set by getanswer() */ |