aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2018-04-14 23:08:23 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2018-04-14 23:08:23 +0200
commitcf950cd3eae0c8d1f711163ea1d99d5891f4f392 (patch)
tree7df7f0997256dc006da299eb872d66e2a0137e76
parent71e016d806f0f2c9168e9096546c15996e6a8e20 (diff)
downloadbusybox-w32-cf950cd3eae0c8d1f711163ea1d99d5891f4f392.tar.gz
busybox-w32-cf950cd3eae0c8d1f711163ea1d99d5891f4f392.tar.bz2
busybox-w32-cf950cd3eae0c8d1f711163ea1d99d5891f4f392.zip
nslookup: more closely resemble output format of bind-utils-9.11.3
function old new delta nslookup_main 1880 1832 -48 parse_reply 1022 852 -170 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-218) Total: -218 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--networking/nslookup.c52
1 files changed, 17 insertions, 35 deletions
diff --git a/networking/nslookup.c b/networking/nslookup.c
index 23ab97585..feeec15aa 100644
--- a/networking/nslookup.c
+++ b/networking/nslookup.c
@@ -326,7 +326,7 @@ struct globals {
326} while (0) 326} while (0)
327 327
328static int 328static int
329parse_reply(const unsigned char *msg, size_t len, int *bb_style_counter) 329parse_reply(const unsigned char *msg, size_t len)
330{ 330{
331 ns_msg handle; 331 ns_msg handle;
332 ns_rr rr; 332 ns_rr rr;
@@ -346,36 +346,28 @@ parse_reply(const unsigned char *msg, size_t len, int *bb_style_counter)
346 return -1; 346 return -1;
347 } 347 }
348 348
349 if (bb_style_counter && *bb_style_counter == 1)
350 printf("Name: %s\n", ns_rr_name(rr));
351
352 rdlen = ns_rr_rdlen(rr); 349 rdlen = ns_rr_rdlen(rr);
353 350
354 switch (ns_rr_type(rr)) 351 switch (ns_rr_type(rr))
355 { 352 {
356 case ns_t_a: 353 case ns_t_a:
357 if (rdlen != 4) { 354 if (rdlen != 4) {
358 //fprintf(stderr, "Unexpected A record length\n"); 355 dbg("unexpected A record length %d\n", rdlen);
359 return -1; 356 return -1;
360 } 357 }
361 inet_ntop(AF_INET, ns_rr_rdata(rr), astr, sizeof(astr)); 358 inet_ntop(AF_INET, ns_rr_rdata(rr), astr, sizeof(astr));
362 if (bb_style_counter) 359 printf("Name:\t%s\nAddress: %s\n", ns_rr_name(rr), astr);
363 printf("Address %d: %s\n", (*bb_style_counter)++, astr);
364 else
365 printf("Name:\t%s\nAddress: %s\n", ns_rr_name(rr), astr);
366 break; 360 break;
367 361
368#if ENABLE_FEATURE_IPV6 362#if ENABLE_FEATURE_IPV6
369 case ns_t_aaaa: 363 case ns_t_aaaa:
370 if (rdlen != 16) { 364 if (rdlen != 16) {
371 //fprintf(stderr, "Unexpected AAAA record length\n"); 365 dbg("unexpected AAAA record length %d\n", rdlen);
372 return -1; 366 return -1;
373 } 367 }
374 inet_ntop(AF_INET6, ns_rr_rdata(rr), astr, sizeof(astr)); 368 inet_ntop(AF_INET6, ns_rr_rdata(rr), astr, sizeof(astr));
375 if (bb_style_counter) 369 /* bind-utils-9.11.3 uses the same format for A and AAAA answers */
376 printf("Address %d: %s\n", (*bb_style_counter)++, astr); 370 printf("Name:\t%s\nAddress: %s\n", ns_rr_name(rr), astr);
377 else
378 printf("%s\thas AAAA address %s\n", ns_rr_name(rr), astr);
379 break; 371 break;
380#endif 372#endif
381 373
@@ -393,7 +385,8 @@ parse_reply(const unsigned char *msg, size_t len, int *bb_style_counter)
393 if (!format) 385 if (!format)
394 format = "%s\tname = %s\n"; 386 format = "%s\tname = %s\n";
395 if (ns_name_uncompress(ns_msg_base(handle), ns_msg_end(handle), 387 if (ns_name_uncompress(ns_msg_base(handle), ns_msg_end(handle),
396 ns_rr_rdata(rr), dname, sizeof(dname)) < 0) { 388 ns_rr_rdata(rr), dname, sizeof(dname)) < 0
389 ) {
397 //fprintf(stderr, "Unable to uncompress domain: %s\n", strerror(errno)); 390 //fprintf(stderr, "Unable to uncompress domain: %s\n", strerror(errno));
398 return -1; 391 return -1;
399 } 392 }
@@ -407,7 +400,8 @@ parse_reply(const unsigned char *msg, size_t len, int *bb_style_counter)
407 } 400 }
408 n = ns_get16(ns_rr_rdata(rr)); 401 n = ns_get16(ns_rr_rdata(rr));
409 if (ns_name_uncompress(ns_msg_base(handle), ns_msg_end(handle), 402 if (ns_name_uncompress(ns_msg_base(handle), ns_msg_end(handle),
410 ns_rr_rdata(rr) + 2, dname, sizeof(dname)) < 0) { 403 ns_rr_rdata(rr) + 2, dname, sizeof(dname)) < 0
404 ) {
411 //fprintf(stderr, "Cannot uncompress MX domain: %s\n", strerror(errno)); 405 //fprintf(stderr, "Cannot uncompress MX domain: %s\n", strerror(errno));
412 return -1; 406 return -1;
413 } 407 }
@@ -429,7 +423,7 @@ parse_reply(const unsigned char *msg, size_t len, int *bb_style_counter)
429 423
430 case ns_t_soa: 424 case ns_t_soa:
431 if (rdlen < 20) { 425 if (rdlen < 20) {
432 //fprintf(stderr, "SOA record too short\n"); 426 dbg("SOA record too short:%d\n", rdlen);
433 return -1; 427 return -1;
434 } 428 }
435 429
@@ -438,7 +432,6 @@ parse_reply(const unsigned char *msg, size_t len, int *bb_style_counter)
438 cp = ns_rr_rdata(rr); 432 cp = ns_rr_rdata(rr);
439 n = ns_name_uncompress(ns_msg_base(handle), ns_msg_end(handle), 433 n = ns_name_uncompress(ns_msg_base(handle), ns_msg_end(handle),
440 cp, dname, sizeof(dname)); 434 cp, dname, sizeof(dname));
441
442 if (n < 0) { 435 if (n < 0) {
443 //fprintf(stderr, "Unable to uncompress domain: %s\n", strerror(errno)); 436 //fprintf(stderr, "Unable to uncompress domain: %s\n", strerror(errno));
444 return -1; 437 return -1;
@@ -449,7 +442,6 @@ parse_reply(const unsigned char *msg, size_t len, int *bb_style_counter)
449 442
450 n = ns_name_uncompress(ns_msg_base(handle), ns_msg_end(handle), 443 n = ns_name_uncompress(ns_msg_base(handle), ns_msg_end(handle),
451 cp, dname, sizeof(dname)); 444 cp, dname, sizeof(dname));
452
453 if (n < 0) { 445 if (n < 0) {
454 //fprintf(stderr, "Unable to uncompress domain: %s\n", strerror(errno)); 446 //fprintf(stderr, "Unable to uncompress domain: %s\n", strerror(errno));
455 return -1; 447 return -1;
@@ -725,7 +717,6 @@ int nslookup_main(int argc UNUSED_PARAM, char **argv)
725 struct query *queries; 717 struct query *queries;
726 llist_t *type_strings; 718 llist_t *type_strings;
727 int n_queries; 719 int n_queries;
728 int bb_style_counter = 0;
729 unsigned types; 720 unsigned types;
730 int rc; 721 int rc;
731 int opts; 722 int opts;
@@ -811,7 +802,6 @@ int nslookup_main(int argc UNUSED_PARAM, char **argv)
811 add_query(&queries, &n_queries, T_PTR, ptr); 802 add_query(&queries, &n_queries, T_PTR, ptr);
812 } 803 }
813 else { 804 else {
814 bb_style_counter = 1;
815 add_query(&queries, &n_queries, T_A, *argv); 805 add_query(&queries, &n_queries, T_A, *argv);
816#if ENABLE_FEATURE_IPV6 806#if ENABLE_FEATURE_IPV6
817 add_query(&queries, &n_queries, T_AAAA, *argv); 807 add_query(&queries, &n_queries, T_AAAA, *argv);
@@ -868,7 +858,7 @@ int nslookup_main(int argc UNUSED_PARAM, char **argv)
868 int c; 858 int c;
869 859
870 if (opts & OPT_stats) { 860 if (opts & OPT_stats) {
871 printf("Query #%d completed in %lums:\n", rc, queries[rc].latency); 861 printf("Query #%d completed in %ums:\n", rc, queries[rc].latency);
872 } 862 }
873 863
874 if (queries[rc].rcode != 0) { 864 if (queries[rc].rcode != 0) {
@@ -878,20 +868,13 @@ int nslookup_main(int argc UNUSED_PARAM, char **argv)
878 } 868 }
879 869
880 c = 0; 870 c = 0;
881
882 if (queries[rc].rlen) { 871 if (queries[rc].rlen) {
883 HEADER *header; 872 HEADER *header;
884 873
885 if (!bb_style_counter) { 874 header = (HEADER *)queries[rc].reply;
886 header = (HEADER *)queries[rc].reply; 875 if (!header->aa)
887 if (!header->aa) 876 printf("Non-authoritative answer:\n");
888 printf("Non-authoritative answer:\n"); 877 c = parse_reply(queries[rc].reply, queries[rc].rlen);
889 c = parse_reply(queries[rc].reply, queries[rc].rlen, NULL);
890 }
891 else {
892 c = parse_reply(queries[rc].reply, queries[rc].rlen,
893 &bb_style_counter);
894 }
895 } 878 }
896 879
897 if (c == 0) 880 if (c == 0)
@@ -899,8 +882,7 @@ int nslookup_main(int argc UNUSED_PARAM, char **argv)
899 else if (c < 0) 882 else if (c < 0)
900 printf("*** Can't find %s: Parse error\n", queries[rc].name); 883 printf("*** Can't find %s: Parse error\n", queries[rc].name);
901 884
902 if (!bb_style_counter) 885 bb_putchar('\n');
903 printf("\n");
904 } 886 }
905 887
906 if (ENABLE_FEATURE_CLEAN_UP) { 888 if (ENABLE_FEATURE_CLEAN_UP) {