cdown / rpms / util-linux

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