diff options
Diffstat (limited to 'dutmp.c')
-rw-r--r-- | dutmp.c | 35 |
1 files changed, 16 insertions, 19 deletions
@@ -8,22 +8,20 @@ | |||
8 | * versions of 'who', 'last', etc. IP Addr is output in hex, | 8 | * versions of 'who', 'last', etc. IP Addr is output in hex, |
9 | * little endian on x86. | 9 | * little endian on x86. |
10 | * | 10 | * |
11 | * made against libc6 | 11 | * Modified to support all sort of libcs by |
12 | * Erik Andersen <andersen@lineo.com> | ||
12 | */ | 13 | */ |
13 | 14 | ||
14 | #include "internal.h" | 15 | #include "internal.h" |
15 | #include <stdio.h> | 16 | #include <sys/types.h> |
17 | #include <sys/stat.h> | ||
18 | #include <fcntl.h> | ||
19 | |||
16 | #include <errno.h> | 20 | #include <errno.h> |
17 | #define BB_DECLARE_EXTERN | 21 | #define BB_DECLARE_EXTERN |
18 | #define bb_need_io_error | 22 | #define bb_need_io_error |
19 | #include "messages.c" | 23 | #include "messages.c" |
20 | |||
21 | #if defined(__GLIBC__) | ||
22 | #include <utmp.h> | 24 | #include <utmp.h> |
23 | #else | ||
24 | #include <utmp-wrap.h> | ||
25 | #define utmp new_utmp | ||
26 | #endif | ||
27 | 25 | ||
28 | 26 | ||
29 | static const char dutmp_usage[] = "dutmp [FILE]\n" | 27 | static const char dutmp_usage[] = "dutmp [FILE]\n" |
@@ -36,27 +34,26 @@ static const char dutmp_usage[] = "dutmp [FILE]\n" | |||
36 | extern int dutmp_main(int argc, char **argv) | 34 | extern int dutmp_main(int argc, char **argv) |
37 | { | 35 | { |
38 | 36 | ||
39 | FILE *f; | 37 | int file; |
40 | struct utmp ut; | 38 | struct utmp ut; |
41 | 39 | ||
42 | if (argc<2) { | 40 | if (argc<2) { |
43 | f = stdin; | 41 | file = fileno(stdin); |
44 | } else if (*argv[1] == '-' ) { | 42 | } else if (*argv[1] == '-' ) { |
45 | usage(dutmp_usage); | 43 | usage(dutmp_usage); |
46 | } else { | 44 | } else { |
47 | f = fopen(argv[1], "r"); | 45 | file = open(argv[1], O_RDONLY); |
48 | if (f == NULL) { | 46 | if (file < 0) { |
49 | fatalError(io_error, argv[1], strerror(errno)); | 47 | fatalError(io_error, argv[1], strerror(errno)); |
50 | } | 48 | } |
51 | } | 49 | } |
52 | 50 | ||
53 | while (fread(&ut, sizeof(struct utmp), 1, f)) { | 51 | while (read(file, (void*)&ut, sizeof(struct utmp))) { |
54 | printf("%d|%d|%s|%s|%s|%s|%d|%d|%ld|%ld|%ld|%x\n", | 52 | printf("%d|%d|%s|%s|%s|%s|%s|%lx\n", |
55 | ut.ut_type, ut.ut_pid, ut.ut_line, | 53 | ut.ut_type, ut.ut_pid, ut.ut_line, |
56 | ut.ut_id, ut.ut_user, ut.ut_host, | 54 | ut.ut_id, ut.ut_user, ut.ut_host, |
57 | ut.ut_exit.e_termination, ut.ut_exit.e_exit, | 55 | ctime(&(ut.ut_time)), |
58 | ut.ut_session, ut.ut_tv.tv_sec, ut.ut_tv.tv_usec, | 56 | (long)ut.ut_addr); |
59 | ut.ut_addr_v6[0]); | ||
60 | } | 57 | } |
61 | 58 | ||
62 | exit(TRUE); | 59 | exit(TRUE); |