am 0bca08d6: Merge "Update res_debug.c to take into account changes to the nameser.h"

* commit '0bca08d69f4d68782f5a3e6cf16dc74997bcf277':
  Update res_debug.c to take into account changes to the nameser.h
This commit is contained in:
Calin Juravle 2014-03-10 11:26:28 +00:00 committed by Android Git Automerger
commit f535485cc0

View File

@ -1,4 +1,21 @@
/* $NetBSD: res_debug.c,v 1.7 2004/11/07 02:25:01 christos Exp $ */
/* $NetBSD: res_debug.c,v 1.13 2012/06/25 22:32:45 abs Exp $ */
/*
* Portions Copyright (C) 2004, 2005, 2008, 2009 Internet Systems Consortium, Inc. ("ISC")
* Portions Copyright (C) 1996-2003 Internet Software Consortium.
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
/*
* Copyright (c) 1985
@ -78,30 +95,13 @@
* IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES.
*/
/*
* Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
* Portions Copyright (c) 1996-1999 by Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
#ifdef notdef
static const char sccsid[] = "@(#)res_debug.c 8.1 (Berkeley) 6/4/93";
static const char rcsid[] = "Id: res_debug.c,v 1.3.2.5.4.5 2004/07/28 20:16:46 marka Exp";
static const char rcsid[] = "Id: res_debug.c,v 1.19 2009/02/26 11:20:20 tbox Exp";
#else
__RCSID("$NetBSD: res_debug.c,v 1.7 2004/11/07 02:25:01 christos Exp $");
__RCSID("$NetBSD: res_debug.c,v 1.13 2012/06/25 22:32:45 abs Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@ -134,8 +134,6 @@ __RCSID("$NetBSD: res_debug.c,v 1.7 2004/11/07 02:25:01 christos Exp $");
# define SPRINTF(x) sprintf x
#endif
static const char *precsize_ntoa(u_int32_t);
extern const char * const _res_opcodes[];
extern const char * const _res_sectioncodes[];
@ -169,7 +167,7 @@ do_section(const res_state statp,
/*
* Print answer records.
*/
sflag = (statp->pfcode & pflag);
sflag = (int)(statp->pfcode & pflag);
if (statp->pfcode && !sflag)
return;
@ -200,10 +198,57 @@ do_section(const res_state statp,
p_type(ns_rr_type(rr)),
p_class(ns_rr_class(rr)));
else if (section == ns_s_ar && ns_rr_type(rr) == ns_t_opt) {
u_int32_t ttl = ns_rr_ttl(rr);
size_t rdatalen, ttl;
uint16_t optcode, optlen;
rdatalen = ns_rr_rdlen(rr);
ttl = ns_rr_ttl(rr);
fprintf(file,
"; EDNS: version: %u, udp=%u, flags=%04x\n",
"; EDNS: version: %zu, udp=%u, flags=%04zx\n",
(ttl>>16)&0xff, ns_rr_class(rr), ttl&0xffff);
while (rdatalen >= 4) {
const u_char *cp = ns_rr_rdata(rr);
int i;
GETSHORT(optcode, cp);
GETSHORT(optlen, cp);
if (optcode == NS_OPT_NSID) {
fputs("; NSID: ", file);
if (optlen == 0) {
fputs("; NSID\n", file);
} else {
fputs("; NSID: ", file);
for (i = 0; i < optlen; i++)
fprintf(file, "%02x ",
cp[i]);
fputs(" (",file);
for (i = 0; i < optlen; i++)
fprintf(file, "%c",
isprint(cp[i])?
cp[i] : '.');
fputs(")\n", file);
}
} else {
if (optlen == 0) {
fprintf(file, "; OPT=%u\n",
optcode);
} else {
fprintf(file, "; OPT=%u: ",
optcode);
for (i = 0; i < optlen; i++)
fprintf(file, "%02x ",
cp[i]);
fputs(" (",file);
for (i = 0; i < optlen; i++)
fprintf(file, "%c",
isprint(cp[i]) ?
cp[i] : '.');
fputs(")\n", file);
}
}
rdatalen -= 4 + optlen;
}
} else {
n = ns_sprintrr(handle, &rr, NULL, NULL,
buf, (u_int)buflen);
@ -315,7 +360,7 @@ p_cdnname(const u_char *cp, const u_char *msg, int len, FILE *file) {
char name[MAXDNAME];
int n;
if ((n = dn_expand(msg, msg + len, cp, name, sizeof name)) < 0)
if ((n = dn_expand(msg, msg + len, cp, name, (int)sizeof name)) < 0)
return (NULL);
if (name[0] == '\0')
putc('.', file);
@ -333,19 +378,17 @@ p_cdname(const u_char *cp, const u_char *msg, FILE *file) {
length supplied). */
const u_char *
p_fqnname(cp, msg, msglen, name, namelen)
const u_char *cp, *msg;
int msglen;
char *name;
int namelen;
p_fqnname(const u_char *cp, const u_char *msg, int msglen, char *name,
int namelen)
{
int n, newlen;
int n;
size_t newlen;
if ((n = dn_expand(msg, cp + msglen, cp, name, namelen)) < 0)
return (NULL);
newlen = strlen(name);
if (newlen == 0 || name[newlen - 1] != '.') {
if (newlen + 1 >= namelen) /* Lack space for final dot */
if ((int)newlen + 1 >= namelen) /* Lack space for final dot */
return (NULL);
else
strcpy(name + newlen, ".");
@ -360,7 +403,7 @@ p_fqname(const u_char *cp, const u_char *msg, FILE *file) {
char name[MAXDNAME];
const u_char *n;
n = p_fqnname(cp, msg, MAXCDNAME, name, sizeof name);
n = p_fqnname(cp, msg, MAXCDNAME, name, (int)sizeof name);
if (n == NULL)
return (NULL);
fputs(name, file);
@ -460,6 +503,24 @@ const struct res_sym __p_type_syms[] = {
{ns_t_nimloc, "NIMLOC", "NIMROD locator (unimplemented)"},
{ns_t_srv, "SRV", "server selection"},
{ns_t_atma, "ATMA", "ATM address (unimplemented)"},
{ns_t_naptr, "NAPTR", "naptr"},
{ns_t_kx, "KX", "key exchange"},
{ns_t_cert, "CERT", "certificate"},
{ns_t_a6, "A", "IPv6 address (experminental)"},
{ns_t_dname, "DNAME", "non-terminal redirection"},
{ns_t_opt, "OPT", "opt"},
{ns_t_apl, "apl", "apl"},
{ns_t_ds, "DS", "delegation signer"},
{ns_t_sshfp, "SSFP", "SSH fingerprint"},
{ns_t_ipseckey, "IPSECKEY", "IPSEC key"},
{ns_t_rrsig, "RRSIG", "rrsig"},
{ns_t_nsec, "NSEC", "nsec"},
{ns_t_dnskey, "DNSKEY", "DNS key"},
{ns_t_dhcid, "DHCID", "dynamic host configuration identifier"},
{ns_t_nsec3, "NSEC3", "nsec3"},
{ns_t_nsec3param, "NSEC3PARAM", "NSEC3 parameters"},
{ns_t_hip, "HIP", "host identity protocol"},
{ns_t_spf, "SPF", "sender policy framework"},
{ns_t_tkey, "TKEY", "tkey"},
{ns_t_tsig, "TSIG", "transaction signature"},
{ns_t_ixfr, "IXFR", "incremental zone transfer"},
@ -475,6 +536,7 @@ const struct res_sym __p_type_syms[] = {
{ns_t_sink, "SINK", "Kitchen Sink (experimental)"},
{ns_t_opt, "OPT", "EDNS Options"},
{ns_t_any, "ANY", "\"any\""},
{ns_t_dlv, "DLV", "DNSSEC look-aside validation"},
{0, NULL, NULL}
};
@ -675,7 +737,7 @@ p_sockun(union res_sockaddr_union u, char *buf, size_t size) {
switch (u.sin.sin_family) {
case AF_INET:
inet_ntop(AF_INET, &u.sin.sin_addr, ret, sizeof ret);
inet_ntop(AF_INET, &u.sin.sin_addr, ret, (socklen_t)sizeof ret);
break;
#ifdef HAS_INET6_STRUCTS
case AF_INET6:
@ -704,8 +766,7 @@ static const unsigned int poweroften[10] = {1, 10, 100, 1000, 10000, 100000,
/* takes an XeY precision/size value, returns a string representation. */
static const char *
precsize_ntoa(prec)
u_int32_t prec;
precsize_ntoa(u_int32_t prec)
{
static char retbuf[sizeof "90000000.00"]; /* XXX nonreentrant */
unsigned long val;
@ -858,9 +919,7 @@ latlon2ul(const char **latlonstrptr, int *which) {
/* converts a zone file representation in a string to an RDATA on-the-wire
* representation. */
int
loc_aton(ascii, binary)
const char *ascii;
u_char *binary;
loc_aton(const char *ascii, u_char *binary)
{
const char *cp, *maxcp;
u_char *bcp;
@ -969,9 +1028,7 @@ loc_aton(ascii, binary)
/* takes an on-the-wire LOC RR and formats it in a human readable format. */
const char *
loc_ntoa(binary, ascii)
const u_char *binary;
char *ascii;
loc_ntoa(const u_char *binary, char *ascii)
{
static const char *error = "?";
static char tmpbuf[sizeof
@ -1080,7 +1137,7 @@ loc_ntoa(binary, ascii)
/* Return the number of DNS hierarchy levels in the name. */
int
dn_count_labels(const char *name) {
int i, len, count;
size_t len, i, count;
len = strlen(name);
for (i = 0, count = 0; i < len; i++) {
@ -1099,7 +1156,8 @@ dn_count_labels(const char *name) {
/* count to include last label */
if (len > 0 && name[len-1] != '.')
count++;
return (count);
_DIAGASSERT(__type_fit(int, count));
return (int)count;
}