diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-08-18 18:16:39 +0400 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-08-18 18:16:39 +0400 |
commit | a27a11bb2c033d3e0312dc1d62430a002314686f (patch) | |
tree | 74b32a18cb1e09c4f663a49c27ffa3725d3e4ee5 /libbb | |
parent | b98c26ad684e3aed8f1480458737f1ab90477c9e (diff) |
introduce and use xdup2(int, int)
stop checking whether setsockopt_reuseaddr(int fd) was successful (it always is)
remove second parameter (sockllen) from xmalloc_sockaddr2xxxxx functions
sockaddr2str 142 156 +14
collect_blk 467 474 +7
xdup2 28 33 +5
singlemount 4456 4454 -2
print_host 214 212 -2
nslookup_main 139 137 -2
ftpgetput_main 414 412 -2
udhcpd_main 1258 1255 -3
udhcpc_main 2405 2402 -3
traceroute_main 4125 4122 -3
nc_main 1072 1069 -3
buffer_fill_and_print 76 73 -3
xmalloc_sockaddr2hostonly_noport 18 14 -4
xmalloc_sockaddr2host_noport 18 14 -4
xmalloc_sockaddr2host 15 11 -4
xmalloc_sockaddr2dotted_noport 18 14 -4
xmalloc_sockaddr2dotted 18 14 -4
wget_main 2618 2614 -4
ping_main 393 389 -4
ip_port_str 120 115 -5
dhcprelay_main 1146 1141 -5
dnsd_main 1531 1525 -6
passwd_main 1110 1102 -8
udhcp_kernel_packet 206 197 -9
udhcp_listen_socket 154 144 -10
getty_main 2576 2566 -10
setup 655 640 -15
xmove_fd 51 34 -17
dolisten 759 742 -17
tcpudpsvd_main 1866 1836 -30
startservice 339 299 -40
Diffstat (limited to 'libbb')
-rw-r--r-- | libbb/xconnect.c | 38 | ||||
-rw-r--r-- | libbb/xfuncs.c | 9 |
2 files changed, 31 insertions, 16 deletions
diff --git a/libbb/xconnect.c b/libbb/xconnect.c index b90aa9add..cb5ac2c8e 100644 --- a/libbb/xconnect.c +++ b/libbb/xconnect.c @@ -9,9 +9,9 @@ #include <netinet/in.h> #include "libbb.h" -int setsockopt_reuseaddr(int fd) +void setsockopt_reuseaddr(int fd) { - return setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &const_int_1, sizeof(const_int_1)); + setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &const_int_1, sizeof(const_int_1)); } int setsockopt_broadcast(int fd) { @@ -298,11 +298,21 @@ int xconnect_stream(const len_and_sockaddr *lsa) /* We hijack this constant to mean something else */ /* It doesn't hurt because we will add this bit anyway */ #define IGNORE_PORT NI_NUMERICSERV -static char* sockaddr2str(const struct sockaddr *sa, socklen_t salen, int flags) +static char* sockaddr2str(const struct sockaddr *sa, int flags) { char host[128]; char serv[16]; - int rc = getnameinfo(sa, salen, + int rc; + socklen_t salen; + + salen = LSA_SIZEOF_SA; +#if ENABLE_FEATURE_IPV6 + if (sa->sa_family == AF_INET) + salen = sizeof(struct sockaddr_in); + if (sa->sa_family == AF_INET6) + salen = sizeof(struct sockaddr_in6); +#endif + rc = getnameinfo(sa, salen, host, sizeof(host), /* can do ((flags & IGNORE_PORT) ? NULL : serv) but why bother? */ serv, sizeof(serv), @@ -327,26 +337,26 @@ static char* sockaddr2str(const struct sockaddr *sa, socklen_t salen, int flags) /*return xstrdup(host);*/ } -char* xmalloc_sockaddr2host(const struct sockaddr *sa, socklen_t salen) +char* xmalloc_sockaddr2host(const struct sockaddr *sa) { - return sockaddr2str(sa, salen, 0); + return sockaddr2str(sa, 0); } -char* xmalloc_sockaddr2host_noport(const struct sockaddr *sa, socklen_t salen) +char* xmalloc_sockaddr2host_noport(const struct sockaddr *sa) { - return sockaddr2str(sa, salen, IGNORE_PORT); + return sockaddr2str(sa, IGNORE_PORT); } -char* xmalloc_sockaddr2hostonly_noport(const struct sockaddr *sa, socklen_t salen) +char* xmalloc_sockaddr2hostonly_noport(const struct sockaddr *sa) { - return sockaddr2str(sa, salen, NI_NAMEREQD | IGNORE_PORT); + return sockaddr2str(sa, NI_NAMEREQD | IGNORE_PORT); } -char* xmalloc_sockaddr2dotted(const struct sockaddr *sa, socklen_t salen) +char* xmalloc_sockaddr2dotted(const struct sockaddr *sa) { - return sockaddr2str(sa, salen, NI_NUMERICHOST); + return sockaddr2str(sa, NI_NUMERICHOST); } -char* xmalloc_sockaddr2dotted_noport(const struct sockaddr *sa, socklen_t salen) +char* xmalloc_sockaddr2dotted_noport(const struct sockaddr *sa) { - return sockaddr2str(sa, salen, NI_NUMERICHOST | IGNORE_PORT); + return sockaddr2str(sa, NI_NUMERICHOST | IGNORE_PORT); } diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c index 64061e4f0..5a1090eaf 100644 --- a/libbb/xfuncs.c +++ b/libbb/xfuncs.c @@ -169,13 +169,18 @@ int ndelay_off(int fd) return fcntl(fd, F_SETFL, fcntl(fd,F_GETFL,0) & ~O_NONBLOCK); } +void xdup2(int from, int to) +{ + if (dup2(from, to) != to) + bb_perror_msg_and_die("can't duplicate file descriptor"); +} + // "Renumber" opened fd void xmove_fd(int from, int to) { if (from == to) return; - if (dup2(from, to) != to) - bb_perror_msg_and_die("can't duplicate file descriptor"); + xdup2(from, to); close(from); } |