1 /* vi: set sw=4 ts=4: */
3 * public domain -- Dave 'Kill a Cop' Cinege <dcinege@psychosis.com>
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.
18 static const char dutmp_usage[] = "dutmp\n"
21 "\tDump file or stdin utmp file format to stdout, pipe delimited.\n"
22 "\tdutmp /var/run/utmp\n";
24 extern int dutmp_main(int argc, char **argv)
30 if ((argc < 2) || (**(argv + 1) == '-')) {
34 if (**(++argv) == 0) {
35 f = fopen(*(++argv), "r");
42 while (fread(&ut, 1, sizeof(struct utmp), f)) {
43 // printf("%d:%d:%s:%s:%s:%s:%d:%d:%ld:%ld:%ld:%x\n",
44 printf("%d|%d|%s|%s|%s|%s|%d|%d|%ld|%ld|%ld|%x\n",
45 ut.ut_type, ut.ut_pid, ut.ut_line,
46 ut.ut_id, ut.ut_user, ut.ut_host,
47 ut.ut_exit.e_termination, ut.ut_exit.e_exit,
49 ut.ut_tv.tv_sec, ut.ut_tv.tv_usec, ut.ut_addr);