cdown / rpms / util-linux

Forked from rpms/util-linux 2 years ago
Clone
9d84b2
diff -up util-linux-2.23.2/login-utils/utmpdump.c.kzak util-linux-2.23.2/login-utils/utmpdump.c
9d84b2
--- util-linux-2.23.2/login-utils/utmpdump.c.kzak	2013-10-07 11:56:02.030191040 +0200
9d84b2
+++ util-linux-2.23.2/login-utils/utmpdump.c	2013-10-07 12:05:08.671171091 +0200
9d84b2
@@ -85,11 +85,14 @@ static void xcleanse(char *s, int len)
9d84b2
 
9d84b2
 static void print_utline(struct utmp ut)
9d84b2
 {
9d84b2
-	char *addr_string, *time_string;
9d84b2
-	struct in_addr in;
9d84b2
+	const char *addr_string, *time_string;
9d84b2
+	char buffer[INET6_ADDRSTRLEN];
9d84b2
+
9d84b2
+	if (ut.ut_addr_v6[1] || ut.ut_addr_v6[2] || ut.ut_addr_v6[3])
9d84b2
+		addr_string = inet_ntop(AF_INET6, &(ut.ut_addr_v6), buffer, sizeof(buffer));
9d84b2
+	else
9d84b2
+		addr_string = inet_ntop(AF_INET, &(ut.ut_addr_v6), buffer, sizeof(buffer));
9d84b2
 
9d84b2
-	in.s_addr = ut.ut_addr;
9d84b2
-	addr_string = inet_ntoa(in);
9d84b2
 	time_string = timetostr(ut.ut_time);
9d84b2
 	cleanse(ut.ut_id);
9d84b2
 	cleanse(ut.ut_user);
9d84b2
@@ -97,7 +100,7 @@ static void print_utline(struct utmp ut)
9d84b2
 	cleanse(ut.ut_host);
9d84b2
 
9d84b2
 	/*            pid    id       user     line     host     addr       time */
9d84b2
-	printf("[%d] [%05d] [%-4.4s] [%-*.*s] [%-*.*s] [%-*.*s] [%-15.15s] [%-28.28s]\n",
9d84b2
+	printf("[%d] [%05d] [%-4.4s] [%-*.*s] [%-*.*s] [%-*.*s] [%-15s] [%-28.28s]\n",
9d84b2
 	       ut.ut_type, ut.ut_pid, ut.ut_id, 8, UT_NAMESIZE, ut.ut_user,
9d84b2
 	       12, UT_LINESIZE, ut.ut_line, 20, UT_HOSTSIZE, ut.ut_host,
9d84b2
 	       addr_string, time_string);
9d84b2
@@ -248,11 +251,10 @@ static int gettok(char *line, char *dest
9d84b2
 static void undump(FILE *fp)
9d84b2
 {
9d84b2
 	struct utmp ut;
9d84b2
-	char s_addr[16], s_time[29], *linestart, *line;
9d84b2
+	char s_addr[INET6_ADDRSTRLEN + 1], s_time[29], *linestart, *line;
9d84b2
 	int count = 0;
9d84b2
 
9d84b2
 	line = linestart = xmalloc(1024 * sizeof(*linestart));
9d84b2
-	s_addr[15] = 0;
9d84b2
 	s_time[28] = 0;
9d84b2
 
9d84b2
 	while (fgets(linestart, 1023, fp)) {
9d84b2
@@ -267,7 +269,10 @@ static void undump(FILE *fp)
9d84b2
 		line += gettok(line, s_addr, sizeof(s_addr) - 1, 1);
9d84b2
 		line += gettok(line, s_time, sizeof(s_time) - 1, 0);
9d84b2
 
9d84b2
-		ut.ut_addr = inet_addr(s_addr);
9d84b2
+		if (strchr(s_addr, '.'))
9d84b2
+			inet_pton(AF_INET, s_addr, &(ut.ut_addr_v6));
9d84b2
+		else
9d84b2
+			inet_pton(AF_INET6, s_addr, &(ut.ut_addr_v6));
9d84b2
 		ut.ut_time = strtotime(s_time);
9d84b2
 
9d84b2
 		ignore_result( fwrite(&ut, sizeof(ut), 1, stdout) );