aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--networking/nslookup.c71
1 files changed, 34 insertions, 37 deletions
diff --git a/networking/nslookup.c b/networking/nslookup.c
index 99f781e1b..fd241a5ca 100644
--- a/networking/nslookup.c
+++ b/networking/nslookup.c
@@ -484,40 +484,6 @@ static int parse_reply(const unsigned char *msg, size_t len)
484 return i; 484 return i;
485} 485}
486 486
487static char *make_ptr(char resbuf[80], const char *addrstr)
488{
489 unsigned char addr[16];
490 int i;
491
492#if ENABLE_FEATURE_IPV6
493 if (inet_pton(AF_INET6, addrstr, addr)) {
494 if (memcmp(addr, v4_mapped, 12) != 0) {
495 char *ptr = resbuf;
496 for (i = 0; i < 16; i++) {
497 *ptr++ = 0x20 | bb_hexdigits_upcase[(unsigned char)addr[15 - i] & 0xf];
498 *ptr++ = '.';
499 *ptr++ = 0x20 | bb_hexdigits_upcase[(unsigned char)addr[15 - i] >> 4];
500 *ptr++ = '.';
501 }
502 strcpy(ptr, "ip6.arpa");
503 }
504 else {
505 sprintf(resbuf, "%u.%u.%u.%u.in-addr.arpa",
506 addr[15], addr[14], addr[13], addr[12]);
507 }
508 return resbuf;
509 }
510#endif
511
512 if (inet_pton(AF_INET, addrstr, addr)) {
513 sprintf(resbuf, "%u.%u.%u.%u.in-addr.arpa",
514 addr[3], addr[2], addr[1], addr[0]);
515 return resbuf;
516 }
517
518 return NULL;
519}
520
521/* 487/*
522 * Function logic borrowed & modified from musl libc, res_msend.c 488 * Function logic borrowed & modified from musl libc, res_msend.c
523 * G.query_count is always > 0. 489 * G.query_count is always > 0.
@@ -743,6 +709,38 @@ static void add_query(int type, const char *dname)
743 new_q->qlen = qlen; 709 new_q->qlen = qlen;
744} 710}
745 711
712static char *make_ptr(const char *addrstr)
713{
714 unsigned char addr[16];
715 int i;
716
717#if ENABLE_FEATURE_IPV6
718 if (inet_pton(AF_INET6, addrstr, addr)) {
719 if (memcmp(addr, v4_mapped, 12) != 0) {
720 char resbuf[80];
721 char *ptr = resbuf;
722 for (i = 0; i < 16; i++) {
723 *ptr++ = 0x20 | bb_hexdigits_upcase[(unsigned char)addr[15 - i] & 0xf];
724 *ptr++ = '.';
725 *ptr++ = 0x20 | bb_hexdigits_upcase[(unsigned char)addr[15 - i] >> 4];
726 *ptr++ = '.';
727 }
728 strcpy(ptr, "ip6.arpa");
729 return xstrdup(resbuf);
730 }
731 return xasprintf("%u.%u.%u.%u.in-addr.arpa",
732 addr[15], addr[14], addr[13], addr[12]);
733 }
734#endif
735
736 if (inet_pton(AF_INET, addrstr, addr)) {
737 return xasprintf("%u.%u.%u.%u.in-addr.arpa",
738 addr[3], addr[2], addr[1], addr[0]);
739 }
740
741 return NULL;
742}
743
746int nslookup_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 744int nslookup_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
747int nslookup_main(int argc UNUSED_PARAM, char **argv) 745int nslookup_main(int argc UNUSED_PARAM, char **argv)
748{ 746{
@@ -843,11 +841,10 @@ int nslookup_main(int argc UNUSED_PARAM, char **argv)
843 * mimicking the one of the traditional nslookup applet. 841 * mimicking the one of the traditional nslookup applet.
844 */ 842 */
845 char *ptr; 843 char *ptr;
846 char buf80[80];
847 844
848 ptr = make_ptr(buf80, argv[0]); 845 ptr = make_ptr(argv[0]);
849 if (ptr) { 846 if (ptr) {
850 add_query(T_PTR, xstrdup(ptr)); 847 add_query(T_PTR, ptr);
851 } else { 848 } else {
852 add_query(T_A, argv[0]); 849 add_query(T_A, argv[0]);
853#if ENABLE_FEATURE_IPV6 850#if ENABLE_FEATURE_IPV6