Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-1-6]: src/lib/libc/net Pull up revision 1.52 (requested by itojun...



details:   https://anonhg.NetBSD.org/src/rev/483697623270
branches:  netbsd-1-6
changeset: 529036:483697623270
user:      lukem <lukem%NetBSD.org@localhost>
date:      Tue Aug 27 09:23:26 2002 +0000

description:
Pull up revision 1.52 (requested by itojun in ticket #735):
allocate 64K recieve buffer for DNS responses.

diffstat:

 lib/libc/net/gethnamaddr.c |  42 ++++++++++++++++++++++++++----------------
 1 files changed, 26 insertions(+), 16 deletions(-)

diffs (105 lines):

diff -r 61c4abafad5f -r 483697623270 lib/libc/net/gethnamaddr.c
--- a/lib/libc/net/gethnamaddr.c        Tue Aug 27 09:03:02 2002 +0000
+++ b/lib/libc/net/gethnamaddr.c        Tue Aug 27 09:23:26 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: gethnamaddr.c,v 1.42.2.8 2002/08/24 02:57:20 lukem Exp $       */
+/*     $NetBSD: gethnamaddr.c,v 1.42.2.9 2002/08/27 09:23:26 lukem Exp $       */
 
 /*
  * ++Copyright++ 1985, 1988, 1993
@@ -61,7 +61,7 @@
 static char sccsid[] = "@(#)gethostnamadr.c    8.1 (Berkeley) 6/4/93";
 static char rcsid[] = "Id: gethnamaddr.c,v 8.21 1997/06/01 20:34:37 vixie Exp ";
 #else
-__RCSID("$NetBSD: gethnamaddr.c,v 1.42.2.8 2002/08/24 02:57:20 lukem Exp $");
+__RCSID("$NetBSD: gethnamaddr.c,v 1.42.2.9 2002/08/27 09:23:26 lukem Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -128,12 +128,7 @@
 static FILE *hostf = NULL;
 static int stayopen = 0;
 
-
-#if PACKETSZ > 1024
-#define        MAXPACKET       PACKETSZ
-#else
-#define        MAXPACKET       1024
-#endif
+#define        MAXPACKET       (64*1024)
 
 typedef union {
     HEADER hdr;
@@ -1130,7 +1125,7 @@
        void    *cb_data;
        va_list  ap;
 {
-       querybuf buf;
+       querybuf *buf;
        int n, type;
        struct hostent *hp;
        const char *name;
@@ -1152,11 +1147,19 @@
        default:
                return NS_UNAVAIL;
        }
-       if ((n = res_search(name, C_IN, type, buf.buf, sizeof(buf))) < 0) {
+       buf = malloc(sizeof(*buf));
+       if (buf == NULL) {
+               h_errno = NETDB_INTERNAL;
+               return NS_NOTFOUND;
+       }
+       n = res_search(name, C_IN, type, buf->buf, sizeof(buf->buf));
+       if (n < 0) {
+               free(buf);
                dprintf("res_search failed (%d)\n", n);
                return NS_NOTFOUND;
        }
-       hp = getanswer(&buf, n, name, type);
+       hp = getanswer(buf, n, name, type);
+       free(buf);
        if (hp == NULL)
                switch (h_errno) {
                case HOST_NOT_FOUND:
@@ -1179,7 +1182,7 @@
 {
        char qbuf[MAXDNAME + 1], *qp, *ep;
        int n;
-       querybuf buf;
+       querybuf *buf;
        struct hostent *hp;
        const unsigned char *uaddr;
        int len, af, advance;
@@ -1220,21 +1223,28 @@
                abort();
        }
 
-       n = res_query(qbuf, C_IN, T_PTR, (u_char *)(void *)&buf, sizeof(buf));
+       buf = malloc(sizeof(*buf));
+       if (buf == NULL) {
+               h_errno = NETDB_INTERNAL;
+               return NS_NOTFOUND;
+       }
+       n = res_query(qbuf, C_IN, T_PTR, buf->buf, sizeof(buf->buf));
        if (n < 0 && af == AF_INET6) {
                *qp = '\0';
                if (strlcat(qbuf, "ip6.int", sizeof(qbuf)) >= sizeof(qbuf)) {
+                       free(buf);
                        h_errno = NETDB_INTERNAL;
                        return NS_NOTFOUND;
                }
-               n = res_query(qbuf, C_IN, T_PTR, (u_char *)(void *)&buf,
-                   sizeof(buf));
+               n = res_query(qbuf, C_IN, T_PTR, buf->buf, sizeof(buf->buf));
        }
        if (n < 0) {
+               free(buf);
                dprintf("res_query failed (%d)\n", n);
                return NS_NOTFOUND;
        }
-       hp = getanswer(&buf, n, qbuf, T_PTR);
+       hp = getanswer(buf, n, qbuf, T_PTR);
+       free(buf);
        if (hp == NULL)
                switch (h_errno) {
                case HOST_NOT_FOUND:



Home | Main Index | Thread Index | Old Index