Skip to content

Instantly share code, notes, and snippets.

@eerpini
Last active February 19, 2020 19:02
Show Gist options
  • Save eerpini/55c0cd3bb62870b965a8 to your computer and use it in GitHub Desktop.
Save eerpini/55c0cd3bb62870b965a8 to your computer and use it in GitHub Desktop.
sample code to read the unix session log utmp
#include <utmpx.h>
#include <paths.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main(int argc, char **argv){
struct utmpx data;
FILE *log_file = fopen(_PATH_UTMP, "r");
memset(&amp;data, 0, sizeof(struct utmpx));
while(fread(&amp;data, sizeof(struct utmpx), 1, log_file) == 1){
printf("Read a record , User : %s\n", data.ut_user);
}
fclose(log_file);
return EXIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment