- while (fread(&ut, sizeof(struct utmp), 1, f)) {
- printf("%d|%d|%s|%s|%s|%s|%d|%d|%ld|%ld|%ld|%x\n",
- ut.ut_type, ut.ut_pid, ut.ut_line,
- ut.ut_id, ut.ut_user, ut.ut_host,
- ut.ut_exit.e_termination, ut.ut_exit.e_exit,
- ut.ut_session, ut.ut_tv.tv_sec, ut.ut_tv.tv_usec,
- ut.ut_addr_v6[0]);
+
+ while ((n = safe_read(file, (void*)&ut, sizeof(struct utmp))) != 0) {
+
+ if (n != sizeof(struct utmp)) {
+ bb_perror_msg_and_die("short read");
+ }
+
+ /* Kludge around the fact that the binary format for utmp has changed. */
+#if __GNU_LIBRARY__ < 5
+ /* Linux libc5 */
+
+ bb_printf("%d|%d|%s|%s|%s|%s|%s|%lx\n",
+ ut.ut_type, ut.ut_pid, ut.ut_line,
+ ut.ut_id, ut.ut_user, ut.ut_host,
+ ctime(&(ut.ut_time)),
+ (long)ut.ut_addr);
+#else
+ /* Glibc, uClibc, etc. */
+
+ bb_printf("%d|%d|%.32s|%.4s|%.32s|%.256s|%d|%d|%ld|%ld|%ld|%x\n",
+ ut.ut_type, ut.ut_pid, ut.ut_line,
+ ut.ut_id, ut.ut_user, ut.ut_host,
+ ut.ut_exit.e_termination, ut.ut_exit.e_exit,
+ ut.ut_session,
+ ut.ut_tv.tv_sec, ut.ut_tv.tv_usec,
+ ut.ut_addr);
+#endif