home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <pwd.h>
- #define RWHO "/usr/ucb/rwho "
-
- main(argc,argv)
- int argc;
- char *argv[];
- {
- FILE *pipe;
-
- char real_name[20], inline[80];
- char *user, *host, *time, *gecos, *tty, *strtok();
-
- register int i;
-
- struct passwd *pw;
-
- argv++;
- strcpy(inline,RWHO);
- strcat(inline,*argv);
-
- if ((pipe = popen(inline,"r")) == NULL)
- {
- fprintf (stderr,"Broken pipe\n");
- exit(-1);
- }
-
- printf ("User Real Name Host TTY When Idle\n");
- for (i=0;i<80;i++) printf ("-");
- printf ("\n");
-
- while (fgets(inline,80,pipe) != NULL)
- {
- user = strtok(inline," ");
- host = strtok(NULL,":");
- tty = strtok(NULL," ");
- time = strtok(NULL,"\n");
-
- if ((pw = getpwnam(user)) != NULL)
- {
- gecos = strtok(pw->pw_gecos,",");
-
- strncpy(real_name,gecos,20);
- real_name[20] = NULL;
-
- while(time[0] == ' ') time++;
- while(host[0] == ' ') host++;
-
- printf ("%8s %20s %10s %6s %s\n",
- user,
- real_name,
- strtok(host,"."),
- tty,
- time);
- }
- }
- }
-