Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!hellgate.utah.edu!cs.utexas.edu!ginosko!usc!snorkelwacker!mit-eddie!bu-cs!buengc!bph From: bph@buengc.BU.EDU (Blair P. Houghton) Newsgroups: comp.unix.questions Subject: Re: Finding the originating host on a network login Message-ID: <4647@buengc.BU.EDU> Date: 25 Oct 89 04:48:46 GMT References: <1158@rex.cs.tulane.edu> <3539@amelia.nas.nasa.gov> Reply-To: bph@buengc.bu.edu (Blair P. Houghton) Followup-To: comp.unix.questions Organization: Boston Univ. Col. of Eng. Lines: 51 In article (Skip Montanaro) writes: >In article <3539@amelia.nas.nasa.gov> samlb@pioneer.arc.nasa.gov (Sam Bassett RCD) writes: > > On my Ultrix 3.0 system here (4.3BSD derived), 'who' gives me > just that info. I am not an expert on SysV 'who's, but I know that > they're different . . . > >I think it depends how good a job the vendor has done incoporating all the >little odds'n'ends that go into "Berkeley UNIX compatibility". Stellar's >'who' command prints the originating host, while HP-UX (at least as of 6.5) >does not. Screw 'who': -----------------------------Clip 'n' compile------------------------------- #include #include /* Where the current logins are stored. */ #define LOGFILE "/etc/utmp" extern char *rindex(); main() { char *tty, *ttyname(), *nptr; struct utmp U; FILE *fp, *fopen(); fp = fopen( LOGFILE, "r"); /* Get stdin's tty's name. */ tty = ttyname(0); /* "/dev/ttyxx" ==> "ttyxx" */ nptr = 1 + rindex(tty,'/'); /* Loop through login log, printing remote * * host for all that have this tty's name. */ while( fread( (char *)&U, sizeof(struct utmp), 1, fp ) ) if ( (*U.ut_name != '\0') && (strcmp(nptr, U.ut_line) == 0) ) printf( "%s\n", U.ut_host); } ---------------------------------------------------------------------------- This is a rather thoroughly altered version of something I got from someone else. I forget who. (No doubt their lawyers will remind me :-). --Blair "An oldie but a goodie."