Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/telnet use getnameinfo for "Trying ::1..." message, ...



details:   https://anonhg.NetBSD.org/src/rev/1c23d4a63c28
branches:  trunk
changeset: 481758:1c23d4a63c28
user:      itojun <itojun%NetBSD.org@localhost>
date:      Sat Feb 05 17:44:11 2000 +0000

description:
use getnameinfo for "Trying ::1..." message, to enable printing of
IPv6 scopeid.

diffstat:

 usr.bin/telnet/commands.c |  26 ++++++++++++--------------
 1 files changed, 12 insertions(+), 14 deletions(-)

diffs (49 lines):

diff -r c4010064356c -r 1c23d4a63c28 usr.bin/telnet/commands.c
--- a/usr.bin/telnet/commands.c Sat Feb 05 17:39:22 2000 +0000
+++ b/usr.bin/telnet/commands.c Sat Feb 05 17:44:11 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: commands.c,v 1.37 2000/01/31 14:25:42 itojun Exp $     */
+/*     $NetBSD: commands.c,v 1.38 2000/02/05 17:44:11 itojun Exp $     */
 
 /*
  * Copyright (C) 1997 and 1998 WIDE Project.
@@ -67,7 +67,7 @@
 #if 0
 static char sccsid[] = "@(#)commands.c 8.4 (Berkeley) 5/30/95";
 #else
-__RCSID("$NetBSD: commands.c,v 1.37 2000/01/31 14:25:42 itojun Exp $");
+__RCSID("$NetBSD: commands.c,v 1.38 2000/02/05 17:44:11 itojun Exp $");
 #endif
 #endif /* not lint */
 
@@ -2164,20 +2164,18 @@
 sockaddr_ntop(sa)
     struct sockaddr *sa;
 {
-    void *addr;
-    static char addrbuf[INET6_ADDRSTRLEN];
+    static char addrbuf[NI_MAXHOST];
+#ifdef NI_WITHSCOPEID
+    const int niflags = NI_NUMERICHOST | NI_WITHSCOPEID;
+#else
+    const int niflags = NI_NUMERICHOST;
+#endif
 
-    switch (sa->sa_family) {
-    case AF_INET:
-       addr = &((struct sockaddr_in *)sa)->sin_addr;
-       break;
-    case AF_INET6:
-       addr = &((struct sockaddr_in6 *)sa)->sin6_addr;
-       break;
-    default:
+    if (getnameinfo(sa, sa->sa_len, addrbuf, sizeof(addrbuf),
+           NULL, 0, niflags) == 0)
+       return addrbuf;
+    else
        return NULL;
-    }
-    return (char *)inet_ntop(sa->sa_family, addr, addrbuf, sizeof(addrbuf));
 }
 
 #if defined(IPSEC) && defined(IPSEC_POLICY_IPSEC)



Home | Main Index | Thread Index | Old Index