aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2018-04-14 18:11:35 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2018-04-14 18:11:35 +0200
commitdb93b21ec9c7923dc2c419c81650b070b9ca751a (patch)
tree2d1be5e4cc3354cbf12902e30cff55751fbb7ed9
parent55bc8e8826df8cf5c342f57e513d10ee6c632838 (diff)
downloadbusybox-w32-db93b21ec9c7923dc2c419c81650b070b9ca751a.tar.gz
busybox-w32-db93b21ec9c7923dc2c419c81650b070b9ca751a.tar.bz2
busybox-w32-db93b21ec9c7923dc2c419c81650b070b9ca751a.zip
nslookup: use xmalloc_sockaddr2dotted() instead of homegrown function
function old new delta nslookup_main 2091 2007 -84 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--networking/nslookup.c48
1 files changed, 11 insertions, 37 deletions
diff --git a/networking/nslookup.c b/networking/nslookup.c
index 50d91abbc..2e6569497 100644
--- a/networking/nslookup.c
+++ b/networking/nslookup.c
@@ -557,7 +557,11 @@ static int send_queries(struct ns *ns, struct query *queries, int n_queries)
557 xconnect(pfd.fd, &ns->lsa->u.sa, ns->lsa->len); 557 xconnect(pfd.fd, &ns->lsa->u.sa, ns->lsa->len);
558 ndelay_on(pfd.fd); 558 ndelay_on(pfd.fd);
559 } 559 }
560 write(pfd.fd, queries[qn].query, queries[qn].qlen); 560 if (write(pfd.fd, queries[qn].query, queries[qn].qlen) < 0) {
561 bb_perror_msg("write to '%s'", ns->name);
562 close(pfd.fd);
563 return -1; /* "no go, try next server" */
564 }
561 } 565 }
562 566
563 t1 = t2; 567 t1 = t2;
@@ -710,36 +714,6 @@ static struct query *add_query(struct query **queries, int *n_queries,
710 return new_q; 714 return new_q;
711} 715}
712 716
713//FIXME: use xmalloc_sockaddr2dotted[_noport]() instead of sal2str()
714
715#define SIZEOF_SAL2STR_BUF (INET6_ADDRSTRLEN + 1 + IFNAMSIZ + 1 + 5 + 1)
716static char *sal2str(char buf[SIZEOF_SAL2STR_BUF], len_and_sockaddr *a)
717{
718 char *p = buf;
719
720#if ENABLE_FEATURE_IPV6
721 if (a->u.sa.sa_family == AF_INET6) {
722 inet_ntop(AF_INET6, &a->u.sin6.sin6_addr, buf, SIZEOF_SAL2STR_BUF);
723 p += strlen(p);
724
725 if (a->u.sin6.sin6_scope_id) {
726 if (if_indextoname(a->u.sin6.sin6_scope_id, p + 1)) {
727 *p++ = '%';
728 p += strlen(p);
729 }
730 }
731 } else
732#endif
733 {
734 inet_ntop(AF_INET, &a->u.sin.sin_addr, buf, SIZEOF_SAL2STR_BUF);
735 p += strlen(p);
736 }
737
738 sprintf(p, "#%hu", ntohs(a->u.sin.sin_port));
739
740 return buf;
741}
742
743int nslookup_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 717int nslookup_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
744int nslookup_main(int argc UNUSED_PARAM, char **argv) 718int nslookup_main(int argc UNUSED_PARAM, char **argv)
745{ 719{
@@ -862,10 +836,10 @@ int nslookup_main(int argc UNUSED_PARAM, char **argv)
862 836
863 for (rc = 0; rc < G.serv_count; rc++) { 837 for (rc = 0; rc < G.serv_count; rc++) {
864 int c = send_queries(&G.server[rc], queries, n_queries); 838 int c = send_queries(&G.server[rc], queries, n_queries);
865 if (c < 0)
866 bb_perror_msg_and_die("can't send queries");
867 if (c > 0) 839 if (c > 0)
868 break; 840 break;
841 /* c = 0: timed out waiting for replies */
842 /* c < 0: error (message already printed) */
869 rc++; 843 rc++;
870 if (rc >= G.serv_count) { 844 if (rc >= G.serv_count) {
871 fprintf(stderr, 845 fprintf(stderr,
@@ -875,10 +849,10 @@ int nslookup_main(int argc UNUSED_PARAM, char **argv)
875 } 849 }
876 850
877 printf("Server:\t\t%s\n", G.server[rc].name); 851 printf("Server:\t\t%s\n", G.server[rc].name);
878 { 852 printf("Address:\t%s\n", xmalloc_sockaddr2dotted(&G.server[rc].lsa->u.sa));
879 char buf[SIZEOF_SAL2STR_BUF]; 853 /* In "Address", bind-utils-9.11.3 show port after a hash: "1.2.3.4#53" */
880 printf("Address:\t%s\n", sal2str(buf, G.server[rc].lsa)); 854 /* Should we do the same? */
881 } 855
882 if (opts & OPT_stats) { 856 if (opts & OPT_stats) {
883 printf("Replies:\t%d\n", G.server[rc].replies); 857 printf("Replies:\t%d\n", G.server[rc].replies);
884 printf("Failures:\t%d\n", G.server[rc].failures); 858 printf("Failures:\t%d\n", G.server[rc].failures);