aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonh Wendell <jonh.wendell@vexcorp.com>2012-02-09 15:14:33 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2012-02-09 15:14:33 +0100
commit9106107a509cfb23806e46765ea2704cdd130654 (patch)
treedbc6ac28d378479b3b841c763e9b1c4bd49e9ef9
parent638dbc34b3dd2a6e340a2370056913ed5770d196 (diff)
downloadbusybox-w32-9106107a509cfb23806e46765ea2704cdd130654.tar.gz
busybox-w32-9106107a509cfb23806e46765ea2704cdd130654.tar.bz2
busybox-w32-9106107a509cfb23806e46765ea2704cdd130654.zip
Make unix (local) sockets work without IPv6 enabled
The xsocket_type() function had an optional "family" argument that was enabled only if IPv6 is enabled. In the case of the function was called with a valid AF_UNIX argument, and IPv6 is disabled, this argument was silently ignored. This patch makes the "family" argument mandatory, while keeping the old behavior i.e., if AF_UNSPEC is passed, we try first IPv6 (if it's enabled) and fallback to IPv4. Also I changed all callers of xsocket_type() to reflect its new interface. Signed-off-by: Jonh Wendell <jonh.wendell@vexcorp.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--include/libbb.h5
-rw-r--r--libbb/xconnect.c16
2 files changed, 9 insertions, 12 deletions
diff --git a/include/libbb.h b/include/libbb.h
index 4975b97fe..f743bdfc6 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -568,12 +568,7 @@ enum {
568 * and if kernel doesn't support it, fall back to IPv4. 568 * and if kernel doesn't support it, fall back to IPv4.
569 * This is useful if you plan to bind to resulting local lsa. 569 * This is useful if you plan to bind to resulting local lsa.
570 */ 570 */
571#if ENABLE_FEATURE_IPV6
572int xsocket_type(len_and_sockaddr **lsap, int af, int sock_type) FAST_FUNC; 571int xsocket_type(len_and_sockaddr **lsap, int af, int sock_type) FAST_FUNC;
573#else
574int xsocket_type(len_and_sockaddr **lsap, int sock_type) FAST_FUNC;
575#define xsocket_type(lsap, af, sock_type) xsocket_type((lsap), (sock_type))
576#endif
577int xsocket_stream(len_and_sockaddr **lsap) FAST_FUNC; 572int xsocket_stream(len_and_sockaddr **lsap) FAST_FUNC;
578/* Create server socket bound to bindaddr:port. bindaddr can be NULL, 573/* Create server socket bound to bindaddr:port. bindaddr can be NULL,
579 * numeric IP ("N.N.N.N") or numeric IPv6 address, 574 * numeric IP ("N.N.N.N") or numeric IPv6 address,
diff --git a/libbb/xconnect.c b/libbb/xconnect.c
index 4b7c110d3..1c8bb2b73 100644
--- a/libbb/xconnect.c
+++ b/libbb/xconnect.c
@@ -322,26 +322,28 @@ len_and_sockaddr* FAST_FUNC xdotted2sockaddr(const char *host, int port)
322 return str2sockaddr(host, port, AF_UNSPEC, AI_NUMERICHOST | DIE_ON_ERROR); 322 return str2sockaddr(host, port, AF_UNSPEC, AI_NUMERICHOST | DIE_ON_ERROR);
323} 323}
324 324
325#undef xsocket_type 325int FAST_FUNC xsocket_type(len_and_sockaddr **lsap, int family, int sock_type)
326int FAST_FUNC xsocket_type(len_and_sockaddr **lsap, IF_FEATURE_IPV6(int family,) int sock_type)
327{ 326{
328 IF_NOT_FEATURE_IPV6(enum { family = AF_INET };)
329 len_and_sockaddr *lsa; 327 len_and_sockaddr *lsa;
330 int fd; 328 int fd;
331 int len; 329 int len;
332 330
333#if ENABLE_FEATURE_IPV6
334 if (family == AF_UNSPEC) { 331 if (family == AF_UNSPEC) {
332#if ENABLE_FEATURE_IPV6
335 fd = socket(AF_INET6, sock_type, 0); 333 fd = socket(AF_INET6, sock_type, 0);
336 if (fd >= 0) { 334 if (fd >= 0) {
337 family = AF_INET6; 335 family = AF_INET6;
338 goto done; 336 goto done;
339 } 337 }
338#endif
340 family = AF_INET; 339 family = AF_INET;
341 } 340 }
342#endif 341
343 fd = xsocket(family, sock_type, 0); 342 fd = xsocket(family, sock_type, 0);
343
344 len = sizeof(struct sockaddr_in); 344 len = sizeof(struct sockaddr_in);
345 if (family == AF_UNIX)
346 len = sizeof(struct sockaddr_un);
345#if ENABLE_FEATURE_IPV6 347#if ENABLE_FEATURE_IPV6
346 if (family == AF_INET6) { 348 if (family == AF_INET6) {
347 done: 349 done:
@@ -357,7 +359,7 @@ int FAST_FUNC xsocket_type(len_and_sockaddr **lsap, IF_FEATURE_IPV6(int family,)
357 359
358int FAST_FUNC xsocket_stream(len_and_sockaddr **lsap) 360int FAST_FUNC xsocket_stream(len_and_sockaddr **lsap)
359{ 361{
360 return xsocket_type(lsap, IF_FEATURE_IPV6(AF_UNSPEC,) SOCK_STREAM); 362 return xsocket_type(lsap, AF_UNSPEC, SOCK_STREAM);
361} 363}
362 364
363static int create_and_bind_or_die(const char *bindaddr, int port, int sock_type) 365static int create_and_bind_or_die(const char *bindaddr, int port, int sock_type)
@@ -370,7 +372,7 @@ static int create_and_bind_or_die(const char *bindaddr, int port, int sock_type)
370 /* user specified bind addr dictates family */ 372 /* user specified bind addr dictates family */
371 fd = xsocket(lsa->u.sa.sa_family, sock_type, 0); 373 fd = xsocket(lsa->u.sa.sa_family, sock_type, 0);
372 } else { 374 } else {
373 fd = xsocket_type(&lsa, IF_FEATURE_IPV6(AF_UNSPEC,) sock_type); 375 fd = xsocket_type(&lsa, AF_UNSPEC, sock_type);
374 set_nport(&lsa->u.sa, htons(port)); 376 set_nport(&lsa->u.sa, htons(port));
375 } 377 }
376 setsockopt_reuseaddr(fd); 378 setsockopt_reuseaddr(fd);