arping: stop using last gethostbyname2 in the tree
hostname: small optimization
This commit is contained in:
@@ -338,8 +338,6 @@ char* xmalloc_sockaddr2dotted_noport(const struct sockaddr *sa, socklen_t salen)
|
|||||||
// "old" (ipv4 only) API
|
// "old" (ipv4 only) API
|
||||||
// users: traceroute.c hostname.c ifconfig.c ping.c
|
// users: traceroute.c hostname.c ifconfig.c ping.c
|
||||||
struct hostent *xgethostbyname(const char *name);
|
struct hostent *xgethostbyname(const char *name);
|
||||||
//TODO: eliminate gethostbyname2 in arping (the only remaining place),
|
|
||||||
//use host_and_af2sockaddr instead.
|
|
||||||
|
|
||||||
|
|
||||||
extern char *xstrdup(const char *s);
|
extern char *xstrdup(const char *s);
|
||||||
|
@@ -305,13 +305,11 @@ int arping_main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!inet_aton(target, &dst)) {
|
if (!inet_aton(target, &dst)) {
|
||||||
struct hostent *hp;
|
len_and_sockaddr *lsa;
|
||||||
|
lsa = host_and_af2sockaddr(target, 0, AF_INET);
|
||||||
hp = gethostbyname2(target, AF_INET);
|
memcpy(&dst, &lsa->sin.sin_addr.s_addr, 4);
|
||||||
if (!hp) {
|
if (ENABLE_FEATURE_CLEAN_UP)
|
||||||
bb_error_msg_and_die("invalid or unknown target %s", target);
|
free(lsa);
|
||||||
}
|
|
||||||
memcpy(&dst, hp->h_addr, 4);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (source && !inet_aton(source, &src)) {
|
if (source && !inet_aton(source, &src)) {
|
||||||
|
@@ -48,11 +48,12 @@ int hostname_main(int argc, char **argv)
|
|||||||
OPT_f = 0x2,
|
OPT_f = 0x2,
|
||||||
OPT_i = 0x4,
|
OPT_i = 0x4,
|
||||||
OPT_s = 0x8,
|
OPT_s = 0x8,
|
||||||
|
OPT_F = 0x8,
|
||||||
OPT_dfis = 0xf,
|
OPT_dfis = 0xf,
|
||||||
};
|
};
|
||||||
|
|
||||||
char buf[256];
|
char buf[256];
|
||||||
char *hostname_str = NULL;
|
char *hostname_str;
|
||||||
|
|
||||||
if (argc < 1)
|
if (argc < 1)
|
||||||
bb_show_usage();
|
bb_show_usage();
|
||||||
@@ -70,7 +71,7 @@ int hostname_main(int argc, char **argv)
|
|||||||
puts(hp->h_name);
|
puts(hp->h_name);
|
||||||
} else if (option_mask32 & OPT_s) {
|
} else if (option_mask32 & OPT_s) {
|
||||||
if (p != NULL) {
|
if (p != NULL) {
|
||||||
*p = 0;
|
*p = '\0';
|
||||||
}
|
}
|
||||||
puts(hp->h_name);
|
puts(hp->h_name);
|
||||||
} else if (option_mask32 & OPT_d) {
|
} else if (option_mask32 & OPT_d) {
|
||||||
@@ -84,7 +85,7 @@ int hostname_main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Set the hostname */
|
/* Set the hostname */
|
||||||
else if (hostname_str != NULL) {
|
else if (option_mask32 & OPT_F) {
|
||||||
do_sethostname(hostname_str, 1);
|
do_sethostname(hostname_str, 1);
|
||||||
} else if (optind < argc) {
|
} else if (optind < argc) {
|
||||||
do_sethostname(argv[optind], 0);
|
do_sethostname(argv[optind], 0);
|
||||||
|
Reference in New Issue
Block a user