-
-
Save bensenq/af6017e7a141117497dbb70b0f2d7fa7 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