Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 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 | */ |
Eric Andersen | 3cf52d1 | 1999-10-12 22:26:06 +0000 | [diff] [blame] | 12 | |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 13 | #include "internal.h" |
| 14 | #include <stdio.h> |
| 15 | #include <utmp.h> |
| 16 | |
Eric Andersen | e77ae3a | 1999-10-19 20:03:34 +0000 | [diff] [blame^] | 17 | static const char dutmp_usage[] = "dutmp\n" |
Eric Andersen | 3cf52d1 | 1999-10-12 22:26:06 +0000 | [diff] [blame] | 18 | "\n" |
| 19 | "\tDump file or stdin utmp file format to stdout, pipe delimited.\n" |
| 20 | "\tdutmp /var/run/utmp\n"; |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 21 | |
Eric Andersen | e77ae3a | 1999-10-19 20:03:34 +0000 | [diff] [blame^] | 22 | static int dutmp_main (int argc, char **argv) |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 23 | { |
| 24 | |
Eric Andersen | 3cf52d1 | 1999-10-12 22:26:06 +0000 | [diff] [blame] | 25 | FILE *f = stdin; |
| 26 | struct utmp ut; |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 27 | |
Eric Andersen | 3cf52d1 | 1999-10-12 22:26:06 +0000 | [diff] [blame] | 28 | if ((argc < 2) || (**(argv + 1) == '-')) { |
Eric Andersen | b0e9a70 | 1999-10-18 22:28:26 +0000 | [diff] [blame] | 29 | usage( dutmp_usage); |
Eric Andersen | 3cf52d1 | 1999-10-12 22:26:06 +0000 | [diff] [blame] | 30 | } |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 31 | |
Eric Andersen | 3cf52d1 | 1999-10-12 22:26:06 +0000 | [diff] [blame] | 32 | if ( **(++argv) == 0 ) { |
| 33 | f = fopen (*(++argv), "r"); |
| 34 | if (f < 0 ) { |
| 35 | perror (*argv); |
| 36 | exit (FALSE); |
| 37 | } |
| 38 | } |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 39 | |
Eric Andersen | 3cf52d1 | 1999-10-12 22:26:06 +0000 | [diff] [blame] | 40 | while (fread (&ut, 1, sizeof (struct utmp), f)) { |
| 41 | // printf("%d:%d:%s:%s:%s:%s:%d:%d:%ld:%ld:%ld:%x\n", |
| 42 | printf ("%d|%d|%s|%s|%s|%s|%d|%d|%ld|%ld|%ld|%x\n", |
| 43 | ut.ut_type, ut.ut_pid, ut.ut_line, |
| 44 | ut.ut_id, ut.ut_user, ut.ut_host, |
| 45 | ut.ut_exit.e_termination, ut.ut_exit.e_exit, |
| 46 | ut.ut_session, |
| 47 | ut.ut_tv.tv_sec, ut.ut_tv.tv_usec, ut.ut_addr); |
| 48 | } |
| 49 | |
| 50 | exit (TRUE); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 51 | } |