aboutsummaryrefslogtreecommitdiff
path: root/dutmp.c
diff options
context:
space:
mode:
Diffstat (limited to 'dutmp.c')
-rw-r--r--dutmp.c64
1 files changed, 0 insertions, 64 deletions
diff --git a/dutmp.c b/dutmp.c
deleted file mode 100644
index df7f64d30..000000000
--- a/dutmp.c
+++ /dev/null
@@ -1,64 +0,0 @@
1/* vi: set sw=4 ts=4: */
2/*
3 * public domain -- Dave 'Kill a Cop' Cinege <dcinege@psychosis.com>
4 *
5 * dutmp
6 * Takes utmp formated file on stdin and dumps it's contents
7 * out in colon delimited fields. Easy to 'cut' for shell based
8 * versions of 'who', 'last', etc. IP Addr is output in hex,
9 * little endian on x86.
10 *
11 * Modified to support all sorts of libcs by
12 * Erik Andersen <andersen@lineo.com>
13 */
14
15#include <sys/types.h>
16#include <fcntl.h>
17
18#include <errno.h>
19#include <utmp.h>
20#include <stdlib.h>
21#include <unistd.h>
22#include "busybox.h"
23
24extern int dutmp_main(int argc, char **argv)
25{
26
27 int file;
28 struct utmp ut;
29
30 if (argc<2) {
31 file = fileno(stdin);
32 } else if (*argv[1] == '-' ) {
33 show_usage();
34 } else {
35 file = open(argv[1], O_RDONLY);
36 if (file < 0) {
37 perror_msg_and_die(io_error, argv[1]);
38 }
39 }
40
41/* Kludge around the fact that the binary format for utmp has changed. */
42#if __GNU_LIBRARY__ < 5 || defined __UCLIBC__
43 /* Linux libc5 */
44 while (read(file, (void*)&ut, sizeof(struct utmp))) {
45 printf("%d|%d|%s|%s|%s|%s|%s|%lx\n",
46 ut.ut_type, ut.ut_pid, ut.ut_line,
47 ut.ut_id, ut.ut_user, ut.ut_host,
48 ctime(&(ut.ut_time)),
49 (long)ut.ut_addr);
50 }
51#else
52 /* Glibc, uClibc, etc. */
53 while (read(file, (void*)&ut, sizeof(struct utmp))) {
54 printf("%d|%d|%s|%s|%s|%s|%d|%d|%ld|%ld|%ld|%x\n",
55 ut.ut_type, ut.ut_pid, ut.ut_line,
56 ut.ut_id, ut.ut_user, ut.ut_host,
57 ut.ut_exit.e_termination, ut.ut_exit.e_exit,
58 ut.ut_session,
59 ut.ut_tv.tv_sec, ut.ut_tv.tv_usec,
60 ut.ut_addr);
61 }
62#endif
63 return EXIT_SUCCESS;
64}