From ba3b9dbf065438402d89655d7baefb0ccc6f0663 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sun, 11 Feb 2018 14:55:46 +0100 Subject: libbb: introduce and use bb_getsockname() function old new delta bb_getsockname - 18 +18 xrtnl_open 88 83 -5 do_iplink 1216 1209 -7 arping_main 1686 1668 -18 ------------------------------------------------------------------------------ (add/remove: 2/0 grow/shrink: 0/3 up/down: 18/-30) Total: -12 bytes Signed-off-by: Denys Vlasenko --- networking/libiproute/iplink.c | 4 +--- networking/libiproute/libnetlink.c | 5 +---- 2 files changed, 2 insertions(+), 7 deletions(-) (limited to 'networking/libiproute') diff --git a/networking/libiproute/iplink.c b/networking/libiproute/iplink.c index aef5f64..f38fba0 100644 --- a/networking/libiproute/iplink.c +++ b/networking/libiproute/iplink.c @@ -132,7 +132,6 @@ static int get_address(char *dev, int *htype) { struct ifreq ifr; struct sockaddr_ll me; - socklen_t alen; int s; s = xsocket(PF_PACKET, SOCK_DGRAM, 0); @@ -146,8 +145,7 @@ 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); - getsockname(s, (struct sockaddr*)&me, &alen); + bb_getsockname(s, (struct sockaddr*)&me, sizeof(me)); //never happens: //if (getsockname(s, (struct sockaddr*)&me, &alen) == -1) // bb_perror_msg_and_die("getsockname"); diff --git a/networking/libiproute/libnetlink.c b/networking/libiproute/libnetlink.c index f08d862..40955fc 100644 --- a/networking/libiproute/libnetlink.c +++ b/networking/libiproute/libnetlink.c @@ -15,16 +15,13 @@ void FAST_FUNC xrtnl_open(struct rtnl_handle *rth/*, unsigned subscriptions*/) { - socklen_t addr_len; - memset(rth, 0, sizeof(*rth)); rth->fd = xsocket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE); 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); + bb_getsockname(rth->fd, (struct sockaddr*)&rth->local, sizeof(rth->local)); /* too much paranoia if (getsockname(rth->fd, (struct sockaddr*)&rth->local, &addr_len) < 0) -- cgit v1.1