summaryrefslogtreecommitdiffstats
path: root/usr.bin/w
diff options
context:
space:
mode:
authorume <ume@FreeBSD.org>2009-11-22 16:51:44 +0000
committerume <ume@FreeBSD.org>2009-11-22 16:51:44 +0000
commitba91da3aff4fb68aa0ec546f7eeb21855b267fc7 (patch)
treef2fe8021b537490927bce18f99a7e10c4efe388f /usr.bin/w
parent20812b17e03ee11696a188bf6ff7052d42c72df8 (diff)
downloadFreeBSD-src-ba91da3aff4fb68aa0ec546f7eeb21855b267fc7.zip
FreeBSD-src-ba91da3aff4fb68aa0ec546f7eeb21855b267fc7.tar.gz
When -n is specified, attempt to turn hostnames found in utmp into IP
addresses, again. However, change a hostname into an IP address, only when a host has just one A/AAAA RR. Requested by: candy__at__kgc.co.jp MFC after: 2 weeks
Diffstat (limited to 'usr.bin/w')
-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 10ec7b0..fca5df9 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;
OpenPOWER on IntegriCloud