LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Displaying fields in wtmp file? (https://www.linuxquestions.org/questions/programming-9/displaying-fields-in-wtmp-file-198141/)

eclapton1 06-26-2004 08:56 PM

Displaying fields in wtmp file?
 
Anyone have any idea on how to display the fields for each record stored in the wtmp file using C? Am I correct in thinking that the info stored in wtmp is in binary and that utmpx will be of some help? Being a beginner, I can come up with bits and pieces of what I might need in order to do the task, but have a harder time putting all the pieces together to form working code. I am assuming I need to include these bits of code:

#include <utmp.h>
#include <utmpx.h>

struct utmpx record;
fread(&record, sizeof(record), ???)

printf(??????)

Any assistance would be greatly appreciated. Thanks.

jwstric2 06-26-2004 09:51 PM

man getutent
man fread

You won't have to do the straight file operations then. If you want to do it manulally with fread:

struct utmpx record;
FILE fd = 0;

fd = fopen(name, 'r'); //Usally /var/run/utmp
fread(&record, sizeof(record), 1, fd);

printf("Whatever fields you want, check out the header\n");


All times are GMT -5. The time now is 11:38 PM.