resolv: Move fp_nquery, fp_query, p_query, _res_opcodes

From res_data.c to res_debug.c.

Also drop the unnecessary _res initialization from fp_nquery.
This commit is contained in:
Florian Weimer 2017-06-30 11:31:35 +02:00
parent 4d4ce84924
commit d85f99679d
4 changed files with 71 additions and 59 deletions

View File

@ -1,3 +1,16 @@
2017-06-30 Florian Weimer <fweimer@redhat.com>
* include/resolv.h (res_pquery): Remove declaration.
* resolv/res_data.c (fp_nquery, fp_query, p_query): Remove
functions.
(_res_opcodes): Remove variable.
* resolv/res_debug.c (do_section): Receive pfcode instead of
statp.
(res_pquery): Rename ...
(fp_nquery): to this function. Skip unnecessary _res
initialization.
(fp_query, p_query, _res_opcodes): Copied from resolv/res_data.c.
2017-06-30 Florian Weimer <fweimer@redhat.com>
* resolv/res_debug.h: Remove file.

View File

@ -32,8 +32,6 @@ extern struct hostent *_gethtbyname2 (const char *__name, int __af);
struct hostent *_gethtbyaddr (const char *addr, size_t __len, int __af);
extern uint32_t _getlong (const unsigned char *__src);
extern uint16_t _getshort (const unsigned char *__src);
extern void res_pquery (const res_state __statp, const unsigned char *__msg,
int __len, FILE *__file);
extern int res_ourserver_p (const res_state __statp,
const struct sockaddr_in6 *__inp);
extern void __res_iclose (res_state statp, bool free_addr);

View File

@ -32,46 +32,6 @@
#include <string.h>
#include <unistd.h>
const char *_res_opcodes[] = {
"QUERY",
"IQUERY",
"CQUERYM",
"CQUERYU", /* experimental */
"NOTIFY", /* experimental */
"UPDATE",
"6",
"7",
"8",
"9",
"10",
"11",
"12",
"13",
"ZONEINIT",
"ZONEREF",
};
libresolv_hidden_data_def (_res_opcodes)
void
p_query(const u_char *msg) {
fp_query(msg, stdout);
}
void
fp_query(const u_char *msg, FILE *file) {
fp_nquery(msg, PACKETSZ, file);
}
libresolv_hidden_def (fp_query)
void
fp_nquery(const u_char *msg, int len, FILE *file) {
if (__res_maybe_init (&_res, 0) == -1)
return;
res_pquery(&_res, msg, len, file);
}
libresolv_hidden_def (fp_nquery)
int
res_query(const char *name, /* domain name */
int class, int type, /* class and type of query */

View File

@ -115,6 +115,27 @@
extern const char *_res_sectioncodes[] attribute_hidden;
const char *_res_opcodes[] =
{
"QUERY",
"IQUERY",
"CQUERYM",
"CQUERYU", /* experimental */
"NOTIFY", /* experimental */
"UPDATE",
"6",
"7",
"8",
"9",
"10",
"11",
"12",
"13",
"ZONEINIT",
"ZONEREF",
};
libresolv_hidden_data_def (_res_opcodes)
static const char *p_section(int section, int opcode);
/*
@ -132,9 +153,7 @@ fp_resstat(const res_state statp, FILE *file) {
}
static void
do_section(const res_state statp,
ns_msg *handle, ns_sect section,
int pflag, FILE *file)
do_section (int pfcode, ns_msg *handle, ns_sect section, int pflag, FILE *file)
{
int n, sflag, rrnum;
static int buflen = 2048;
@ -145,8 +164,8 @@ do_section(const res_state statp,
/*
* Print answer records.
*/
sflag = (statp->pfcode & pflag);
if (statp->pfcode && !sflag)
sflag = (pfcode & pflag);
if (pfcode && !sflag)
return;
buf = malloc(buflen);
@ -163,11 +182,11 @@ do_section(const res_state statp,
fprintf(file, ";; ns_parserr: %s\n",
strerror(errno));
else if (rrnum > 0 && sflag != 0 &&
(statp->pfcode & RES_PRF_HEAD1))
(pfcode & RES_PRF_HEAD1))
putc('\n', file);
goto cleanup;
}
if (rrnum == 0 && sflag != 0 && (statp->pfcode & RES_PRF_HEAD1))
if (rrnum == 0 && sflag != 0 && (pfcode & RES_PRF_HEAD1))
fprintf(file, ";; %s SECTION:\n",
p_section(section, opcode));
if (section == ns_s_qd)
@ -209,11 +228,19 @@ do_section(const res_state statp,
* This is intended to be primarily a debugging routine.
*/
void
res_pquery(const res_state statp, const u_char *msg, int len, FILE *file) {
fp_nquery (const unsigned char *msg, int len, FILE *file)
{
ns_msg handle;
int qdcount, ancount, nscount, arcount;
u_int opcode, rcode, id;
/* There is no need to initialize _res: If _res is not yet
initialized, _res.pfcode is zero. But initialization will
leave it at zero, too. _res.pfcode is an unsigned long,
but the code here assumes that the flags fit into an int,
so use that. */
int pfcode = _res.pfcode;
if (ns_initparse(msg, len, &handle) < 0) {
fprintf(file, ";; ns_initparse: %s\n", strerror(errno));
return;
@ -229,13 +256,13 @@ res_pquery(const res_state statp, const u_char *msg, int len, FILE *file) {
/*
* Print header fields.
*/
if ((!statp->pfcode) || (statp->pfcode & RES_PRF_HEADX) || rcode)
if ((!pfcode) || (pfcode & RES_PRF_HEADX) || rcode)
fprintf(file,
";; ->>HEADER<<- opcode: %s, status: %s, id: %d\n",
_res_opcodes[opcode], p_rcode(rcode), id);
if ((!statp->pfcode) || (statp->pfcode & RES_PRF_HEADX))
if ((!pfcode) || (pfcode & RES_PRF_HEADX))
putc(';', file);
if ((!statp->pfcode) || (statp->pfcode & RES_PRF_HEAD2)) {
if ((!pfcode) || (pfcode & RES_PRF_HEAD2)) {
fprintf(file, "; flags:");
if (ns_msg_getflag(handle, ns_f_qr))
fprintf(file, " qr");
@ -254,7 +281,7 @@ res_pquery(const res_state statp, const u_char *msg, int len, FILE *file) {
if (ns_msg_getflag(handle, ns_f_cd))
fprintf(file, " cd");
}
if ((!statp->pfcode) || (statp->pfcode & RES_PRF_HEAD1)) {
if ((!pfcode) || (pfcode & RES_PRF_HEAD1)) {
fprintf(file, "; %s: %d",
p_section(ns_s_qd, opcode), qdcount);
fprintf(file, ", %s: %d",
@ -264,21 +291,35 @@ res_pquery(const res_state statp, const u_char *msg, int len, FILE *file) {
fprintf(file, ", %s: %d",
p_section(ns_s_ar, opcode), arcount);
}
if ((!statp->pfcode) || (statp->pfcode &
if ((!pfcode) || (pfcode &
(RES_PRF_HEADX | RES_PRF_HEAD2 | RES_PRF_HEAD1))) {
putc('\n',file);
}
/*
* Print the various sections.
*/
do_section(statp, &handle, ns_s_qd, RES_PRF_QUES, file);
do_section(statp, &handle, ns_s_an, RES_PRF_ANS, file);
do_section(statp, &handle, ns_s_ns, RES_PRF_AUTH, file);
do_section(statp, &handle, ns_s_ar, RES_PRF_ADD, file);
do_section (pfcode, &handle, ns_s_qd, RES_PRF_QUES, file);
do_section (pfcode, &handle, ns_s_an, RES_PRF_ANS, file);
do_section (pfcode, &handle, ns_s_ns, RES_PRF_AUTH, file);
do_section (pfcode, &handle, ns_s_ar, RES_PRF_ADD, file);
if (qdcount == 0 && ancount == 0 &&
nscount == 0 && arcount == 0)
putc('\n', file);
}
libresolv_hidden_def (fp_nquery)
void
fp_query (const unsigned char *msg, FILE *file)
{
fp_nquery (msg, PACKETSZ, file);
}
libresolv_hidden_def (fp_query)
void
p_query (const unsigned char *msg)
{
fp_query (msg, stdout);
}
const u_char *
p_cdnname(const u_char *cp, const u_char *msg, int len, FILE *file) {