tcpdump/print-lwres.c

597 lines
14 KiB
C
Raw Normal View History

2001-01-29 17:18:46 +08:00
/*
* Copyright (C) 2001 WIDE Project.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the project nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/* \summary: BIND9 Lightweight Resolver protocol printer */
2001-01-29 17:18:46 +08:00
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <netdissect-stdinc.h>
2001-01-29 17:18:46 +08:00
#include <stdio.h>
#include <string.h>
#include "netdissect.h"
2001-01-29 17:18:46 +08:00
#include "addrtoname.h"
2015-09-07 21:01:46 +08:00
#include "extract.h"
2001-01-29 17:18:46 +08:00
#include "nameser.h"
2001-01-29 17:18:46 +08:00
/* BIND9 lib/lwres/include/lwres */
2017-12-31 09:07:06 +08:00
typedef nd_uint32_t lwres_uint32_t;
typedef nd_uint16_t lwres_uint16_t;
typedef nd_uint8_t lwres_uint8_t;
2001-01-29 17:18:46 +08:00
struct lwres_lwpacket {
lwres_uint32_t length;
lwres_uint16_t version;
lwres_uint16_t pktflags;
lwres_uint32_t serial;
lwres_uint32_t opcode;
lwres_uint32_t result;
lwres_uint32_t recvlength;
lwres_uint16_t authtype;
lwres_uint16_t authlength;
};
2001-01-29 17:18:46 +08:00
2001-01-30 04:04:00 +08:00
#define LWRES_LWPACKETFLAG_RESPONSE 0x0001U /* if set, pkt is a response */
#define LWRES_LWPACKETVERSION_0 0
2001-01-29 17:18:46 +08:00
#define LWRES_FLAG_TRUSTNOTREQUIRED 0x00000001U
#define LWRES_FLAG_SECUREDATA 0x00000002U
/*
* no-op
*/
#define LWRES_OPCODE_NOOP 0x00000000U
typedef struct {
/* public */
lwres_uint16_t datalength;
2001-01-30 04:04:00 +08:00
/* data follows */
} lwres_nooprequest_t;
2001-01-29 17:18:46 +08:00
typedef struct {
/* public */
lwres_uint16_t datalength;
2001-01-30 04:04:00 +08:00
/* data follows */
} lwres_noopresponse_t;
2001-01-29 17:18:46 +08:00
/*
* get addresses by name
*/
#define LWRES_OPCODE_GETADDRSBYNAME 0x00010001U
2001-01-30 04:04:00 +08:00
typedef struct lwres_addr lwres_addr_t;
struct lwres_addr {
lwres_uint32_t family;
lwres_uint16_t length;
/* address folows */
};
2001-01-30 04:04:00 +08:00
2001-01-29 17:18:46 +08:00
typedef struct {
/* public */
lwres_uint32_t flags;
lwres_uint32_t addrtypes;
lwres_uint16_t namelen;
/* name follows */
} lwres_gabnrequest_t;
2001-01-29 17:18:46 +08:00
typedef struct {
/* public */
lwres_uint32_t flags;
lwres_uint16_t naliases;
lwres_uint16_t naddrs;
lwres_uint16_t realnamelen;
2001-01-30 04:04:00 +08:00
/* aliases follows */
/* addrs follows */
/* realname follows */
} lwres_gabnresponse_t;
2001-01-29 17:18:46 +08:00
/*
* get name by address
*/
#define LWRES_OPCODE_GETNAMEBYADDR 0x00010002U
typedef struct {
/* public */
lwres_uint32_t flags;
lwres_addr_t addr;
2001-01-30 04:04:00 +08:00
/* addr body follows */
2001-01-29 17:18:46 +08:00
} lwres_gnbarequest_t;
typedef struct {
/* public */
lwres_uint32_t flags;
lwres_uint16_t naliases;
lwres_uint16_t realnamelen;
2001-01-30 04:04:00 +08:00
/* aliases follows */
/* realname follows */
} lwres_gnbaresponse_t;
2001-01-29 17:18:46 +08:00
/*
* get rdata by name
*/
#define LWRES_OPCODE_GETRDATABYNAME 0x00010003U
typedef struct {
/* public */
lwres_uint32_t flags;
lwres_uint16_t rdclass;
lwres_uint16_t rdtype;
lwres_uint16_t namelen;
2001-01-30 04:04:00 +08:00
/* name follows */
} lwres_grbnrequest_t;
2001-01-29 17:18:46 +08:00
typedef struct {
/* public */
lwres_uint32_t flags;
lwres_uint16_t rdclass;
lwres_uint16_t rdtype;
lwres_uint32_t ttl;
lwres_uint16_t nrdatas;
lwres_uint16_t nsigs;
2001-01-30 04:04:00 +08:00
/* realname here (len + name) */
/* rdata here (len + name) */
/* signatures here (len + name) */
} lwres_grbnresponse_t;
2001-01-29 17:18:46 +08:00
#define LWRDATA_VALIDATED 0x00000001
#define LWRES_ADDRTYPE_V4 0x00000001U /* ipv4 */
#define LWRES_ADDRTYPE_V6 0x00000002U /* ipv6 */
#define LWRES_MAX_ALIASES 16 /* max # of aliases */
#define LWRES_MAX_ADDRS 64 /* max # of addrs */
static const struct tok opcode[] = {
2001-01-29 17:18:46 +08:00
{ LWRES_OPCODE_NOOP, "noop", },
{ LWRES_OPCODE_GETADDRSBYNAME, "getaddrsbyname", },
{ LWRES_OPCODE_GETNAMEBYADDR, "getnamebyaddr", },
{ LWRES_OPCODE_GETRDATABYNAME, "getrdatabyname", },
{ 0, NULL, },
};
2001-01-30 04:04:00 +08:00
/* print-domain.c */
extern const struct tok ns_type2str[];
extern const struct tok ns_class2str[];
2001-01-29 17:18:46 +08:00
2001-01-30 04:04:00 +08:00
static int
lwres_printname(netdissect_options *ndo,
size_t l, const char *p0)
2001-01-30 04:04:00 +08:00
{
const char *p;
Add a few more GCC warnings on GCC >= 2 for ".devel" builds. From Neil T. Spring: fixes for many of those warnings: addrtoname.c, configure.in: Linux needs netinet/ether.h for ether_ntohost print-*.c: change char *foo = "bar" to const char *foo = "bar" to appease -Wwrite-strings; should affect no run-time behavior. print-*.c: make some variables unsigned. print-bgp.c: plen ('prefix len') is unsigned, no reason to validate by comparing to zero. print-cnfp.c, print-rx.c: use intoa, provided by addrtoname, instead of inet_ntoa. print-domain.c: unsigned int l; (l=foo()) < 0 is guaranteed to be false, so check for (u_int)-1, which represents failure, explicitly. print-isakmp.c: complete initialization of attrmap objects. print-lwres.c: "if(x); print foo;" seemed much more likely to be intended to be "if(x) { print foo; }". print-smb.c: complete initialization of some structures. In addition, add some fixes for the signed vs. unsigned comparison warnings: extract.h: cast the result of the byte-extraction-and-combining, as, at least for the 16-bit version, C's integral promotions will turn "u_int16_t" into "int" if there are other "int"s nearby. print-*.c: make some more variables unsigned, or add casts to an unsigned type of signed values known not to be negative, or add casts to "int" of unsigned values known to fit in an "int", and make other changes needed to handle the aforementioned variables now being unsigned. print-isakmp.c: clean up the handling of error/status indicators in notify messages. print-ppp.c: get rid of a check that an unsigned quantity is >= 0. print-radius.c: clean up some of the bounds checking. print-smb.c: extract the word count into a "u_int" to avoid the aforementioned problems with C's integral promotions. print-snmp.c: change a check that an unsigned variable is >= 0 to a check that it's != 0. Also, fix some formats to use "%u" rather than "%d" for unsigned quantities.
2002-09-05 08:00:07 +08:00
size_t i;
2001-01-30 04:04:00 +08:00
p = p0;
/* + 1 for terminating \0 */
if (p + l + 1 > (const char *)ndo->ndo_snapend)
2001-01-30 04:04:00 +08:00
goto trunc;
ND_PRINT((ndo, " "));
2001-01-30 04:04:00 +08:00
for (i = 0; i < l; i++)
safeputchar(ndo, *p++);
2001-01-30 04:04:00 +08:00
p++; /* skip terminating \0 */
return p - p0;
trunc:
return -1;
}
static int
lwres_printnamelen(netdissect_options *ndo,
const char *p)
2001-01-30 04:04:00 +08:00
{
uint16_t l;
2001-01-30 04:04:00 +08:00
int advance;
if (p + 2 > (const char *)ndo->ndo_snapend)
2001-01-30 04:04:00 +08:00
goto trunc;
l = EXTRACT_BE_U_2(p);
advance = lwres_printname(ndo, l, p + 2);
2001-01-30 04:04:00 +08:00
if (advance < 0)
goto trunc;
return 2 + advance;
trunc:
return -1;
}
static int
lwres_printbinlen(netdissect_options *ndo,
const char *p0)
2001-01-30 04:04:00 +08:00
{
const char *p;
uint16_t l;
2001-01-30 04:04:00 +08:00
int i;
p = p0;
if (p + 2 > (const char *)ndo->ndo_snapend)
2001-01-30 04:04:00 +08:00
goto trunc;
l = EXTRACT_BE_U_2(p);
if (p + 2 + l > (const char *)ndo->ndo_snapend)
2001-01-30 04:04:00 +08:00
goto trunc;
p += 2;
for (i = 0; i < l; i++)
ND_PRINT((ndo, "%02x", *p++));
2001-01-30 04:04:00 +08:00
return p - p0;
trunc:
return -1;
}
static int
lwres_printaddr(netdissect_options *ndo,
2015-04-27 08:24:42 +08:00
const lwres_addr_t *ap)
2001-01-29 17:18:46 +08:00
{
uint16_t l;
2001-01-30 04:04:00 +08:00
const char *p;
int i;
2001-01-29 17:18:46 +08:00
ND_TCHECK(ap->length);
2017-12-31 09:07:06 +08:00
l = EXTRACT_BE_U_2(ap->length);
2001-01-30 04:04:00 +08:00
/* XXX ap points to packed struct */
p = (const char *)&ap->length + sizeof(ap->length);
ND_TCHECK_LEN(p, l);
2001-01-30 04:04:00 +08:00
2017-12-31 09:07:06 +08:00
switch (EXTRACT_BE_U_4(ap->family)) {
2001-01-30 04:04:00 +08:00
case 1: /* IPv4 */
2004-03-24 09:54:29 +08:00
if (l < 4)
return -1;
ND_PRINT((ndo, " %s", ipaddr_string(ndo, p)));
2001-01-30 04:04:00 +08:00
p += sizeof(struct in_addr);
break;
case 2: /* IPv6 */
2004-03-24 09:54:29 +08:00
if (l < 16)
return -1;
ND_PRINT((ndo, " %s", ip6addr_string(ndo, p)));
2001-01-30 04:04:00 +08:00
p += sizeof(struct in6_addr);
break;
default:
2017-12-31 09:07:06 +08:00
ND_PRINT((ndo, " %u/", EXTRACT_BE_U_4(ap->family)));
2001-01-30 04:04:00 +08:00
for (i = 0; i < l; i++)
ND_PRINT((ndo, "%02x", *p++));
2001-01-29 17:18:46 +08:00
}
2001-01-30 04:04:00 +08:00
return p - (const char *)ap;
trunc:
return -1;
2001-01-29 17:18:46 +08:00
}
void
lwres_print(netdissect_options *ndo,
const u_char *bp, u_int length)
2001-01-29 17:18:46 +08:00
{
const struct lwres_lwpacket *np;
uint32_t v;
2001-01-29 17:18:46 +08:00
const char *s;
2001-01-30 04:04:00 +08:00
int response;
int advance;
int unsupported = 0;
2001-01-29 17:18:46 +08:00
np = (const struct lwres_lwpacket *)bp;
ND_TCHECK(np->authlength);
2001-01-29 17:18:46 +08:00
ND_PRINT((ndo, " lwres"));
2017-12-31 09:07:06 +08:00
v = EXTRACT_BE_U_2(np->version);
if (ndo->ndo_vflag || v != LWRES_LWPACKETVERSION_0)
ND_PRINT((ndo, " v%u", v));
2001-01-30 04:04:00 +08:00
if (v != LWRES_LWPACKETVERSION_0) {
2017-12-31 09:07:06 +08:00
s = (const char *)np + EXTRACT_BE_U_4(np->length);
2001-01-30 04:04:00 +08:00
goto tail;
}
2017-12-31 09:07:06 +08:00
response = EXTRACT_BE_U_2(np->pktflags) & LWRES_LWPACKETFLAG_RESPONSE;
2001-01-29 17:18:46 +08:00
2001-01-30 04:04:00 +08:00
/* opcode and pktflags */
2017-12-31 09:07:06 +08:00
v = EXTRACT_BE_U_4(np->opcode);
2001-01-30 04:04:00 +08:00
s = tok2str(opcode, "#0x%x", v);
ND_PRINT((ndo, " %s%s", s, response ? "" : "?"));
2001-01-30 04:04:00 +08:00
/* pktflags */
2017-12-31 09:07:06 +08:00
v = EXTRACT_BE_U_2(np->pktflags);
2001-01-30 04:04:00 +08:00
if (v & ~LWRES_LWPACKETFLAG_RESPONSE)
ND_PRINT((ndo, "[0x%x]", v));
2001-01-29 17:18:46 +08:00
if (ndo->ndo_vflag > 1) {
ND_PRINT((ndo, " (")); /*)*/
2017-12-31 09:07:06 +08:00
ND_PRINT((ndo, "serial:0x%x", EXTRACT_BE_U_4(np->serial)));
ND_PRINT((ndo, " result:0x%x", EXTRACT_BE_U_4(np->result)));
ND_PRINT((ndo, " recvlen:%u", EXTRACT_BE_U_4(np->recvlength)));
2001-01-30 04:04:00 +08:00
/* BIND910: not used */
if (ndo->ndo_vflag > 2) {
2017-12-31 09:07:06 +08:00
ND_PRINT((ndo, " authtype:0x%x", EXTRACT_BE_U_2(np->authtype)));
ND_PRINT((ndo, " authlen:%u", EXTRACT_BE_U_2(np->authlength)));
2001-01-30 04:04:00 +08:00
}
2001-01-29 17:18:46 +08:00
/*(*/
ND_PRINT((ndo, ")"));
2001-01-29 17:18:46 +08:00
}
/* per-opcode content */
2001-01-30 04:04:00 +08:00
if (!response) {
/*
* queries
*/
2015-04-27 08:24:42 +08:00
const lwres_gabnrequest_t *gabn;
const lwres_gnbarequest_t *gnba;
const lwres_grbnrequest_t *grbn;
uint32_t l;
2001-01-30 04:04:00 +08:00
gabn = NULL;
gnba = NULL;
grbn = NULL;
2017-12-31 09:07:06 +08:00
switch (EXTRACT_BE_U_4(np->opcode)) {
2001-01-30 04:04:00 +08:00
case LWRES_OPCODE_NOOP:
break;
case LWRES_OPCODE_GETADDRSBYNAME:
2015-04-27 08:24:42 +08:00
gabn = (const lwres_gabnrequest_t *)(np + 1);
ND_TCHECK(gabn->namelen);
2001-01-30 04:04:00 +08:00
/* XXX gabn points to packed struct */
s = (const char *)&gabn->namelen +
sizeof(gabn->namelen);
2017-12-31 09:07:06 +08:00
l = EXTRACT_BE_U_2(gabn->namelen);
2001-01-30 04:04:00 +08:00
/* BIND910: not used */
if (ndo->ndo_vflag > 2) {
ND_PRINT((ndo, " flags:0x%x",
2017-12-31 09:07:06 +08:00
EXTRACT_BE_U_4(gabn->flags)));
2001-01-30 04:04:00 +08:00
}
2017-12-31 09:07:06 +08:00
v = EXTRACT_BE_U_4(gabn->addrtypes);
2001-01-30 04:04:00 +08:00
switch (v & (LWRES_ADDRTYPE_V4 | LWRES_ADDRTYPE_V6)) {
case LWRES_ADDRTYPE_V4:
ND_PRINT((ndo, " IPv4"));
2001-01-30 04:04:00 +08:00
break;
case LWRES_ADDRTYPE_V6:
ND_PRINT((ndo, " IPv6"));
2001-01-30 04:04:00 +08:00
break;
case LWRES_ADDRTYPE_V4 | LWRES_ADDRTYPE_V6:
ND_PRINT((ndo, " IPv4/6"));
2001-01-30 04:04:00 +08:00
break;
}
if (v & ~(LWRES_ADDRTYPE_V4 | LWRES_ADDRTYPE_V6))
ND_PRINT((ndo, "[0x%x]", v));
2001-01-30 04:04:00 +08:00
advance = lwres_printname(ndo, l, s);
2001-01-30 04:04:00 +08:00
if (advance < 0)
goto trunc;
s += advance;
2001-01-29 17:18:46 +08:00
break;
2001-01-30 04:04:00 +08:00
case LWRES_OPCODE_GETNAMEBYADDR:
2015-04-27 08:24:42 +08:00
gnba = (const lwres_gnbarequest_t *)(np + 1);
ND_TCHECK(gnba->addr);
2001-01-30 04:04:00 +08:00
/* BIND910: not used */
if (ndo->ndo_vflag > 2) {
ND_PRINT((ndo, " flags:0x%x",
2017-12-31 09:07:06 +08:00
EXTRACT_BE_U_4(gnba->flags)));
2001-01-30 04:04:00 +08:00
}
s = (const char *)&gnba->addr;
advance = lwres_printaddr(ndo, &gnba->addr);
2001-01-30 04:04:00 +08:00
if (advance < 0)
goto trunc;
s += advance;
2001-01-29 17:18:46 +08:00
break;
2001-01-30 04:04:00 +08:00
case LWRES_OPCODE_GETRDATABYNAME:
/* XXX no trace, not tested */
2015-04-27 08:24:42 +08:00
grbn = (const lwres_grbnrequest_t *)(np + 1);
ND_TCHECK(grbn->namelen);
2001-01-30 04:04:00 +08:00
/* BIND910: not used */
if (ndo->ndo_vflag > 2) {
ND_PRINT((ndo, " flags:0x%x",
2017-12-31 09:07:06 +08:00
EXTRACT_BE_U_4(grbn->flags)));
2001-01-30 04:04:00 +08:00
}
2017-12-31 09:07:06 +08:00
ND_PRINT((ndo, " %s", tok2str(ns_type2str, "Type%u",
EXTRACT_BE_U_2(grbn->rdtype))));
if (EXTRACT_BE_U_2(grbn->rdclass) != C_IN) {
ND_PRINT((ndo, " %s", tok2str(ns_class2str, "Class%u",
EXTRACT_BE_U_2(grbn->rdclass))));
Add a few more GCC warnings on GCC >= 2 for ".devel" builds. From Neil T. Spring: fixes for many of those warnings: addrtoname.c, configure.in: Linux needs netinet/ether.h for ether_ntohost print-*.c: change char *foo = "bar" to const char *foo = "bar" to appease -Wwrite-strings; should affect no run-time behavior. print-*.c: make some variables unsigned. print-bgp.c: plen ('prefix len') is unsigned, no reason to validate by comparing to zero. print-cnfp.c, print-rx.c: use intoa, provided by addrtoname, instead of inet_ntoa. print-domain.c: unsigned int l; (l=foo()) < 0 is guaranteed to be false, so check for (u_int)-1, which represents failure, explicitly. print-isakmp.c: complete initialization of attrmap objects. print-lwres.c: "if(x); print foo;" seemed much more likely to be intended to be "if(x) { print foo; }". print-smb.c: complete initialization of some structures. In addition, add some fixes for the signed vs. unsigned comparison warnings: extract.h: cast the result of the byte-extraction-and-combining, as, at least for the 16-bit version, C's integral promotions will turn "u_int16_t" into "int" if there are other "int"s nearby. print-*.c: make some more variables unsigned, or add casts to an unsigned type of signed values known not to be negative, or add casts to "int" of unsigned values known to fit in an "int", and make other changes needed to handle the aforementioned variables now being unsigned. print-isakmp.c: clean up the handling of error/status indicators in notify messages. print-ppp.c: get rid of a check that an unsigned quantity is >= 0. print-radius.c: clean up some of the bounds checking. print-smb.c: extract the word count into a "u_int" to avoid the aforementioned problems with C's integral promotions. print-snmp.c: change a check that an unsigned variable is >= 0 to a check that it's != 0. Also, fix some formats to use "%u" rather than "%d" for unsigned quantities.
2002-09-05 08:00:07 +08:00
}
2001-01-30 04:04:00 +08:00
/* XXX grbn points to packed struct */
s = (const char *)&grbn->namelen +
sizeof(grbn->namelen);
2017-12-31 09:07:06 +08:00
l = EXTRACT_BE_U_2(grbn->namelen);
2001-01-30 04:04:00 +08:00
advance = lwres_printname(ndo, l, s);
2001-01-30 04:04:00 +08:00
if (advance < 0)
goto trunc;
s += advance;
break;
default:
unsupported++;
break;
}
} else {
/*
* responses
*/
2015-04-27 08:24:42 +08:00
const lwres_gabnresponse_t *gabn;
const lwres_gnbaresponse_t *gnba;
const lwres_grbnresponse_t *grbn;
uint32_t l, na;
uint32_t i;
2001-01-30 04:04:00 +08:00
gabn = NULL;
gnba = NULL;
grbn = NULL;
2017-12-31 09:07:06 +08:00
switch (EXTRACT_BE_U_4(np->opcode)) {
2001-01-30 04:04:00 +08:00
case LWRES_OPCODE_NOOP:
break;
case LWRES_OPCODE_GETADDRSBYNAME:
2015-04-27 08:24:42 +08:00
gabn = (const lwres_gabnresponse_t *)(np + 1);
ND_TCHECK(gabn->realnamelen);
2001-01-30 04:04:00 +08:00
/* XXX gabn points to packed struct */
s = (const char *)&gabn->realnamelen +
sizeof(gabn->realnamelen);
2017-12-31 09:07:06 +08:00
l = EXTRACT_BE_U_2(gabn->realnamelen);
2001-01-30 04:04:00 +08:00
/* BIND910: not used */
if (ndo->ndo_vflag > 2) {
ND_PRINT((ndo, " flags:0x%x",
2017-12-31 09:07:06 +08:00
EXTRACT_BE_U_4(gabn->flags)));
2001-01-30 04:04:00 +08:00
}
2017-12-31 09:07:06 +08:00
ND_PRINT((ndo, " %u/%u", EXTRACT_BE_U_2(gabn->naliases),
EXTRACT_BE_U_2(gabn->naddrs)));
2001-01-30 04:04:00 +08:00
advance = lwres_printname(ndo, l, s);
2001-01-30 04:04:00 +08:00
if (advance < 0)
goto trunc;
s += advance;
/* aliases */
2017-12-31 09:07:06 +08:00
na = EXTRACT_BE_U_2(gabn->naliases);
2001-01-30 04:04:00 +08:00
for (i = 0; i < na; i++) {
advance = lwres_printnamelen(ndo, s);
2001-01-30 04:04:00 +08:00
if (advance < 0)
goto trunc;
s += advance;
}
/* addrs */
2017-12-31 09:07:06 +08:00
na = EXTRACT_BE_U_2(gabn->naddrs);
2001-01-30 04:04:00 +08:00
for (i = 0; i < na; i++) {
2015-04-27 08:24:42 +08:00
advance = lwres_printaddr(ndo, (const lwres_addr_t *)s);
2001-01-30 04:04:00 +08:00
if (advance < 0)
goto trunc;
s += advance;
}
break;
case LWRES_OPCODE_GETNAMEBYADDR:
2015-04-27 08:24:42 +08:00
gnba = (const lwres_gnbaresponse_t *)(np + 1);
ND_TCHECK(gnba->realnamelen);
2001-01-30 04:04:00 +08:00
/* XXX gnba points to packed struct */
s = (const char *)&gnba->realnamelen +
sizeof(gnba->realnamelen);
2017-12-31 09:07:06 +08:00
l = EXTRACT_BE_U_2(gnba->realnamelen);
2001-01-30 04:04:00 +08:00
/* BIND910: not used */
if (ndo->ndo_vflag > 2) {
ND_PRINT((ndo, " flags:0x%x",
2017-12-31 09:07:06 +08:00
EXTRACT_BE_U_4(gnba->flags)));
2001-01-30 04:04:00 +08:00
}
2017-12-31 09:07:06 +08:00
ND_PRINT((ndo, " %u", EXTRACT_BE_U_2(gnba->naliases)));
2001-01-30 04:04:00 +08:00
advance = lwres_printname(ndo, l, s);
2001-01-30 04:04:00 +08:00
if (advance < 0)
goto trunc;
s += advance;
/* aliases */
2017-12-31 09:07:06 +08:00
na = EXTRACT_BE_U_2(gnba->naliases);
2001-01-30 04:04:00 +08:00
for (i = 0; i < na; i++) {
advance = lwres_printnamelen(ndo, s);
2001-01-30 04:04:00 +08:00
if (advance < 0)
goto trunc;
s += advance;
}
break;
case LWRES_OPCODE_GETRDATABYNAME:
/* XXX no trace, not tested */
2015-04-27 08:24:42 +08:00
grbn = (const lwres_grbnresponse_t *)(np + 1);
ND_TCHECK(grbn->nsigs);
2001-01-30 04:04:00 +08:00
/* BIND910: not used */
if (ndo->ndo_vflag > 2) {
ND_PRINT((ndo, " flags:0x%x",
2017-12-31 09:07:06 +08:00
EXTRACT_BE_U_4(grbn->flags)));
2001-01-30 04:04:00 +08:00
}
2017-12-31 09:07:06 +08:00
ND_PRINT((ndo, " %s", tok2str(ns_type2str, "Type%u",
EXTRACT_BE_U_2(grbn->rdtype))));
if (EXTRACT_BE_U_2(grbn->rdclass) != C_IN) {
ND_PRINT((ndo, " %s", tok2str(ns_class2str, "Class%u",
EXTRACT_BE_U_2(grbn->rdclass))));
Add a few more GCC warnings on GCC >= 2 for ".devel" builds. From Neil T. Spring: fixes for many of those warnings: addrtoname.c, configure.in: Linux needs netinet/ether.h for ether_ntohost print-*.c: change char *foo = "bar" to const char *foo = "bar" to appease -Wwrite-strings; should affect no run-time behavior. print-*.c: make some variables unsigned. print-bgp.c: plen ('prefix len') is unsigned, no reason to validate by comparing to zero. print-cnfp.c, print-rx.c: use intoa, provided by addrtoname, instead of inet_ntoa. print-domain.c: unsigned int l; (l=foo()) < 0 is guaranteed to be false, so check for (u_int)-1, which represents failure, explicitly. print-isakmp.c: complete initialization of attrmap objects. print-lwres.c: "if(x); print foo;" seemed much more likely to be intended to be "if(x) { print foo; }". print-smb.c: complete initialization of some structures. In addition, add some fixes for the signed vs. unsigned comparison warnings: extract.h: cast the result of the byte-extraction-and-combining, as, at least for the 16-bit version, C's integral promotions will turn "u_int16_t" into "int" if there are other "int"s nearby. print-*.c: make some more variables unsigned, or add casts to an unsigned type of signed values known not to be negative, or add casts to "int" of unsigned values known to fit in an "int", and make other changes needed to handle the aforementioned variables now being unsigned. print-isakmp.c: clean up the handling of error/status indicators in notify messages. print-ppp.c: get rid of a check that an unsigned quantity is >= 0. print-radius.c: clean up some of the bounds checking. print-smb.c: extract the word count into a "u_int" to avoid the aforementioned problems with C's integral promotions. print-snmp.c: change a check that an unsigned variable is >= 0 to a check that it's != 0. Also, fix some formats to use "%u" rather than "%d" for unsigned quantities.
2002-09-05 08:00:07 +08:00
}
ND_PRINT((ndo, " TTL "));
unsigned_relts_print(ndo,
2017-12-31 09:07:06 +08:00
EXTRACT_BE_U_4(grbn->ttl));
ND_PRINT((ndo, " %u/%u", EXTRACT_BE_U_2(grbn->nrdatas),
EXTRACT_BE_U_2(grbn->nsigs)));
2001-01-30 04:04:00 +08:00
/* XXX grbn points to packed struct */
s = (const char *)&grbn->nsigs+ sizeof(grbn->nsigs);
advance = lwres_printnamelen(ndo, s);
2001-01-30 04:04:00 +08:00
if (advance < 0)
goto trunc;
s += advance;
/* rdatas */
2017-12-31 09:07:06 +08:00
na = EXTRACT_BE_U_2(grbn->nrdatas);
2001-01-30 04:04:00 +08:00
for (i = 0; i < na; i++) {
/* XXX should decode resource data */
advance = lwres_printbinlen(ndo, s);
2001-01-30 04:04:00 +08:00
if (advance < 0)
goto trunc;
s += advance;
}
/* sigs */
2017-12-31 09:07:06 +08:00
na = EXTRACT_BE_U_2(grbn->nsigs);
2001-01-30 04:04:00 +08:00
for (i = 0; i < na; i++) {
/* XXX how should we print it? */
advance = lwres_printbinlen(ndo, s);
2001-01-30 04:04:00 +08:00
if (advance < 0)
goto trunc;
s += advance;
}
break;
default:
unsupported++;
2001-01-29 17:18:46 +08:00
break;
}
}
2001-01-30 04:04:00 +08:00
tail:
2001-01-29 17:18:46 +08:00
/* length mismatch */
2017-12-31 09:07:06 +08:00
if (EXTRACT_BE_U_4(np->length) != length) {
ND_PRINT((ndo, " [len: %u != %u]", EXTRACT_BE_U_4(np->length),
length));
2001-01-30 04:04:00 +08:00
}
2017-12-31 09:07:06 +08:00
if (!unsupported && s < (const char *)np + EXTRACT_BE_U_4(np->length))
ND_PRINT((ndo, "[extra]"));
2001-01-29 17:18:46 +08:00
return;
trunc:
ND_PRINT((ndo, "[|lwres]"));
2001-01-29 17:18:46 +08:00
}