diff options
author | Denis Vlasenko | 2006-11-22 23:22:06 +0000 |
---|---|---|
committer | Denis Vlasenko | 2006-11-22 23:22:06 +0000 |
commit | 48237b0c88343154d58854020c3a9c8b07c61b10 (patch) | |
tree | b36bc84f22dd797b45c8d665e50e2f6c690e1370 /libbb | |
parent | b40bdb383a6b7a7f0fd36d0b1cc24deb42cd5f0d (diff) | |
download | busybox-48237b0c88343154d58854020c3a9c8b07c61b10.zip busybox-48237b0c88343154d58854020c3a9c8b07c61b10.tar.gz |
introduce setsockopt_reuseaddr(int fd), setsockopt_broadcast(int fd),
use them where appropriate. 200 bytes saved
Diffstat (limited to 'libbb')
-rw-r--r-- | libbb/xconnect.c | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/libbb/xconnect.c b/libbb/xconnect.c index 9f95e38..b856480 100644 --- a/libbb/xconnect.c +++ b/libbb/xconnect.c @@ -67,6 +67,16 @@ int xconnect_tcp_v4(struct sockaddr_in *s_addr) return s; } +static const int one = 1; +int setsockopt_reuseaddr(int fd) +{ + return setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)); +} +int setsockopt_broadcast(int fd) +{ + return setsockopt(fd, SOL_SOCKET, SO_BROADCAST, &one, sizeof(one)); +} + int dotted2sockaddr(const char *dotted, struct sockaddr* sp, int socklen) { union { @@ -116,7 +126,6 @@ int xsocket_stream_ip4or6(sa_family_t *fp) int create_and_bind_socket_ip4or6(const char *hostaddr, int port) { - static const int on = 1; int fd; sockaddr_inet sa; @@ -128,7 +137,7 @@ int create_and_bind_socket_ip4or6(const char *hostaddr, int port) fd = xsocket(sa.sa.sa_family, SOCK_STREAM, 0); } else fd = xsocket_stream_ip4or6(&sa.sa.sa_family); - setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)); + setsockopt_reuseaddr(fd); /* if (port >= 0) { */ #if ENABLE_FEATURE_IPV6 |