initctl: Fix display of UTMP records, add IP addr

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson committed 2016-08-09 00:12:47 +02:00
1 parent f8def336d4
commit 0d1bc167ff
3 files changed
+9 -2

No files matched your search

-1
View File
@@ -27,7 +27,6 @@
#include <grp.h> #include <grp.h>
#include <pwd.h> #include <pwd.h>
#include <limits.h> #include <limits.h>
#include <arpa/inet.h>
#include <net/if.h> #include <net/if.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <stdarg.h> #include <stdarg.h>
+1
View File
@@ -26,6 +26,7 @@
#include <glob.h> #include <glob.h>
#include <paths.h> #include <paths.h>
#include <stdio.h> #include <stdio.h>
#include <arpa/inet.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <sys/un.h> #include <sys/un.h>
#include <lite/lite.h> #include <lite/lite.h>
+8 -1
View File
@@ -24,6 +24,7 @@
#include <stdio.h> #include <stdio.h>
#include <time.h> #include <time.h>
#include <utmp.h> #include <utmp.h>
#include <arpa/inet.h>
#include <sys/utsname.h> #include <sys/utsname.h>
#include <lite/lite.h> #include <lite/lite.h>
@@ -98,6 +99,8 @@ int utmp_show(char *file)
setutent(); setutent();
while ((ut = getutent())) { while ((ut = getutent())) {
char addr[64];
memset(id, 0, sizeof(id)); memset(id, 0, sizeof(id));
strncpy(id, ut->ut_id, sizeof(ut->ut_id)); strncpy(id, ut->ut_id, sizeof(ut->ut_id));
@@ -109,9 +112,13 @@ int utmp_show(char *file)
strftime(when, sizeof(when), "%F %T", sectm); strftime(when, sizeof(when), "%F %T", sectm);
pid = ut->ut_pid; pid = ut->ut_pid;
if (ut->ut_addr_v6[1] || ut->ut_addr_v6[2] || ut->ut_addr_v6[3])
inet_ntop(AF_INET6, ut->ut_addr_v6, addr, sizeof(addr));
else
inet_ntop(AF_INET, &ut->ut_addr, addr, sizeof(addr));
printf("[%d] [%05d] [%-4.4s] [%-8.8s] [%-12.12s] [%-20.20s] [%-15.15s] [%-19.19s]\n", printf("[%d] [%05d] [%-4.4s] [%-8.8s] [%-12.12s] [%-20.20s] [%-15.15s] [%-19.19s]\n",
ut->ut_type, pid, id, user, ut->ut_line, ut->ut_host, "0.0.0.0", when); ut->ut_type, pid, id, user, ut->ut_line, ut->ut_host, addr, when);
} }
endutent(); endutent();