flag fields are u_int's
[unix-history] / usr / src / lib / libc / net / res_debug.c
index d1d1053..bac8d0b 100644 (file)
@@ -1,22 +1,29 @@
-/*
- * Copyright (c) 1985 Regents of the University of California.
- * All rights reserved.  The Berkeley software License Agreement
- * specifies the terms and conditions for redistribution.
+/*-
+ * Copyright (c) 1985, 1990 Regents of the University of California.
+ * All rights reserved.
+ *
+ * %sccs.include.redist.c%
+ *
+ *     @(#)res_debug.c 5.36 (Berkeley) %G%
  */
 
  */
 
-#ifndef lint
-static char sccsid[] = "@(#)res_debug.c        5.5 (Berkeley) %G%";
-#endif not lint
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)res_debug.c        5.36 (Berkeley) %G%";
+#endif /* LIBC_SCCS and not lint */
 
 
-#include <sys/types.h>
+#include <sys/param.h>
 #include <netinet/in.h>
 #include <netinet/in.h>
-#include <stdio.h>
+#include <arpa/inet.h>
 #include <arpa/nameser.h>
 #include <arpa/nameser.h>
+#include <resolv.h>
+#include <stdio.h>
+#include <string.h>
 
 
-extern char *p_cdname(), *p_rr(), *p_type(), *p_class();
-extern char *inet_ntoa();
+void __fp_query();
+char *__p_class(), *__p_time(), *__p_type();
+static char *p_cdname(), *p_rr();
 
 
-char *opcodes[] = {
+char *_res_opcodes[] = {
        "QUERY",
        "IQUERY",
        "CQUERYM",
        "QUERY",
        "IQUERY",
        "CQUERYM",
@@ -26,16 +33,16 @@ char *opcodes[] = {
        "6",
        "7",
        "8",
        "6",
        "7",
        "8",
-       "9",
-       "10",
        "UPDATEA",
        "UPDATED",
        "UPDATEA",
        "UPDATED",
+       "UPDATEDA",
        "UPDATEM",
        "UPDATEM",
+       "UPDATEMA",
        "ZONEINIT",
        "ZONEREF",
 };
 
        "ZONEINIT",
        "ZONEREF",
 };
 
-char *rcodes[] = {
+char *_res_resultcodes[] = {
        "NOERROR",
        "FORMERR",
        "SERVFAIL",
        "NOERROR",
        "FORMERR",
        "SERVFAIL",
@@ -54,17 +61,18 @@ char *rcodes[] = {
        "NOCHANGE",
 };
 
        "NOCHANGE",
 };
 
-p_query(msg)
+__p_query(msg)
        char *msg;
 {
        char *msg;
 {
-       fp_query(msg,stdout);
+       __fp_query(msg,stdout);
 }
 
 /*
  * Print the contents of a query.
  * This is intended to be primarily a debugging routine.
  */
 }
 
 /*
  * Print the contents of a query.
  * This is intended to be primarily a debugging routine.
  */
-fp_query(msg,file)
+void
+__fp_query(msg,file)
        char *msg;
        FILE *file;
 {
        char *msg;
        FILE *file;
 {
@@ -78,9 +86,9 @@ fp_query(msg,file)
        hp = (HEADER *)msg;
        cp = msg + sizeof(HEADER);
        fprintf(file,"HEADER:\n");
        hp = (HEADER *)msg;
        cp = msg + sizeof(HEADER);
        fprintf(file,"HEADER:\n");
-       fprintf(file,"\topcode = %s", opcodes[hp->opcode]);
+       fprintf(file,"\topcode = %s", _res_opcodes[hp->opcode]);
        fprintf(file,", id = %d", ntohs(hp->id));
        fprintf(file,", id = %d", ntohs(hp->id));
-       fprintf(file,", rcode = %s\n", rcodes[hp->rcode]);
+       fprintf(file,", rcode = %s\n", _res_resultcodes[hp->rcode]);
        fprintf(file,"\theader flags: ");
        if (hp->qr)
                fprintf(file," qr");
        fprintf(file,"\theader flags: ");
        if (hp->qr)
                fprintf(file," qr");
@@ -108,9 +116,10 @@ fp_query(msg,file)
                        cp = p_cdname(cp, msg, file);
                        if (cp == NULL)
                                return;
                        cp = p_cdname(cp, msg, file);
                        if (cp == NULL)
                                return;
-                       fprintf(file,", type = %s", p_type(getshort(cp)));
+                       fprintf(file,", type = %s", __p_type(_getshort(cp)));
                        cp += sizeof(u_short);
                        cp += sizeof(u_short);
-                       fprintf(file,", class = %s\n\n", p_class(getshort(cp)));
+                       fprintf(file,
+                           ", class = %s\n\n", __p_class(_getshort(cp)));
                        cp += sizeof(u_short);
                }
        }
                        cp += sizeof(u_short);
                }
        }
@@ -152,7 +161,7 @@ fp_query(msg,file)
        }
 }
 
        }
 }
 
-char *
+static char *
 p_cdname(cp, msg, file)
        char *cp, *msg;
        FILE *file;
 p_cdname(cp, msg, file)
        char *cp, *msg;
        FILE *file;
@@ -160,7 +169,8 @@ p_cdname(cp, msg, file)
        char name[MAXDNAME];
        int n;
 
        char name[MAXDNAME];
        int n;
 
-       if ((n = dn_expand(msg, cp, name, sizeof(name))) < 0)
+       if ((n = dn_expand((u_char *)msg, (u_char *)msg + 512, (u_char *)cp,
+           (u_char *)name, sizeof(name))) < 0)
                return (NULL);
        if (name[0] == '\0') {
                name[0] = '.';
                return (NULL);
        if (name[0] == '\0') {
                name[0] = '.';
@@ -173,24 +183,24 @@ p_cdname(cp, msg, file)
 /*
  * Print resource record fields in human readable form.
  */
 /*
  * Print resource record fields in human readable form.
  */
-char *
+static char *
 p_rr(cp, msg, file)
        char *cp, *msg;
        FILE *file;
 {
        int type, class, dlen, n, c;
        struct in_addr inaddr;
 p_rr(cp, msg, file)
        char *cp, *msg;
        FILE *file;
 {
        int type, class, dlen, n, c;
        struct in_addr inaddr;
-       char *cp1;
+       char *cp1, *cp2;
 
        if ((cp = p_cdname(cp, msg, file)) == NULL)
                return (NULL);                  /* compression error */
 
        if ((cp = p_cdname(cp, msg, file)) == NULL)
                return (NULL);                  /* compression error */
-       fprintf(file,"\n\ttype = %s", p_type(type = getshort(cp)));
+       fprintf(file,"\n\ttype = %s", __p_type(type = _getshort(cp)));
        cp += sizeof(u_short);
        cp += sizeof(u_short);
-       fprintf(file,", class = %s", p_class(class = getshort(cp)));
+       fprintf(file,", class = %s", __p_class(class = _getshort(cp)));
        cp += sizeof(u_short);
        cp += sizeof(u_short);
-       fprintf(file,", ttl = %u", getlong(cp));
+       fprintf(file,", ttl = %s", __p_time(_getlong(cp)));
        cp += sizeof(u_long);
        cp += sizeof(u_long);
-       fprintf(file,", dlen = %d\n", dlen = getshort(cp));
+       fprintf(file,", dlen = %d\n", dlen = _getshort(cp));
        cp += sizeof(u_short);
        cp1 = cp;
        /*
        cp += sizeof(u_short);
        cp1 = cp;
        /*
@@ -200,6 +210,7 @@ p_rr(cp, msg, file)
        case T_A:
                switch (class) {
                case C_IN:
        case T_A:
                switch (class) {
                case C_IN:
+               case C_HS:
                        bcopy(cp, (char *)&inaddr, sizeof(inaddr));
                        if (dlen == 4) {
                                fprintf(file,"\tinternet address = %s\n",
                        bcopy(cp, (char *)&inaddr, sizeof(inaddr));
                        if (dlen == 4) {
                                fprintf(file,"\tinternet address = %s\n",
@@ -214,12 +225,12 @@ p_rr(cp, msg, file)
                                cp += dlen;
                        }
                        break;
                                cp += dlen;
                        }
                        break;
+               default:
+                       cp += dlen;
                }
                break;
        case T_CNAME:
        case T_MB:
                }
                break;
        case T_CNAME:
        case T_MB:
-       case T_MD:
-       case T_MF:
        case T_MG:
        case T_MR:
        case T_NS:
        case T_MG:
        case T_MR:
        case T_NS:
@@ -245,18 +256,41 @@ p_rr(cp, msg, file)
                cp = p_cdname(cp, msg, file);
                fprintf(file,"\n\tmail addr = ");
                cp = p_cdname(cp, msg, file);
                cp = p_cdname(cp, msg, file);
                fprintf(file,"\n\tmail addr = ");
                cp = p_cdname(cp, msg, file);
-               fprintf(file,"\n\tserial=%ld", getlong(cp));
+               fprintf(file,"\n\tserial = %ld", _getlong(cp));
                cp += sizeof(u_long);
                cp += sizeof(u_long);
-               fprintf(file,", refresh=%ld", getlong(cp));
+               fprintf(file,"\n\trefresh = %s", __p_time(_getlong(cp)));
                cp += sizeof(u_long);
                cp += sizeof(u_long);
-               fprintf(file,", retry=%ld", getlong(cp));
+               fprintf(file,"\n\tretry = %s", __p_time(_getlong(cp)));
                cp += sizeof(u_long);
                cp += sizeof(u_long);
-               fprintf(file,", expire=%ld", getlong(cp));
+               fprintf(file,"\n\texpire = %s", __p_time(_getlong(cp)));
                cp += sizeof(u_long);
                cp += sizeof(u_long);
-               fprintf(file,", min=%ld\n", getlong(cp));
+               fprintf(file,"\n\tmin = %s\n", __p_time(_getlong(cp)));
                cp += sizeof(u_long);
                break;
 
                cp += sizeof(u_long);
                break;
 
+       case T_MX:
+               fprintf(file,"\tpreference = %ld,",_getshort(cp));
+               cp += sizeof(u_short);
+               fprintf(file," name = ");
+               cp = p_cdname(cp, msg, file);
+               break;
+
+       case T_TXT:
+               (void) fputs("\t\"", file);
+               cp2 = cp1 + dlen;
+               while (cp < cp2) {
+                       if (n = (unsigned char) *cp++) {
+                               for (c = n; c > 0 && cp < cp2; c--)
+                                       if (*cp == '\n') {
+                                           (void) putc('\\', file);
+                                           (void) putc(*cp++, file);
+                                       } else
+                                           (void) putc(*cp++, file);
+                       }
+               }
+               (void) fputs("\"\n", file);
+               break;
+
        case T_MINFO:
                fprintf(file,"\trequests = ");
                cp = p_cdname(cp, msg, file);
        case T_MINFO:
                fprintf(file,"\trequests = ");
                cp = p_cdname(cp, msg, file);
@@ -272,7 +306,7 @@ p_rr(cp, msg, file)
        case T_UID:
        case T_GID:
                if (dlen == 4) {
        case T_UID:
        case T_GID:
                if (dlen == 4) {
-                       fprintf(file,"\t%ld\n", getlong(cp));
+                       fprintf(file,"\t%ld\n", _getlong(cp));
                        cp += sizeof(int);
                }
                break;
                        cp += sizeof(int);
                }
                break;
@@ -296,37 +330,51 @@ p_rr(cp, msg, file)
                putc('\n',file);
                break;
 
                putc('\n',file);
                break;
 
+#ifdef ALLOW_T_UNSPEC
+       case T_UNSPEC:
+               {
+                       int NumBytes = 8;
+                       char *DataPtr;
+                       int i;
+
+                       if (dlen < NumBytes) NumBytes = dlen;
+                       fprintf(file, "\tFirst %d bytes of hex data:",
+                               NumBytes);
+                       for (i = 0, DataPtr = cp; i < NumBytes; i++, DataPtr++)
+                               fprintf(file, " %x", *DataPtr);
+                       fputs("\n", file);
+                       cp += dlen;
+               }
+               break;
+#endif /* ALLOW_T_UNSPEC */
+
        default:
                fprintf(file,"\t???\n");
                cp += dlen;
        }
        default:
                fprintf(file,"\t???\n");
                cp += dlen;
        }
-       if (cp != cp1 + dlen)
+       if (cp != cp1 + dlen) {
                fprintf(file,"packet size error (%#x != %#x)\n", cp, cp1+dlen);
                fprintf(file,"packet size error (%#x != %#x)\n", cp, cp1+dlen);
+               cp = NULL;
+       }
        fprintf(file,"\n");
        return (cp);
 }
 
        fprintf(file,"\n");
        return (cp);
 }
 
-static char nbuf[20];
-extern char *sprintf();
+static char nbuf[40];
 
 /*
  * Return a string for the type
  */
 char *
 
 /*
  * Return a string for the type
  */
 char *
-p_type(type)
+__p_type(type)
        int type;
 {
        int type;
 {
-
        switch (type) {
        case T_A:
                return("A");
        case T_NS:              /* authoritative server */
                return("NS");
        switch (type) {
        case T_A:
                return("A");
        case T_NS:              /* authoritative server */
                return("NS");
-       case T_MD:              /* mail destination */
-               return("MD");
-       case T_MF:              /* mail forwarder */
-               return("MF");
-       case T_CNAME:           /* connonical name */
+       case T_CNAME:           /* canonical name */
                return("CNAME");
        case T_SOA:             /* start of authority zone */
                return("SOA");
                return("CNAME");
        case T_SOA:             /* start of authority zone */
                return("SOA");
@@ -346,6 +394,10 @@ p_type(type)
                return("HINFO");
        case T_MINFO:           /* mailbox information */
                return("MINFO");
                return("HINFO");
        case T_MINFO:           /* mailbox information */
                return("MINFO");
+       case T_MX:              /* mail routing info */
+               return("MX");
+       case T_TXT:             /* text */
+               return("TXT");
        case T_AXFR:            /* zone transfer */
                return("AXFR");
        case T_MAILB:           /* mail box */
        case T_AXFR:            /* zone transfer */
                return("AXFR");
        case T_MAILB:           /* mail box */
@@ -360,8 +412,13 @@ p_type(type)
                return("UID");
        case T_GID:
                return("GID");
                return("UID");
        case T_GID:
                return("GID");
+#ifdef ALLOW_T_UNSPEC
+       case T_UNSPEC:
+               return("UNSPEC");
+#endif /* ALLOW_T_UNSPEC */
        default:
        default:
-               return (sprintf(nbuf, "%d", type));
+               (void)sprintf(nbuf, "%d", type);
+               return(nbuf);
        }
 }
 
        }
 }
 
@@ -369,19 +426,67 @@ p_type(type)
  * Return a mnemonic for class
  */
 char *
  * Return a mnemonic for class
  */
 char *
-p_class(class)
+__p_class(class)
        int class;
 {
 
        switch (class) {
        case C_IN:              /* internet class */
                return("IN");
        int class;
 {
 
        switch (class) {
        case C_IN:              /* internet class */
                return("IN");
-       case C_CS:              /* csnet class */
-               return("CS");
+       case C_HS:              /* hesiod class */
+               return("HS");
        case C_ANY:             /* matches any class */
                return("ANY");
        default:
        case C_ANY:             /* matches any class */
                return("ANY");
        default:
-               return (sprintf(nbuf, "%d", class));
+               (void)sprintf(nbuf, "%d", class);
+               return(nbuf);
        }
 }
 
        }
 }
 
+/*
+ * Return a mnemonic for a time to live
+ */
+char *
+__p_time(value)
+       u_long value;
+{
+       int secs, mins, hours;
+       register char *p;
+
+       if (value == 0) {
+               strcpy(nbuf, "0 secs");
+               return(nbuf);
+       }
+
+       secs = value % 60;
+       value /= 60;
+       mins = value % 60;
+       value /= 60;
+       hours = value % 24;
+       value /= 24;
+
+#define        PLURALIZE(x)    x, (x == 1) ? "" : "s"
+       p = nbuf;
+       if (value) {
+               (void)sprintf(p, "%d day%s", PLURALIZE(value));
+               while (*++p);
+       }
+       if (hours) {
+               if (value)
+                       *p++ = ' ';
+               (void)sprintf(p, "%d hour%s", PLURALIZE(hours));
+               while (*++p);
+       }
+       if (mins) {
+               if (value || hours)
+                       *p++ = ' ';
+               (void)sprintf(p, "%d min%s", PLURALIZE(mins));
+               while (*++p);
+       }
+       if (secs || ! (value || hours || mins)) {
+               if (value || hours || mins)
+                       *p++ = ' ';
+               (void)sprintf(p, "%d sec%s", PLURALIZE(secs));
+       }
+       return(nbuf);
+}