Source-Changes-HG archive

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

[src/netbsd-1-5]: src/dist/bind/bin Pull up revisions 1.5-1.6 (requested by i...



details:   https://anonhg.NetBSD.org/src/rev/e554f6972943
branches:  netbsd-1-5
changeset: 493179:e554f6972943
user:      he <he%NetBSD.org@localhost>
date:      Mon Jul 01 17:14:23 2002 +0000

description:
Pull up revisions 1.5-1.6 (requested by itojun):
  Update BIND to version 8.3.3.

diffstat:

 dist/bind/bin/host/host.c    |  423 +++++++++++++++++++++++++++++-------------
 dist/bind/bin/named/ns_ctl.c |  292 +++++++++++++++++++++++++----
 2 files changed, 532 insertions(+), 183 deletions(-)

diffs (truncated from 1337 to 300 lines):

diff -r c99d60de19dc -r e554f6972943 dist/bind/bin/host/host.c
--- a/dist/bind/bin/host/host.c Mon Jul 01 17:14:06 2002 +0000
+++ b/dist/bind/bin/host/host.c Mon Jul 01 17:14:23 2002 +0000
@@ -1,7 +1,7 @@
-/*     $NetBSD: host.c,v 1.2.8.3 2001/01/28 15:52:47 he Exp $  */
+/*     $NetBSD: host.c,v 1.2.8.4 2002/07/01 17:14:23 he Exp $  */
 
 #ifndef lint
-static const char rcsid[] = "Id: host.c,v 8.42 2000/12/23 08:14:32 vixie Exp";
+static const char rcsid[] = "Id: host.c,v 8.53 2002/06/18 02:34:02 marka Exp";
 #endif /* not lint */
 
 /*
@@ -102,7 +102,6 @@
 
 #include <ctype.h>
 #include <netdb.h>
-#include <resolv.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -115,10 +114,15 @@
 
 #include "port_after.h"
 
+#include <resolv.h>
+
 /* Global. */
 
+#ifndef PATH_SEP
+#define PATH_SEP '/'
+#endif
 #define SIG_RDATA_BY_NAME      18
-#define NS_HEADERDATA_SIZE 10
+#define NS_HEADERDATA_SIZE 10  /* type + class + ttl + rdlen */
 
 #define NUMNS          8
 #define NUMNSADDR      16
@@ -184,15 +188,14 @@
 
 static int             parsetype(const char *s);
 static int             parseclass(const char *s);
-static void            printanswer(const struct hostent *hp);
 static void            hperror(int errnum);
-static int             addrinfo(struct in_addr addr);
+static int             addrinfo(struct sockaddr_storage *addr);
 static int             gethostinfo(char *name);
 static int             getdomaininfo(const char *name, const char *domain);
 static int             getinfo(const char *name, const char *domain,
                                int type);
 static int             printinfo(const querybuf *answer, const u_char *eom,
-                                 int filter, int isls);
+                                 int filter, int isls, int isinaddr);
 static const u_char *  pr_rr(const u_char *cp, const u_char *msg, FILE *file,
                              int filter);
 static const char *    pr_type(int type);
@@ -224,16 +227,20 @@
 
 int
 main(int argc, char **argv) {
-       struct in_addr addr;
+       struct sockaddr_storage addr;
        struct hostent *hp;
        char *s;
        int waitmode = 0;
        int ncnames, ch;
        int nkeychains;
+       struct addrinfo *answer = NULL;
+       struct addrinfo *cur = NULL;
+       struct addrinfo hint;
+       int ip = 0;
 
        dst_init();
 
-       if ((progname = strrchr(argv[0], '/')) == NULL)
+       if ((progname = strrchr(argv[0], PATH_SEP)) == NULL)
                progname = argv[0];
        else
                progname++;
@@ -291,33 +298,93 @@
        if (argc > 1)
                usage("extra undefined arguments");
        if (argc == 1) {
+               union res_sockaddr_union u[MAXNS];
+               int nscount;
+
                s = *argv++;
                argc--;
                server_specified++;
+               memset(&hint, 0, sizeof(hint));
+               hint.ai_flags = AI_CANONNAME;
+               hint.ai_family = PF_UNSPEC;
+               hint.ai_socktype = SOCK_DGRAM;
                
-               if (!inet_aton(s, &addr)) {
-                       hp = gethostbyname(s);
-                       if (hp == NULL) {
-                               fprintf(stderr,
-                                       "Error in looking up server name:\n");
-                               hperror(res.res_h_errno);
-                               exit(1);
+               if (!getaddrinfo(s, NULL, &hint, &answer)) {
+                       nscount = 0;
+                       if (answer->ai_canonname != NULL) {
+                               printf("Using domain server:\n");
+                               printf("Name: %s\n", answer->ai_canonname);
+                               printf("Addresses:");
+                       } else
+                               printf("Using domain server");
+                       
+                       for (cur = answer; cur != NULL; cur = cur->ai_next) {
+                               char buf[80];
+                               struct sockaddr_in6 *sin6;
+                               struct sockaddr_in *sin;
+                               
+                               switch (cur->ai_addr->sa_family) {
+                               case AF_INET6:
+                                       sin6 = 
+                                          (struct sockaddr_in6 *)cur->ai_addr;
+                                       inet_ntop(cur->ai_addr->sa_family,
+                                                 &sin6->sin6_addr,
+                                                 buf, sizeof(buf));
+                                       printf(" %s", buf);
+                                       if (nscount >= MAXNS)
+                                               break;
+                                       u[nscount].sin6 = *sin6;
+                                       u[nscount++].sin6.sin6_port =
+                                               htons(NAMESERVER_PORT);
+                                       break;
+                               case AF_INET:
+                                       sin =
+                                            (struct sockaddr_in*)cur->ai_addr;
+                                       inet_ntop(cur->ai_addr->sa_family,
+                                                 &sin->sin_addr,
+                                                 buf, sizeof(buf));
+                                       printf(" %s", buf);
+                                       if (nscount >= MAXNS)
+                                               break;
+                                       u[nscount].sin = *sin;
+                                       u[nscount++].sin6.sin6_port =
+                                               htons(NAMESERVER_PORT);
+                                       break;
+                               }
                        }
-                       memcpy(&res.nsaddr.sin_addr, hp->h_addr, NS_INADDRSZ);
-                       printf("Using domain server:\n");
-                       printanswer(hp);
+                       if (nscount != 0) {
+                               res_setservers(&res, u, nscount);
+                       }
+                       if (answer->ai_canonname != NULL)
+                               printf("\n\n");
+                       else
+                               printf(":\n\n");
+                       freeaddrinfo(answer);
                } else {
-                       res.nsaddr.sin_family = AF_INET;
-                       res.nsaddr.sin_addr = addr;
-                       res.nsaddr.sin_port = htons(NAMESERVER_PORT);
-                       printf("Using domain server %s:\n",
-                              inet_ntoa(res.nsaddr.sin_addr));
+                       fprintf(stderr, "Error in looking up server name:\n");
+                       exit(1);
                }
-               res.nscount = 1;
                res.retry = 2;
        }
-       if (strcmp(getdomain, ".") == 0 || !inet_aton(getdomain, &addr))
-               addr.s_addr = INADDR_NONE;
+       memset(&hint, 0, sizeof(hint));
+       hint.ai_flags = AI_NUMERICHOST;
+       hint.ai_socktype = SOCK_DGRAM;
+       if(!getaddrinfo(getdomain, NULL, &hint, &answer)) { 
+               memset(&addr, 0, sizeof(addr));
+               switch (answer->ai_family) {
+               case AF_INET:
+                       memcpy(&addr, answer->ai_addr,
+                              sizeof(struct sockaddr_in));
+                       ip = 1;
+                       break;
+               case AF_INET6:
+                       memcpy(&addr, answer->ai_addr,
+                              sizeof(struct sockaddr_in6));
+                       ip = 1;
+                       break;
+               }
+               freeaddrinfo(answer);
+       } 
        hp = NULL;
        res.res_h_errno = TRY_AGAIN;
 /*
@@ -329,7 +396,7 @@
                exit(ListHosts(getdomain, querytype ? querytype : ns_t_a));
        ncnames = 5; nkeychains = 18;
        while (hp == NULL && res.res_h_errno == TRY_AGAIN) {
-               if (addr.s_addr == INADDR_NONE) {
+               if (!ip) {
                        cname = NULL;
                        hp = (struct hostent *)(unsigned long)gethostinfo(getdomain);
                        getdomain[0] = 0; /* clear this query */
@@ -353,7 +420,7 @@
                                        printf ("%s for %s not found, last verified key %s\n",
                                                chase_step & SD_SIG ? "Key" : "Signature",
                                                chase_step & SD_SIG ? chase_signer : chase_domain, 
-                                               chase_lastgoodkey ? chase_lastgoodkey : "None");
+                                               chase_lastgoodkey[0] ? chase_lastgoodkey : "None");
                                }
                        }
                        if (!getdomain[0] && cname) {
@@ -377,7 +444,7 @@
                                continue;
                        }
                } else {
-                       if (addrinfo(addr) == 0)
+                       if (addrinfo(&addr) == 0)
                                hp = NULL;
                        else
                                hp = (struct hostent *)1;       /* XXX */
@@ -427,21 +494,6 @@
 }
 
 static void
-printanswer(const struct hostent *hp) {
-       struct in_addr **hptr;
-       char **cp;
-
-       printf("Name: %s\n", hp->h_name);
-       printf("Address:");
-       for (hptr = (struct in_addr **)hp->h_addr_list; *hptr; hptr++)
-               printf(" %s", inet_ntoa(**hptr));
-       printf("\nAliases:");
-       for (cp = hp->h_aliases; cp && *cp && **cp; cp++)
-               printf(" %s", *cp);
-       printf("\n\n");
-}
-
-static void
 hperror(int errnum) {
        switch(errnum) {
        case HOST_NOT_FOUND:
@@ -524,15 +576,50 @@
 }
 
 static int
-addrinfo(struct in_addr addr) {
-       u_int32_t ha = ntohl(addr.s_addr);
+addrinfo(struct sockaddr_storage *addr) {
        char name[NS_MAXDNAME];
+       unsigned char *p;
+       struct in6_addr *addr6;
 
-       sprintf(name, "%u.%u.%u.%u.IN-ADDR.ARPA.",
-               (ha) & 0xff,
-               (ha >> 8) & 0xff,
-               (ha >> 16) & 0xff,
-               (ha >> 24) & 0xff);
+       switch(addr->ss_family) {
+       case AF_INET:
+               p = (unsigned char*)&((struct sockaddr_in *)addr)->sin_addr;
+       mapped:
+               sprintf(name, "%u.%u.%u.%u.IN-ADDR.ARPA.",
+                       p[3], p[2], p[1], p[0]);
+               break;
+       case AF_INET6:
+               addr6 = &((struct sockaddr_in6 *)addr)->sin6_addr;
+               p = (unsigned char *)addr6;
+               if (IN6_IS_ADDR_V4MAPPED(addr6) ||
+                   IN6_IS_ADDR_V4COMPAT(addr6)) {
+                       p += 12;
+                       goto mapped;
+               }
+               sprintf(name,
+                       "%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x."
+                       "%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x."
+                       "IP6.ARPA",
+                       p[15] & 0xf, (p[15] >> 4) & 0xf,
+                       p[14] & 0xf, (p[14] >> 4) & 0xf,
+                       p[13] & 0xf, (p[13] >> 4) & 0xf,
+                       p[12] & 0xf, (p[12] >> 4) & 0xf,
+                       p[11] & 0xf, (p[11] >> 4) & 0xf,
+                       p[10] & 0xf, (p[10] >> 4) & 0xf,
+                       p[9] & 0xf, (p[9] >> 4) & 0xf,
+                       p[8] & 0xf, (p[8] >> 4) & 0xf,
+                       p[7] & 0xf, (p[7] >> 4) & 0xf,
+                       p[6] & 0xf, (p[6] >> 4) & 0xf,
+                       p[5] & 0xf, (p[5] >> 4) & 0xf,
+                       p[4] & 0xf, (p[4] >> 4) & 0xf,
+                       p[3] & 0xf, (p[3] >> 4) & 0xf,
+                       p[2] & 0xf, (p[2] >> 4) & 0xf,
+                       p[1] & 0xf, (p[1] >> 4) & 0xf,
+                       p[0] & 0xf, (p[0] >> 4) & 0xf);
+               break;
+       default:
+               abort();
+       }
        return (getinfo(name, NULL, ns_t_ptr));
 }
 
@@ -590,7 +677,7 @@
 



Home | Main Index | Thread Index | Old Index