1999-03-07 Mark Kettenis <kettenis@gnu.org>
[kopensolaris-gnu/glibc.git] / resolv / res_debug.c
index dfb3b47..eadb020 100644 (file)
@@ -203,7 +203,7 @@ do_rrset(msg, len, cp, cnt, pflag, file, hs)
         * Print answer records.
         */
        sflag = (_res.pfcode & pflag);
-       if (n = ntohs(cnt)) {
+       if ((n = ntohs(cnt))) {
                if ((!_res.pfcode) ||
                    ((sflag) && (_res.pfcode & RES_PRF_HEAD1)))
                        fprintf(file, hs);
@@ -238,6 +238,7 @@ __p_query(msg)
 }
 
 #ifdef ultrix
+#undef p_query
 /* ultrix 4.0's packaging has some icky packaging.  alias for it here.
  * there is more junk of this kind over in res_comp.c.
  */
@@ -286,7 +287,7 @@ __fp_nquery(msg, len, file)
        if ((_res.options & RES_INIT) == 0 && res_init() == -1)
                return;
 
-#define TruncTest(x) if (x >= endMark) goto trunc
+#define TruncTest(x) if (x > endMark) goto trunc
 #define        ErrorTest(x) if (x == NULL) goto error
 
        /*
@@ -294,7 +295,7 @@ __fp_nquery(msg, len, file)
         */
        hp = (HEADER *)msg;
        cp = msg + HFIXEDSZ;
-       endMark = cp + len;
+       endMark = msg + len;
        if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEADX) || hp->rcode) {
                fprintf(file, ";; ->>HEADER<<- opcode: %s, status: %s, id: %d",
                        _res_opcodes[hp->opcode],
@@ -336,7 +337,7 @@ __fp_nquery(msg, len, file)
        /*
         * Print question records.
         */
-       if (n = ntohs(hp->qdcount)) {
+       if ((n = ntohs(hp->qdcount))) {
                if ((!_res.pfcode) || (_res.pfcode & RES_PRF_QUES))
                        fprintf(file, ";; QUESTIONS:\n");
                while (--n >= 0) {
@@ -451,11 +452,12 @@ __p_fqnname(cp, msg, msglen, name, namelen)
        if ((n = dn_expand(msg, cp + msglen, cp, name, namelen)) < 0)
                return (NULL);
        newlen = strlen (name);
-       if (newlen == 0 || name[newlen - 1] != '.')
+       if (newlen == 0 || name[newlen - 1] != '.') {
                if (newlen+1 >= namelen)        /* Lack space for final dot */
                        return (NULL);
                else
                        strcpy(name + newlen, ".");
+       }
        return (cp + n);
 }
 
@@ -495,7 +497,7 @@ __p_rr(cp, msg, file)
        char base64_key[MAX_KEY_BASE64];
 
        if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
-               h_errno = NETDB_INTERNAL;
+               __set_h_errno (NETDB_INTERNAL);
                return (NULL);
        }
        cp = __p_fqnname(cp, msg, MAXCDNAME, rrname, sizeof rrname);
@@ -646,7 +648,7 @@ __p_rr(cp, msg, file)
                cp2 = cp1 + dlen;
                while (cp < cp2) {
                        putc('"', file);
-                       if (n = (unsigned char) *cp++) {
+                       if ((n = (unsigned char) *cp++)) {
                                for (c = n; c > 0 && cp < cp2; c--) {
                                        if (strchr("\n\"\\", *cp))
                                                (void) putc('\\', file);
@@ -667,18 +669,53 @@ __p_rr(cp, msg, file)
        case T_AAAA: {
                char t[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"];
 
-               fprintf(file, "\t%s\n", inet_ntop(AF_INET6, cp, t, sizeof t));
+               fprintf(file, "\t%s", inet_ntop(AF_INET6, cp, t, sizeof t));
                cp += dlen;
                break;
-       }
+           }
 
        case T_LOC: {
                char t[255];
 
-               (void) fprintf(file, "\t%s\n", loc_ntoa(cp, t));
+               (void) fprintf(file, "\t%s", loc_ntoa(cp, t));
                cp += dlen;
                break;
-       }
+           }
+
+       case T_NAPTR: {
+               u_int order, preference;
+
+               order = _getshort(cp);  cp += INT16SZ;
+               preference   = _getshort(cp);  cp += INT16SZ;
+               fprintf(file, "\t%u %u ",order, preference);
+               /* Flags */
+               n = *cp++;
+               fprintf(file,"\"%.*s\" ", (int)n, cp);
+               cp += n;
+               /* Service */
+               n = *cp++;
+               fprintf(file,"\"%.*s\" ", (int)n, cp);
+               cp += n;
+               /* Regexp */
+               n = *cp++;
+               fprintf(file,"\"%.*s\" ", (int)n, cp);
+               cp += n;
+               if ((cp = p_fqname(cp, msg, file)) == NULL)
+                       return (NULL);
+               break;
+           }
+
+       case T_SRV: {
+               u_int priority, weight, port;
+
+               priority = _getshort(cp);  cp += INT16SZ;
+               weight   = _getshort(cp);  cp += INT16SZ;
+               port     = _getshort(cp);  cp += INT16SZ;
+               fprintf(file, "\t%u %u %u ", priority, weight, port);
+               if ((cp = p_fqname(cp, msg, file)) == NULL)
+                       return (NULL);
+               break;
+           }
 
        case T_MINFO:
        case T_RP:
@@ -769,7 +806,7 @@ __p_rr(cp, msg, file)
                                n, c);
                /* orig ttl */
                n = _getlong((u_char*)cp);
-               if (n != tmpttl)
+               if ((u_int32_t) n != tmpttl)
                        fprintf(file, " %u", n);
                cp += INT32SZ;
                /* sig expire */
@@ -856,13 +893,15 @@ const struct res_sym __p_class_syms[] = {
 const struct res_sym __p_type_syms[] = {
        {T_A,           "A",            "address"},
        {T_NS,          "NS",           "name server"},
+       {T_MD,          "MD",           "mail destination (deprecated)"},
+       {T_MF,          "MF",           "mail forwarder (deprecated)"},
        {T_CNAME,       "CNAME",        "canonical name"},
        {T_SOA,         "SOA",          "start of authority"},
        {T_MB,          "MB",           "mailbox"},
        {T_MG,          "MG",           "mail group member"},
        {T_MR,          "MR",           "mail rename"},
        {T_NULL,        "NULL",         "null"},
-       {T_WKS,         "WKS",          "well-known service"},
+       {T_WKS,         "WKS",          "well-known service (deprecated)"},
        {T_PTR,         "PTR",          "domain name pointer"},
        {T_HINFO,       "HINFO",        "host information"},
        {T_MINFO,       "MINFO",        "mailbox information"},
@@ -877,22 +916,28 @@ const struct res_sym __p_type_syms[] = {
        {T_NSAP_PTR,    "NSAP_PTR",     "domain name pointer"},
        {T_SIG,         "SIG",          "signature"},
        {T_KEY,         "KEY",          "key"},
-       {T_NXT,         "NXT",          "next valid name"},
        {T_PX,          "PX",           "mapping information"},
-       {T_GPOS,        "GPOS",         "geographical position"},
+       {T_GPOS,        "GPOS",         "geographical position (withdrawn)"},
        {T_AAAA,        "AAAA",         "IPv6 address"},
        {T_LOC,         "LOC",          "location"},
+       {T_NXT,         "NXT",          "next valid name (unimplemented)"},
+       {T_EID,         "EID",          "endpoint identifier (unimplemented)"},
+       {T_NIMLOC,      "NIMLOC",       "NIMROD locator (unimplemented)"},
+       {T_SRV,         "SRV",          "server selection"},
+       {T_ATMA,        "ATMA",         "ATM address (unimplemented)"},
+       {T_IXFR,        "IXFR",         "incremental zone transfer"},
        {T_AXFR,        "AXFR",         "zone transfer"},
-       {T_MAILB,       "MAILB",        "mailbox-related data"},
-       {T_MAILA,       "MAILA",        "mail agent"},
-       {T_UINFO,       "UINFO",        "user information"},
-       {T_UID,         "UID",          "user ID"},
-       {T_GID,         "GID",          "group ID"},
+       {T_MAILB,       "MAILB",        "mailbox-related data (deprecated)"},
+       {T_MAILA,       "MAILA",        "mail agent (deprecated)"},
+       {T_UINFO,       "UINFO",        "user information (nonstandard)"},
+       {T_UID,         "UID",          "user ID (nonstandard)"},
+       {T_GID,         "GID",          "group ID (nonstandard)"},
+       {T_NAPTR,       "NAPTR",        "URN Naming Authority"},
 #ifdef ALLOW_T_UNSPEC
-       {T_UNSPEC,      "UNSPEC",       "unspecified data"},
+       {T_UNSPEC,      "UNSPEC",       "unspecified data (nonstandard)"},
 #endif /* ALLOW_T_UNSPEC */
        {T_ANY,         "ANY",          "\"any\""},
-       {0,             (char *)0,      (char *)0}
+       {0,             NULL,           NULL}
 };
 
 int
@@ -1022,11 +1067,11 @@ __p_option(option)
 /*
  * Return a mnemonic for a time to live
  */
-char *
-__p_time(value)
+const char *
+p_time(value)
        u_int32_t value;
 {
-       static char nbuf[40];
+       static char nbuf[60];
        int secs, mins, hours, days;
        register char *p;
 
@@ -1102,40 +1147,47 @@ static u_int8_t
 precsize_aton(strptr)
        char **strptr;
 {
-       unsigned int mval = 0, cmval = 0;
        u_int8_t retval = 0;
-       register char *cp;
-       register int exponent;
-       register int mantissa;
+       char *cp;
+       int exponent = 0;
+       int mantissa = 0;
 
        cp = *strptr;
+       while (isdigit(*cp)) {
+               if (mantissa == 0)
+                       mantissa = *cp - '0';
+               else
+                       exponent++;
+               cp++;
+       }
 
-       while (isdigit(*cp))
-               mval = mval * 10 + (*cp++ - '0');
-
-       if (*cp == '.') {               /* centimeters */
+       if (*cp == '.') {
                cp++;
                if (isdigit(*cp)) {
-                       cmval = (*cp++ - '0') * 10;
+                       if (mantissa == 0)
+                               mantissa = *cp - '0';
+                       else
+                               exponent++;
+                       cp++;
+
                        if (isdigit(*cp)) {
-                               cmval += (*cp++ - '0');
+                               if (mantissa == 0)
+                                       mantissa = *cp - '0';
+                               else
+                                       exponent++;
+                               cp++;
                        }
+                       else
+                               exponent++;
                }
        }
-       cmval = (mval * 100) + cmval;
-
-       for (exponent = 0; exponent < 9; exponent++)
-               if (cmval < poweroften[exponent+1])
-                       break;
-
-       mantissa = cmval / poweroften[exponent];
-       if (mantissa > 9)
-               mantissa = 9;
+       else
+               exponent += 2;
 
+       if (mantissa == 0)
+               exponent = 0;
        retval = (mantissa << 4) | exponent;
-
        *strptr = cp;
-
        return (retval);
 }
 
@@ -1350,7 +1402,7 @@ loc_aton(ascii, binary)
 }
 
 /* takes an on-the-wire LOC RR and formats it in a human readable format. */
-char *
+const char *
 loc_ntoa(binary, ascii)
        const u_char *binary;
        char *ascii;
@@ -1390,7 +1442,7 @@ loc_ntoa(binary, ascii)
        longval = (templ - ((unsigned)1<<31));
 
        GETLONG(templ, cp);
-       if (templ < referencealt) { /* below WGS 84 spheroid */
+       if (templ < (u_int32_t) referencealt) { /* below WGS 84 spheroid */
                altval = referencealt - templ;
                altsign = -1;
        } else {
@@ -1491,13 +1543,13 @@ __p_secstodate (secs)
 {
        static char output[15];         /* YYYYMMDDHHMMSS and null */
        time_t clock = secs;
-       struct tm *time;
+       struct tm time;
 
-       time = gmtime(&clock);
-       time->tm_year += 1900;
-       time->tm_mon += 1;
+       __gmtime_r(&clock, &time);
+       time.tm_year += 1900;
+       time.tm_mon += 1;
        sprintf(output, "%04d%02d%02d%02d%02d%02d",
-               time->tm_year, time->tm_mon, time->tm_mday,
-               time->tm_hour, time->tm_min, time->tm_sec);
+               time.tm_year, time.tm_mon, time.tm_mday,
+               time.tm_hour, time.tm_min, time.tm_sec);
        return (output);
 }