aboutsummaryrefslogtreecommitdiff
path: root/networking
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2018-04-15 20:04:57 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2018-04-15 20:04:57 +0200
commitc72499584abbf32b3757024bb0cd53f23d5d0d72 (patch)
tree7fca91aa28e251b41ea9e7c330e18942fa821570 /networking
parent71e4b3f4824f94e6e9aae25222c41f8789d80fd6 (diff)
downloadbusybox-c72499584abbf32b3757024bb0cd53f23d5d0d72.tar.gz
nslookup: simplify make_ptr
function old new delta nslookup_main 2644 2611 -33 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'networking')
-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)
return i;
}
-static char *make_ptr(char resbuf[80], const char *addrstr)
-{
- unsigned char addr[16];
- int i;
-
-#if ENABLE_FEATURE_IPV6
- if (inet_pton(AF_INET6, addrstr, addr)) {
- if (memcmp(addr, v4_mapped, 12) != 0) {
- char *ptr = resbuf;
- for (i = 0; i < 16; i++) {
- *ptr++ = 0x20 | bb_hexdigits_upcase[(unsigned char)addr[15 - i] & 0xf];
- *ptr++ = '.';
- *ptr++ = 0x20 | bb_hexdigits_upcase[(unsigned char)addr[15 - i] >> 4];
- *ptr++ = '.';
- }
- strcpy(ptr, "ip6.arpa");
- }
- else {
- sprintf(resbuf, "%u.%u.%u.%u.in-addr.arpa",
- addr[15], addr[14], addr[13], addr[12]);
- }
- return resbuf;
- }
-#endif
-
- if (inet_pton(AF_INET, addrstr, addr)) {
- sprintf(resbuf, "%u.%u.%u.%u.in-addr.arpa",
- addr[3], addr[2], addr[1], addr[0]);
- return resbuf;
- }
-
- return NULL;
-}
-
/*
* Function logic borrowed & modified from musl libc, res_msend.c
* G.query_count is always > 0.
@@ -743,6 +709,38 @@ static void add_query(int type, const char *dname)
new_q->qlen = qlen;
}
+static char *make_ptr(const char *addrstr)
+{
+ unsigned char addr[16];
+ int i;
+
+#if ENABLE_FEATURE_IPV6
+ if (inet_pton(AF_INET6, addrstr, addr)) {
+ if (memcmp(addr, v4_mapped, 12) != 0) {
+ char resbuf[80];
+ char *ptr = resbuf;
+ for (i = 0; i < 16; i++) {
+ *ptr++ = 0x20 | bb_hexdigits_upcase[(unsigned char)addr[15 - i] & 0xf];
+ *ptr++ = '.';
+ *ptr++ = 0x20 | bb_hexdigits_upcase[(unsigned char)addr[15 - i] >> 4];
+ *ptr++ = '.';
+ }
+ strcpy(ptr, "ip6.arpa");
+ return xstrdup(resbuf);
+ }
+ return xasprintf("%u.%u.%u.%u.in-addr.arpa",
+ addr[15], addr[14], addr[13], addr[12]);
+ }
+#endif
+
+ if (inet_pton(AF_INET, addrstr, addr)) {
+ return xasprintf("%u.%u.%u.%u.in-addr.arpa",
+ addr[3], addr[2], addr[1], addr[0]);
+ }
+
+ return NULL;
+}
+
int nslookup_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int nslookup_main(int argc UNUSED_PARAM, char **argv)
{
@@ -843,11 +841,10 @@ int nslookup_main(int argc UNUSED_PARAM, char **argv)
* mimicking the one of the traditional nslookup applet.
*/
char *ptr;
- char buf80[80];
- ptr = make_ptr(buf80, argv[0]);
+ ptr = make_ptr(argv[0]);
if (ptr) {
- add_query(T_PTR, xstrdup(ptr));
+ add_query(T_PTR, ptr);
} else {
add_query(T_A, argv[0]);
#if ENABLE_FEATURE_IPV6