summaryrefslogtreecommitdiff
path: root/usr.bin/w/w.c
diff options
context:
space:
mode:
authorHajimu UMEMOTO <ume@FreeBSD.org>2009-11-22 16:51:44 +0000
committerHajimu UMEMOTO <ume@FreeBSD.org>2009-11-22 16:51:44 +0000
commitb94f6865f9cbf1328ac57d9ea342bf735fc2b4b6 (patch)
treef2fe8021b537490927bce18f99a7e10c4efe388f /usr.bin/w/w.c
parenteaa3489312d377f27befcc40ebfc8f9e0460c0b9 (diff)
downloadsrc-test2-b94f6865f9cbf1328ac57d9ea342bf735fc2b4b6.tar.gz
src-test2-b94f6865f9cbf1328ac57d9ea342bf735fc2b4b6.zip
Notes
Diffstat (limited to 'usr.bin/w/w.c')
-rw-r--r--usr.bin/w/w.c42
1 files changed, 31 insertions, 11 deletions
diff --git a/usr.bin/w/w.c b/usr.bin/w/w.c
index 10ec7b04bd22..fca5df9c14af 100644
--- a/usr.bin/w/w.c
+++ b/usr.bin/w/w.c
@@ -348,6 +348,7 @@ main(int argc, char *argv[])
for (ep = ehead; ep != NULL; ep = ep->next) {
char host_buf[UT_HOSTSIZE + 1];
+ struct addrinfo hints, *res;
struct sockaddr_storage ss;
struct sockaddr *sa = (struct sockaddr *)&ss;
struct sockaddr_in *lsin = (struct sockaddr_in *)&ss;
@@ -365,23 +366,42 @@ main(int argc, char *argv[])
else
x_suffix = NULL;
}
+
+ isaddr = 0;
+ memset(&ss, '\0', sizeof(ss));
+ if (inet_pton(AF_INET6, p, &lsin6->sin6_addr) == 1) {
+ lsin6->sin6_len = sizeof(*lsin6);
+ lsin6->sin6_family = AF_INET6;
+ isaddr = 1;
+ } else if (inet_pton(AF_INET, p, &lsin->sin_addr) == 1) {
+ lsin->sin_len = sizeof(*lsin);
+ lsin->sin_family = AF_INET;
+ isaddr = 1;
+ }
if (!nflag) {
/* Attempt to change an IP address into a name */
- isaddr = 0;
- memset(&ss, '\0', sizeof(ss));
- if (inet_pton(AF_INET6, p, &lsin6->sin6_addr) == 1) {
- lsin6->sin6_len = sizeof(*lsin6);
- lsin6->sin6_family = AF_INET6;
- isaddr = 1;
- } else if (inet_pton(AF_INET, p, &lsin->sin_addr) == 1) {
- lsin->sin_len = sizeof(*lsin);
- lsin->sin_family = AF_INET;
- isaddr = 1;
- }
if (isaddr && realhostname_sa(fn, sizeof(fn), sa,
sa->sa_len) == HOSTNAME_FOUND)
p = fn;
+ } else if (!isaddr) {
+ /*
+ * If a host has only one A/AAAA RR, change a
+ * name into an IP address
+ */
+ memset(&hints, 0, sizeof(hints));
+ hints.ai_flags = AI_PASSIVE;
+ hints.ai_family = AF_UNSPEC;
+ hints.ai_socktype = SOCK_STREAM;
+ if (getaddrinfo(p, NULL, &hints, &res) == 0) {
+ if (res->ai_next == NULL &&
+ getnameinfo(res->ai_addr, res->ai_addrlen,
+ fn, sizeof(fn), NULL, 0,
+ NI_NUMERICHOST) == 0)
+ p = fn;
+ freeaddrinfo(res);
+ }
}
+
if (x_suffix) {
(void)snprintf(buf, sizeof(buf), "%s:%s", p, x_suffix);
p = buf;