diff options
author | Denis Vlasenko | 2009-04-21 23:48:38 +0000 |
---|---|---|
committer | Denis Vlasenko | 2009-04-21 23:48:38 +0000 |
commit | a771e7c0057d0f506f8cdf67be39268e1c9f0735 (patch) | |
tree | bef7afb1304b3510d4857148a50e162a0578c363 /networking | |
parent | e6b10ef0a7a5761c4cd0fe5f48bad953aa92240e (diff) | |
download | busybox-a771e7c0057d0f506f8cdf67be39268e1c9f0735.zip busybox-a771e7c0057d0f506f8cdf67be39268e1c9f0735.tar.gz |
*: 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 'networking')
-rw-r--r-- | networking/arping.c | 15 | ||||
-rw-r--r-- | networking/libiproute/iplink.c | 8 | ||||
-rw-r--r-- | networking/libiproute/libnetlink.c | 9 | ||||
-rw-r--r-- | networking/libiproute/libnetlink.h | 3 | ||||
-rw-r--r-- | networking/nc_bloaty.c | 12 |
5 files changed, 24 insertions, 23 deletions
diff --git a/networking/arping.c b/networking/arping.c index 915af32..ab39c71 100644 --- a/networking/arping.c +++ b/networking/arping.c @@ -348,9 +348,10 @@ int arping_main(int argc UNUSED_PARAM, char **argv) if (setsockopt(probe_fd, SOL_SOCKET, SO_DONTROUTE, &const_int_1, sizeof(const_int_1)) == -1) bb_perror_msg("setsockopt(SO_DONTROUTE)"); xconnect(probe_fd, (struct sockaddr *) &saddr, sizeof(saddr)); - if (getsockname(probe_fd, (struct sockaddr *) &saddr, &alen) == -1) { - bb_perror_msg_and_die("getsockname"); - } + getsockname(probe_fd, (struct sockaddr *) &saddr, &alen); + //never happens: + //if (getsockname(probe_fd, (struct sockaddr *) &saddr, &alen) == -1) + // bb_perror_msg_and_die("getsockname"); if (saddr.sin_family != AF_INET) bb_error_msg_and_die("no IP address configured"); src = saddr.sin_addr; @@ -365,10 +366,10 @@ int arping_main(int argc UNUSED_PARAM, char **argv) { socklen_t alen = sizeof(me); - - if (getsockname(sock_fd, (struct sockaddr *) &me, &alen) == -1) { - bb_perror_msg_and_die("getsockname"); - } + getsockname(sock_fd, (struct sockaddr *) &me, &alen); + //never happens: + //if (getsockname(sock_fd, (struct sockaddr *) &me, &alen) == -1) + // bb_perror_msg_and_die("getsockname"); } if (me.sll_halen == 0) { bb_error_msg(err_str, "is not ARPable (no ll address)"); diff --git a/networking/libiproute/iplink.c b/networking/libiproute/iplink.c index 1e7ee07..de7d640 100644 --- a/networking/libiproute/iplink.c +++ b/networking/libiproute/iplink.c @@ -112,11 +112,11 @@ static int get_address(char *dev, int *htype) me.sll_ifindex = ifr.ifr_ifindex; me.sll_protocol = htons(ETH_P_LOOP); xbind(s, (struct sockaddr*)&me, sizeof(me)); - alen = sizeof(me); - if (getsockname(s, (struct sockaddr*)&me, &alen) == -1) { - bb_perror_msg_and_die("getsockname"); - } + getsockname(s, (struct sockaddr*)&me, &alen); + //never happens: + //if (getsockname(s, (struct sockaddr*)&me, &alen) == -1) + // bb_perror_msg_and_die("getsockname"); close(s); *htype = me.sll_hatype; return me.sll_halen; diff --git a/networking/libiproute/libnetlink.c b/networking/libiproute/libnetlink.c index 6d51d8d..7ad2de9 100644 --- a/networking/libiproute/libnetlink.c +++ b/networking/libiproute/libnetlink.c @@ -26,22 +26,23 @@ int FAST_FUNC xrtnl_open(struct rtnl_handle *rth/*, unsigned subscriptions*/) { socklen_t addr_len; - memset(rth, 0, sizeof(rth)); - + memset(rth, 0, sizeof(*rth)); rth->fd = xsocket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE); - - memset(&rth->local, 0, sizeof(rth->local)); rth->local.nl_family = AF_NETLINK; /*rth->local.nl_groups = subscriptions;*/ xbind(rth->fd, (struct sockaddr*)&rth->local, sizeof(rth->local)); addr_len = sizeof(rth->local); + getsockname(rth->fd, (struct sockaddr*)&rth->local, &addr_len); + +/* too much paranoia if (getsockname(rth->fd, (struct sockaddr*)&rth->local, &addr_len) < 0) bb_perror_msg_and_die("getsockname"); if (addr_len != sizeof(rth->local)) bb_error_msg_and_die("wrong address length %d", addr_len); if (rth->local.nl_family != AF_NETLINK) bb_error_msg_and_die("wrong address family %d", rth->local.nl_family); +*/ rth->seq = time(NULL); return 0; } diff --git a/networking/libiproute/libnetlink.h b/networking/libiproute/libnetlink.h index e5fee4d..11a4a10 100644 --- a/networking/libiproute/libnetlink.h +++ b/networking/libiproute/libnetlink.h @@ -10,8 +10,7 @@ PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN -struct rtnl_handle -{ +struct rtnl_handle { int fd; struct sockaddr_nl local; struct sockaddr_nl peer; diff --git a/networking/nc_bloaty.c b/networking/nc_bloaty.c index 47940e9..efe831e 100644 --- a/networking/nc_bloaty.c +++ b/networking/nc_bloaty.c @@ -278,9 +278,9 @@ static void dolisten(void) random unknown port is probably not very useful without "netstat". */ if (o_verbose) { char *addr; - rr = getsockname(netfd, &ouraddr->u.sa, &ouraddr->len); - if (rr < 0) - bb_perror_msg_and_die("getsockname after bind"); + getsockname(netfd, &ouraddr->u.sa, &ouraddr->len); + //if (rr < 0) + // bb_perror_msg_and_die("getsockname after bind"); addr = xmalloc_sockaddr2dotted(&ouraddr->u.sa); fprintf(stderr, "listening on %s ...\n", addr); free(addr); @@ -359,9 +359,9 @@ create new one, and bind() it. TODO */ doing a listen-on-any on a multihomed machine. This allows one to offer different services via different alias addresses, such as the "virtual web site" hack. */ - rr = getsockname(netfd, &ouraddr->u.sa, &ouraddr->len); - if (rr < 0) - bb_perror_msg_and_die("getsockname after accept"); + getsockname(netfd, &ouraddr->u.sa, &ouraddr->len); + //if (rr < 0) + // bb_perror_msg_and_die("getsockname after accept"); } if (o_verbose) { |