summaryrefslogtreecommitdiff
path: root/libbb/xconnect.c
diff options
context:
space:
mode:
Diffstat (limited to 'libbb/xconnect.c')
-rw-r--r--libbb/xconnect.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/libbb/xconnect.c b/libbb/xconnect.c
index 4b7c110..1c8bb2b 100644
--- a/libbb/xconnect.c
+++ b/libbb/xconnect.c
@@ -322,26 +322,28 @@ len_and_sockaddr* FAST_FUNC xdotted2sockaddr(const char *host, int port)
return str2sockaddr(host, port, AF_UNSPEC, AI_NUMERICHOST | DIE_ON_ERROR);
}
-#undef xsocket_type
-int FAST_FUNC xsocket_type(len_and_sockaddr **lsap, IF_FEATURE_IPV6(int family,) int sock_type)
+int FAST_FUNC xsocket_type(len_and_sockaddr **lsap, int family, int sock_type)
{
- IF_NOT_FEATURE_IPV6(enum { family = AF_INET };)
len_and_sockaddr *lsa;
int fd;
int len;
-#if ENABLE_FEATURE_IPV6
if (family == AF_UNSPEC) {
+#if ENABLE_FEATURE_IPV6
fd = socket(AF_INET6, sock_type, 0);
if (fd >= 0) {
family = AF_INET6;
goto done;
}
+#endif
family = AF_INET;
}
-#endif
+
fd = xsocket(family, sock_type, 0);
+
len = sizeof(struct sockaddr_in);
+ if (family == AF_UNIX)
+ len = sizeof(struct sockaddr_un);
#if ENABLE_FEATURE_IPV6
if (family == AF_INET6) {
done:
@@ -357,7 +359,7 @@ int FAST_FUNC xsocket_type(len_and_sockaddr **lsap, IF_FEATURE_IPV6(int family,)
int FAST_FUNC xsocket_stream(len_and_sockaddr **lsap)
{
- return xsocket_type(lsap, IF_FEATURE_IPV6(AF_UNSPEC,) SOCK_STREAM);
+ return xsocket_type(lsap, AF_UNSPEC, SOCK_STREAM);
}
static 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)
/* user specified bind addr dictates family */
fd = xsocket(lsa->u.sa.sa_family, sock_type, 0);
} else {
- fd = xsocket_type(&lsa, IF_FEATURE_IPV6(AF_UNSPEC,) sock_type);
+ fd = xsocket_type(&lsa, AF_UNSPEC, sock_type);
set_nport(&lsa->u.sa, htons(port));
}
setsockopt_reuseaddr(fd);