#include <utmpx.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/types.h>

#ifdef __linux
#define LOGFILE "/var/run/utmp"
#else
#ifdef __sun__
#define LOGFILE "/var/adm/utmpx"
#else
#error Cannot compile on this system
#endif
#endif

int main(void) {
int fd;
struct utmpx theUtmp;

if ((fd = open(LOGFILE, O_RDONLY)) == -1) {
	perror("cannot open utmp");
	exit(1);
}
while (read(fd, &theUtmp, sizeof(struct utmpx)) > 0) {
	printf("%-16.16s %-15.15s %-10ld %-15.15s %d\n",
		theUtmp.ut_user, theUtmp.ut_line,
		(long)(theUtmp.ut_pid), theUtmp.ut_host, theUtmp.ut_type);
}
close(fd);
return 0;
}

