Last active
February 19, 2020 19:02
-
-
Save eerpini/55c0cd3bb62870b965a8 to your computer and use it in GitHub Desktop.
sample code to read the unix session log utmp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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