From f6b4685691ebe00f28e4f9148a1a255e87b8d312 Mon Sep 17 00:00:00 2001 From: Denis Vlasenko Date: Sat, 25 Apr 2009 13:16:53 +0000 Subject: add FEATURE_UNIX_LOCAL. By Ingo van Lil (inguin AT gmx.de) --- libbb/xconnect.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'libbb/xconnect.c') diff --git a/libbb/xconnect.c b/libbb/xconnect.c index f853e9593..85f93b639 100644 --- a/libbb/xconnect.c +++ b/libbb/xconnect.c @@ -9,6 +9,7 @@ #include #include +#include #include "libbb.h" void FAST_FUNC setsockopt_reuseaddr(int fd) @@ -160,13 +161,26 @@ IF_FEATURE_IPV6(sa_family_t af,) int ai_flags) { int rc; - len_and_sockaddr *r = NULL; + len_and_sockaddr *r; struct addrinfo *result = NULL; struct addrinfo *used_res; const char *org_host = host; /* only for error msg */ const char *cp; struct addrinfo hint; + if (ENABLE_FEATURE_UNIX_LOCAL && strncmp(host, "local:", 6) == 0) { + struct sockaddr_un *sun; + + r = xzalloc(LSA_LEN_SIZE + sizeof(struct sockaddr_un)); + r->len = sizeof(struct sockaddr_un); + r->u.sa.sa_family = AF_UNIX; + sun = (struct sockaddr_un *)&r->u.sa; + safe_strncpy(sun->sun_path, host + 6, sizeof(sun->sun_path)); + return r; + } + + r = NULL; + /* Ugly parsing of host:addr */ if (ENABLE_FEATURE_IPV6 && host[0] == '[') { /* Even uglier parsing of [xx]:nn */ @@ -188,6 +202,7 @@ IF_FEATURE_IPV6(sa_family_t af,) } if (cp) { /* points to ":" or "]:" */ int sz = cp - host + 1; + host = safe_strncpy(alloca(sz), host, sz); if (ENABLE_FEATURE_IPV6 && *cp != ':') { cp++; /* skip ']' */ @@ -371,6 +386,13 @@ static char* FAST_FUNC sockaddr2str(const struct sockaddr *sa, int flags) int rc; socklen_t salen; + if (ENABLE_FEATURE_UNIX_LOCAL && sa->sa_family == AF_UNIX) { + struct sockaddr_un *sun = (struct sockaddr_un *)sa; + return xasprintf("local:%.*s", + (int) sizeof(sun->sun_path), + sun->sun_path); + } + salen = LSA_SIZEOF_SA; #if ENABLE_FEATURE_IPV6 if (sa->sa_family == AF_INET) -- cgit v1.2.3