aboutsummaryrefslogtreecommitdiff
path: root/libbb/xconnect.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-01-22 22:43:05 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-01-22 22:43:05 +0000
commit448f0241e06e7df2003b7f8afcf01e7406762b4e (patch)
treebc4a002a534b4c0fb8bba09dbd46f93cea5a38c6 /libbb/xconnect.c
parentfdcd7c4237a99682724ffbf4e40ab50a40197c56 (diff)
downloadbusybox-w32-448f0241e06e7df2003b7f8afcf01e7406762b4e.tar.gz
busybox-w32-448f0241e06e7df2003b7f8afcf01e7406762b4e.tar.bz2
busybox-w32-448f0241e06e7df2003b7f8afcf01e7406762b4e.zip
nslookup: full circle. Here we started IPv6 work. Use "new API"
and thus save a few bytes.
Diffstat (limited to 'libbb/xconnect.c')
-rw-r--r--libbb/xconnect.c24
1 files changed, 22 insertions, 2 deletions
diff --git a/libbb/xconnect.c b/libbb/xconnect.c
index 0addda157..188837e36 100644
--- a/libbb/xconnect.c
+++ b/libbb/xconnect.c
@@ -245,25 +245,36 @@ int xconnect_stream(const len_and_sockaddr *lsa)
245 return fd; 245 return fd;
246} 246}
247 247
248/* We hijack this constant to mean something else */
249/* It doesn't hurt because we will add this bit anyway */
250#define IGNORE_PORT NI_NUMERICSERV
248static char* sockaddr2str(const struct sockaddr *sa, socklen_t salen, int flags) 251static char* sockaddr2str(const struct sockaddr *sa, socklen_t salen, int flags)
249{ 252{
250 char host[128]; 253 char host[128];
251 char serv[16]; 254 char serv[16];
252 int rc = getnameinfo(sa, salen, 255 int rc = getnameinfo(sa, salen,
253 host, sizeof(host), 256 host, sizeof(host),
257 /* can do ((flags & IGNORE_PORT) ? NULL : serv) but why bother? */
254 serv, sizeof(serv), 258 serv, sizeof(serv),
255 /* do not resolve port# into service _name_ */ 259 /* do not resolve port# into service _name_ */
256 flags | NI_NUMERICSERV 260 flags | NI_NUMERICSERV
257 ); 261 );
258 if (rc) 262 if (rc)
259 return NULL; 263 return NULL;
264 if (flags & IGNORE_PORT)
265 return xstrdup(host);
260#if ENABLE_FEATURE_IPV6 266#if ENABLE_FEATURE_IPV6
261 if (sa->sa_family == AF_INET6) 267 if (sa->sa_family == AF_INET6) {
262 return xasprintf("[%s]:%s", host, serv); 268 if (strchr(host, ':')) /* heh, it's not a resolved hostname */
269 return xasprintf("[%s]:%s", host, serv);
270 /*return xasprintf("%s:%s", host, serv);*/
271 /* - fall through instead */
272 }
263#endif 273#endif
264 /* For now we don't support anything else, so it has to be INET */ 274 /* For now we don't support anything else, so it has to be INET */
265 /*if (sa->sa_family == AF_INET)*/ 275 /*if (sa->sa_family == AF_INET)*/
266 return xasprintf("%s:%s", host, serv); 276 return xasprintf("%s:%s", host, serv);
277 /*return xstrdup(host);*/
267} 278}
268 279
269char* xmalloc_sockaddr2host(const struct sockaddr *sa, socklen_t salen) 280char* xmalloc_sockaddr2host(const struct sockaddr *sa, socklen_t salen)
@@ -271,7 +282,16 @@ char* xmalloc_sockaddr2host(const struct sockaddr *sa, socklen_t salen)
271 return sockaddr2str(sa, salen, 0); 282 return sockaddr2str(sa, salen, 0);
272} 283}
273 284
285char* xmalloc_sockaddr2hostonly_noport(const struct sockaddr *sa, socklen_t salen)
286{
287 return sockaddr2str(sa, salen, NI_NAMEREQD | IGNORE_PORT);
288}
274char* xmalloc_sockaddr2dotted(const struct sockaddr *sa, socklen_t salen) 289char* xmalloc_sockaddr2dotted(const struct sockaddr *sa, socklen_t salen)
275{ 290{
276 return sockaddr2str(sa, salen, NI_NUMERICHOST); 291 return sockaddr2str(sa, salen, NI_NUMERICHOST);
277} 292}
293
294char* xmalloc_sockaddr2dotted_noport(const struct sockaddr *sa, socklen_t salen)
295{
296 return sockaddr2str(sa, salen, NI_NUMERICHOST | IGNORE_PORT);
297}