-
Notifications
You must be signed in to change notification settings - Fork 0
/
mywho.c
43 lines (39 loc) · 968 Bytes
/
mywho.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*
* =====================================================================================
*
* Filename: mywho.c
*
* Description:
*
* Version: 1.0
* Created: 2013年04月09日 09时34分00秒
* Revision: none
* Compiler: gcc
*
* Author: HeYuhang (HeYuhang),
* Company:
*
* =====================================================================================
*/
#include <unistd.h>
#include <utmp.h>
#include <stdio.h>
#include <fcntl.h>
#include <time.h>
int main(int argc, char *argv[])
{
struct utmp user_record;
int utmp;
if((utmp=open(UTMP_FILE,O_RDONLY))==-1)
{
return -1;
}
printf("username hostname device time\n");
while(read(utmp,&user_record,sizeof(user_record)))
{
// printf("username hostname device time\n");
printf("%s %s %s %s\n",user_record.ut_user,user_record.ut_host,user_record.ut_line,ctime(&user_record.ut_time));
}
close(utmp);
return 1;
}