aboutsummaryrefslogtreecommitdiff
path: root/libbb/xconnect.c
diff options
context:
space:
mode:
authorGravatar Denis Vlasenko <vda.linux@googlemail.com>2009-04-21 23:48:38 +0000
committerGravatar Denis Vlasenko <vda.linux@googlemail.com>2009-04-21 23:48:38 +0000
commita771e7c0057d0f506f8cdf67be39268e1c9f0735 (patch)
treebef7afb1304b3510d4857148a50e162a0578c363 /libbb/xconnect.c
parente6b10ef0a7a5761c4cd0fe5f48bad953aa92240e (diff)
downloadbusybox-a771e7c0057d0f506f8cdf67be39268e1c9f0735.tar.gz
busybox-a771e7c0057d0f506f8cdf67be39268e1c9f0735.tar.bz2
*: remove check for errors on getsockaddr in cases we know they can't happen
libbb: make get_sock_lsa use only one getsockaddr syscall, not two function old new delta get_sock_lsa 72 101 +29 do_iplink 1151 1137 -14 arping_main 1585 1569 -16 dolisten 789 755 -34 xrtnl_open 161 94 -67
Diffstat (limited to 'libbb/xconnect.c')
-rw-r--r--libbb/xconnect.c21
1 files changed, 13 insertions, 8 deletions
diff --git a/libbb/xconnect.c b/libbb/xconnect.c
index 1b4f4f78a..f853e9593 100644
--- a/libbb/xconnect.c
+++ b/libbb/xconnect.c
@@ -37,16 +37,21 @@ int FAST_FUNC setsockopt_bindtodevice(int fd, const char *iface)
len_and_sockaddr* FAST_FUNC get_sock_lsa(int fd)
{
- len_and_sockaddr *lsa;
- socklen_t len = 0;
+ len_and_sockaddr lsa;
+ len_and_sockaddr *lsa_ptr;
- /* Can be optimized to do only one getsockname() */
- if (getsockname(fd, NULL, &len) != 0)
+ lsa.len = LSA_SIZEOF_SA;
+ if (getsockname(fd, &lsa.u.sa, &lsa.len) != 0)
return NULL;
- lsa = xzalloc(LSA_LEN_SIZE + len);
- lsa->len = len;
- getsockname(fd, &lsa->u.sa, &lsa->len);
- return lsa;
+
+ lsa_ptr = xzalloc(LSA_LEN_SIZE + lsa.len);
+ if (lsa.len > LSA_SIZEOF_SA) { /* rarely (if ever) happens */
+ lsa_ptr->len = lsa.len;
+ getsockname(fd, &lsa_ptr->u.sa, &lsa_ptr->len);
+ } else {
+ memcpy(lsa_ptr, &lsa, LSA_LEN_SIZE + lsa.len);
+ }
+ return lsa_ptr;
}
void FAST_FUNC xconnect(int s, const struct sockaddr *s_addr, socklen_t addrlen)