diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-01-22 22:43:05 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-01-22 22:43:05 +0000 |
commit | 448f0241e06e7df2003b7f8afcf01e7406762b4e (patch) | |
tree | bc4a002a534b4c0fb8bba09dbd46f93cea5a38c6 /libbb | |
parent | fdcd7c4237a99682724ffbf4e40ab50a40197c56 (diff) |
nslookup: full circle. Here we started IPv6 work. Use "new API"
and thus save a few bytes.
Diffstat (limited to 'libbb')
-rw-r--r-- | libbb/xconnect.c | 24 |
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) return fd; } +/* We hijack this constant to mean something else */ +/* It doesn't hurt because we will add this bit anyway */ +#define IGNORE_PORT NI_NUMERICSERV static char* sockaddr2str(const struct sockaddr *sa, socklen_t salen, int flags) { char host[128]; char serv[16]; int rc = getnameinfo(sa, salen, host, sizeof(host), + /* can do ((flags & IGNORE_PORT) ? NULL : serv) but why bother? */ serv, sizeof(serv), /* do not resolve port# into service _name_ */ flags | NI_NUMERICSERV ); if (rc) return NULL; + if (flags & IGNORE_PORT) + return xstrdup(host); #if ENABLE_FEATURE_IPV6 - if (sa->sa_family == AF_INET6) - return xasprintf("[%s]:%s", host, serv); + if (sa->sa_family == AF_INET6) { + if (strchr(host, ':')) /* heh, it's not a resolved hostname */ + return xasprintf("[%s]:%s", host, serv); + /*return xasprintf("%s:%s", host, serv);*/ + /* - fall through instead */ + } #endif /* For now we don't support anything else, so it has to be INET */ /*if (sa->sa_family == AF_INET)*/ return xasprintf("%s:%s", host, serv); + /*return xstrdup(host);*/ } char* xmalloc_sockaddr2host(const struct sockaddr *sa, socklen_t salen) @@ -271,7 +282,16 @@ char* xmalloc_sockaddr2host(const struct sockaddr *sa, socklen_t salen) return sockaddr2str(sa, salen, 0); } +char* xmalloc_sockaddr2hostonly_noport(const struct sockaddr *sa, socklen_t salen) +{ + return sockaddr2str(sa, salen, NI_NAMEREQD | IGNORE_PORT); +} char* xmalloc_sockaddr2dotted(const struct sockaddr *sa, socklen_t salen) { return sockaddr2str(sa, salen, NI_NUMERICHOST); } + +char* xmalloc_sockaddr2dotted_noport(const struct sockaddr *sa, socklen_t salen) +{ + return sockaddr2str(sa, salen, NI_NUMERICHOST | IGNORE_PORT); +} |