Skip to content

Instantly share code, notes, and snippets.

@bensenq
Forked from eerpini/read-utmp-file.c
Last active May 17, 2016 13:57
Show Gist options
  • Select an option

  • Save bensenq/af6017e7a141117497dbb70b0f2d7fa7 to your computer and use it in GitHub Desktop.

Select an option

Save bensenq/af6017e7a141117497dbb70b0f2d7fa7 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(&data, 0, sizeof(struct utmpx));
while(fread(&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