diff options
author | Florian Weimer <fweimer@redhat.com> | 2017-06-30 11:31:35 +0200 |
---|---|---|
committer | Florian Weimer <fweimer@redhat.com> | 2017-06-30 11:31:35 +0200 |
commit | d85f99679d89fb47426301620b7a980388fddcfd (patch) | |
tree | e3bc95de2ce21a0e77a680647a1b3febee8a698b /resolv | |
parent | 4d4ce84924dbde90294522598212e997b5f719e9 (diff) | |
download | glibc-d85f99679d89fb47426301620b7a980388fddcfd.tar.gz glibc-d85f99679d89fb47426301620b7a980388fddcfd.tar.xz glibc-d85f99679d89fb47426301620b7a980388fddcfd.zip |
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.
Diffstat (limited to 'resolv')
-rw-r--r-- | resolv/res_data.c | 40 | ||||
-rw-r--r-- | resolv/res_debug.c | 75 |
2 files changed, 58 insertions, 57 deletions
diff --git a/resolv/res_data.c b/resolv/res_data.c index d907bfc9bd..d05389e134 100644 --- a/resolv/res_data.c +++ b/resolv/res_data.c @@ -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 */ diff --git a/resolv/res_debug.c b/resolv/res_debug.c index e23559bad3..182aeefa1f 100644 --- a/resolv/res_debug.c +++ b/resolv/res_debug.c @@ -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) { |