/* This program is designed to help system administrators overcome the limitation of the last command by printing out the ip address (or host name) fully on the right extreme */ #include #include #include #include #include /* Function to display the required information */ disp(struct utmpx *u) { printf("%-8s %-8s %-35s %s", u->ut_user,u->ut_line,u->ut_host, ctime(&u->ut_xtime)); fflush(stdout); } /* Main control function */ main (int argc, char **argv) { struct utmpx *u = (struct utmpx *) malloc (sizeof(struct utmpx)); int i=0, n = 0, m = 0; char * fname = "/var/adm/wtmpx"; /* This makes sure that the default location for the program to take its input from will be /var/adm/wtmpx, unless the user gives in his own path */ int fp; char *name=0; int days=0; char hosts[100][100]; int j=0,k=0; int s = sizeof(struct utmpx); for (i=1;iut_user) ) /* This part evaluates the information for a particular user */ if ( u->ut_type == 7) { for (i=1; iut_host, hosts[j])) n = 1; /* This part keeps track of the host names that have been accessed so that there are no repetitions. */ if (n != 1) { strcpy(hosts[k], u->ut_host); k++; disp(u); i++; } // end if. else n = 0; } // end if. else { disp(u); i++; } // end else. } // end if. lseek(fp,-2*s,SEEK_CUR); /* The lseek is formatted in such a way that it reads back two records, since, after reading a record, we need to go back to the record previous to the one that was just read ... thats two records */ continue; } // end if. else { if ( u->ut_type == 7) { disp(u); i++; } // end if. } // end else. if (lseek(fp,-2*s,SEEK_CUR) < 0 ) { close(fp); exit(0); } } // end while. } // End of main.