aboutsummaryrefslogtreecommitdiff
path: root/libbb/xconnect.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2009-04-25 13:16:53 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2009-04-25 13:16:53 +0000
commitf6b4685691ebe00f28e4f9148a1a255e87b8d312 (patch)
treef9445de4ac97a635d2fc8a9deeb29a892a0e81ba /libbb/xconnect.c
parent9ac3dc764a78b51fe8fdcd1b4682850de098733b (diff)
downloadbusybox-f6b4685691ebe00f28e4f9148a1a255e87b8d312.tar.gz
add FEATURE_UNIX_LOCAL. By Ingo van Lil (inguin AT gmx.de)
Diffstat (limited to 'libbb/xconnect.c')
-rw-r--r--libbb/xconnect.c24
1 files changed, 23 insertions, 1 deletions
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 <netinet/in.h>
#include <net/if.h>
+#include <sys/un.h>
#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)