Source-Changes-HG archive

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

[src/trunk]: src/usr.sbin/lastlogin Use sockaddr_snprintf()



details:   https://anonhg.NetBSD.org/src/rev/48e39350b820
branches:  trunk
changeset: 571363:48e39350b820
user:      christos <christos%NetBSD.org@localhost>
date:      Fri Nov 19 21:43:40 2004 +0000

description:
Use sockaddr_snprintf()

diffstat:

 usr.sbin/lastlogin/Makefile    |   5 ++++-
 usr.sbin/lastlogin/lastlogin.c |  28 ++++++----------------------
 2 files changed, 10 insertions(+), 23 deletions(-)

diffs (71 lines):

diff -r f3c8ad918bc5 -r 48e39350b820 usr.sbin/lastlogin/Makefile
--- a/usr.sbin/lastlogin/Makefile       Fri Nov 19 21:41:25 2004 +0000
+++ b/usr.sbin/lastlogin/Makefile       Fri Nov 19 21:43:40 2004 +0000
@@ -1,7 +1,10 @@
-#      $NetBSD: Makefile,v 1.2 2004/11/11 20:17:36 christos Exp $
+#      $NetBSD: Makefile,v 1.3 2004/11/19 21:43:40 christos Exp $
 
 PROG= lastlogin
 MAN= lastlogin.8
 CPPFLAGS+=-DSUPPORT_UTMP -DSUPPORT_UTMPX
 
+LDADD+=-lutil
+DPADD+=${LIBUTIL}
+
 .include <bsd.prog.mk>
diff -r f3c8ad918bc5 -r 48e39350b820 usr.sbin/lastlogin/lastlogin.c
--- a/usr.sbin/lastlogin/lastlogin.c    Fri Nov 19 21:41:25 2004 +0000
+++ b/usr.sbin/lastlogin/lastlogin.c    Fri Nov 19 21:43:40 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lastlogin.c,v 1.10 2004/11/13 00:11:03 he Exp $        */
+/*     $NetBSD: lastlogin.c,v 1.11 2004/11/19 21:43:40 christos Exp $  */
 /*
  * Copyright (c) 1996 John M. Vinopal
  * All rights reserved.
@@ -33,7 +33,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: lastlogin.c,v 1.10 2004/11/13 00:11:03 he Exp $");
+__RCSID("$NetBSD: lastlogin.c,v 1.11 2004/11/19 21:43:40 christos Exp $");
 #endif
 
 #include <sys/types.h>
@@ -55,6 +55,7 @@
 #include <utmpx.h>
 #endif
 #include <unistd.h>
+#include <util.h>
 
 struct output {
        struct timeval   o_tv;
@@ -417,26 +418,9 @@
                return o->o_host;
        else {
                static char buf[512];
-               const char *p;
-               struct sockaddr_storage *ss = &o->o_ss;
-               void *a;
-               switch (ss->ss_family) {
-               default:
-                       (void)snprintf(buf, sizeof(buf), "%d: unknown family",
-                               ss->ss_family);
-                       return buf;
-               case 0: /* reboot etc. entries */
-                       return "";
-               case AF_INET:
-                       a = &((struct sockaddr_in *)(void *)ss)->sin_addr;
-                       break;
-               case AF_INET6:
-                       a = &((struct sockaddr_in6 *)(void *)ss)->sin6_addr;
-                       break;
-               }
-               if ((p = inet_ntop(ss->ss_family, a, buf, ss->ss_len)) != NULL)
-                       return p;
-               (void)snprintf(buf, sizeof(buf), "%s", strerror(errno));
+               buf[0] = '\0';
+               (void)sockaddr_snprintf(buf, sizeof(buf), "%a",
+                   (struct sockaddr *)&o->o_ss);
                return buf;
        }
 }



Home | Main Index | Thread Index | Old Index