summaryrefslogtreecommitdiff
path: root/dutmp.c
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>1999-10-05 16:24:54 +0000
committerEric Andersen <andersen@codepoet.org>1999-10-05 16:24:54 +0000
commitcc8ed39b240180b58810784f844e253263594ac3 (patch)
tree15feebbb4be9a9168209609f48f0b100f9364420 /dutmp.c
downloadbusybox-w32-0_29alpha2.tar.gz
busybox-w32-0_29alpha2.tar.bz2
busybox-w32-0_29alpha2.zip
Initial revision0_29alpha2
Diffstat (limited to 'dutmp.c')
-rw-r--r--dutmp.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/dutmp.c b/dutmp.c
new file mode 100644
index 000000000..e92b6700f
--- /dev/null
+++ b/dutmp.c
@@ -0,0 +1,47 @@
1/*
2 * public domain -- Dave 'Kill a Cop' Cinege <dcinege@psychosis.com>
3 *
4 * dutmp
5 * Takes utmp formated file on stdin and dumps it's contents
6 * out in colon delimited fields. Easy to 'cut' for shell based
7 * versions of 'who', 'last', etc. IP Addr is output in hex,
8 * little endian on x86.
9 *
10 * made against libc6
11 */
12
13#include "internal.h"
14#include <stdio.h>
15#include <utmp.h>
16
17const char dutmp_usage[] = "dutmp\n"
18"\n"
19"\tDump file or stdin utmp file format to stdout, pipe delimited.\n"
20"\tdutmp /var/run/utmp\n";
21
22extern int
23dutmp_fn(const struct FileInfo * i)
24{
25
26FILE * f = stdin;
27struct utmp * ut = (struct utmp *) malloc(sizeof(struct utmp) );
28
29 if ( i )
30 if (! (f = fopen(i->source, "r"))) {
31 name_and_error(i->source);
32 return 1;
33 }
34
35 while (fread (ut, 1, sizeof(struct utmp), f)) {
36 //printf("%d:%d:%s:%s:%s:%s:%d:%d:%ld:%ld:%ld:%x\n",
37 printf("%d|%d|%s|%s|%s|%s|%d|%d|%ld|%ld|%ld|%x\n",
38 ut->ut_type, ut->ut_pid, ut->ut_line,
39 ut->ut_id, ut->ut_user, ut->ut_host,
40 ut->ut_exit.e_termination, ut->ut_exit.e_exit,
41 ut->ut_session,
42 ut->ut_tv.tv_sec, ut->ut_tv.tv_usec,
43 ut->ut_addr);
44 }
45
46return 0;
47}