diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2009-04-25 13:16:53 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2009-04-25 13:16:53 +0000 |
commit | f6b4685691ebe00f28e4f9148a1a255e87b8d312 (patch) | |
tree | f9445de4ac97a635d2fc8a9deeb29a892a0e81ba /libbb | |
parent | 9ac3dc764a78b51fe8fdcd1b4682850de098733b (diff) | |
download | busybox-w32-f6b4685691ebe00f28e4f9148a1a255e87b8d312.tar.gz busybox-w32-f6b4685691ebe00f28e4f9148a1a255e87b8d312.tar.bz2 busybox-w32-f6b4685691ebe00f28e4f9148a1a255e87b8d312.zip |
add FEATURE_UNIX_LOCAL. By Ingo van Lil (inguin AT gmx.de)
Diffstat (limited to 'libbb')
-rw-r--r-- | libbb/xconnect.c | 24 |
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 @@ | |||
9 | 9 | ||
10 | #include <netinet/in.h> | 10 | #include <netinet/in.h> |
11 | #include <net/if.h> | 11 | #include <net/if.h> |
12 | #include <sys/un.h> | ||
12 | #include "libbb.h" | 13 | #include "libbb.h" |
13 | 14 | ||
14 | void FAST_FUNC setsockopt_reuseaddr(int fd) | 15 | void FAST_FUNC setsockopt_reuseaddr(int fd) |
@@ -160,13 +161,26 @@ IF_FEATURE_IPV6(sa_family_t af,) | |||
160 | int ai_flags) | 161 | int ai_flags) |
161 | { | 162 | { |
162 | int rc; | 163 | int rc; |
163 | len_and_sockaddr *r = NULL; | 164 | len_and_sockaddr *r; |
164 | struct addrinfo *result = NULL; | 165 | struct addrinfo *result = NULL; |
165 | struct addrinfo *used_res; | 166 | struct addrinfo *used_res; |
166 | const char *org_host = host; /* only for error msg */ | 167 | const char *org_host = host; /* only for error msg */ |
167 | const char *cp; | 168 | const char *cp; |
168 | struct addrinfo hint; | 169 | struct addrinfo hint; |
169 | 170 | ||
171 | if (ENABLE_FEATURE_UNIX_LOCAL && strncmp(host, "local:", 6) == 0) { | ||
172 | struct sockaddr_un *sun; | ||
173 | |||
174 | r = xzalloc(LSA_LEN_SIZE + sizeof(struct sockaddr_un)); | ||
175 | r->len = sizeof(struct sockaddr_un); | ||
176 | r->u.sa.sa_family = AF_UNIX; | ||
177 | sun = (struct sockaddr_un *)&r->u.sa; | ||
178 | safe_strncpy(sun->sun_path, host + 6, sizeof(sun->sun_path)); | ||
179 | return r; | ||
180 | } | ||
181 | |||
182 | r = NULL; | ||
183 | |||
170 | /* Ugly parsing of host:addr */ | 184 | /* Ugly parsing of host:addr */ |
171 | if (ENABLE_FEATURE_IPV6 && host[0] == '[') { | 185 | if (ENABLE_FEATURE_IPV6 && host[0] == '[') { |
172 | /* Even uglier parsing of [xx]:nn */ | 186 | /* Even uglier parsing of [xx]:nn */ |
@@ -188,6 +202,7 @@ IF_FEATURE_IPV6(sa_family_t af,) | |||
188 | } | 202 | } |
189 | if (cp) { /* points to ":" or "]:" */ | 203 | if (cp) { /* points to ":" or "]:" */ |
190 | int sz = cp - host + 1; | 204 | int sz = cp - host + 1; |
205 | |||
191 | host = safe_strncpy(alloca(sz), host, sz); | 206 | host = safe_strncpy(alloca(sz), host, sz); |
192 | if (ENABLE_FEATURE_IPV6 && *cp != ':') { | 207 | if (ENABLE_FEATURE_IPV6 && *cp != ':') { |
193 | cp++; /* skip ']' */ | 208 | cp++; /* skip ']' */ |
@@ -371,6 +386,13 @@ static char* FAST_FUNC sockaddr2str(const struct sockaddr *sa, int flags) | |||
371 | int rc; | 386 | int rc; |
372 | socklen_t salen; | 387 | socklen_t salen; |
373 | 388 | ||
389 | if (ENABLE_FEATURE_UNIX_LOCAL && sa->sa_family == AF_UNIX) { | ||
390 | struct sockaddr_un *sun = (struct sockaddr_un *)sa; | ||
391 | return xasprintf("local:%.*s", | ||
392 | (int) sizeof(sun->sun_path), | ||
393 | sun->sun_path); | ||
394 | } | ||
395 | |||
374 | salen = LSA_SIZEOF_SA; | 396 | salen = LSA_SIZEOF_SA; |
375 | #if ENABLE_FEATURE_IPV6 | 397 | #if ENABLE_FEATURE_IPV6 |
376 | if (sa->sa_family == AF_INET) | 398 | if (sa->sa_family == AF_INET) |