diff options
author | Denis Vlasenko | 2007-11-14 10:18:33 +0000 |
---|---|---|
committer | Denis Vlasenko | 2007-11-14 10:18:33 +0000 |
commit | 9d6c46955fb51d7867e0d8d0ed94006ab72e4821 (patch) | |
tree | ab5d74afb28887ad9ce249e6ba0e1c69844e64e6 /libbb | |
parent | 8d0a734d91ff197a86ce0b8fc892e24a15783395 (diff) | |
download | busybox-9d6c46955fb51d7867e0d8d0ed94006ab72e4821.zip busybox-9d6c46955fb51d7867e0d8d0ed94006ab72e4821.tar.gz |
Introduce FEATURE_PREFER_IPV4_ADDRESS. If selected, we have:
function old new delta
str2sockaddr 328 344 +16
Diffstat (limited to 'libbb')
-rw-r--r-- | libbb/xconnect.c | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/libbb/xconnect.c b/libbb/xconnect.c index cb5ac2c..91c12f4 100644 --- a/libbb/xconnect.c +++ b/libbb/xconnect.c @@ -125,6 +125,7 @@ USE_FEATURE_IPV6(sa_family_t af,) int rc; len_and_sockaddr *r = NULL; struct addrinfo *result = NULL; + struct addrinfo *used_res; const char *org_host = host; /* only for error msg */ const char *cp; struct addrinfo hint; @@ -169,9 +170,21 @@ USE_FEATURE_IPV6(sa_family_t af,) xfunc_die(); goto ret; } - r = xmalloc(offsetof(len_and_sockaddr, sa) + result->ai_addrlen); - r->len = result->ai_addrlen; - memcpy(&r->sa, result->ai_addr, result->ai_addrlen); + used_res = result; +#if ENABLE_FEATURE_PREFER_IPV4_ADDRESS + while (1) { + if (used_res->ai_family == AF_INET) + break; + used_res = used_res->ai_next; + if (!used_res) { + used_res = result; + break; + } + } +#endif + r = xmalloc(offsetof(len_and_sockaddr, sa) + used_res->ai_addrlen); + r->len = used_res->ai_addrlen; + memcpy(&r->sa, used_res->ai_addr, used_res->ai_addrlen); set_nport(r, htons(port)); ret: freeaddrinfo(result); |