Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!magnus.acs.ohio-state.edu!usenet.ins.cwru.edu!gatech!udel!haven.umd.edu!umbc3.umbc.edu!bernie From: bernie@umbc3.umbc.edu (Bernard J. Duffy) Newsgroups: comp.sys.sgi Subject: Re: setting REMOTEHOST on rlogins Message-ID: <1991Jun21.234120.16696@umbc3.umbc.edu> Date: 21 Jun 91 23:41:20 GMT References: <1991Jun12.174725@spruce.gsfc.nasa.gov> <1991Jun21.173050.9868@umbc3.umbc.edu> Organization: University of Maryland Baltimore County Lines: 70 In article <1991Jun21.173050.9868@umbc3.umbc.edu> bernie@umbc3.umbc.edu (Bernard J. Duffy) writes: >In article <1991Jun12.174725@spruce.gsfc.nasa.gov> karl@spruce.gsfc.nasa.gov (karl anderson) writes: >>I'm just getting acquainted with SGI machines after using Suns alot. >>I see that when I rlogin to one of our Irises, an environment variable >>named "REMOTEHOST" is set to the name of the machine I'm logging in >>from. Is this something unique to IRIX? I'd love to be able to do >>that on my Suns - can anyone tell me how? Please answer by email, >>as I don't ordinarily take this group. TIA. > You can make a simple C program that could set this for you and >it would be pretty easy to port to most of your un*x-es . ... Well I had this question around here lately ... so I wrote some code and lucky for you, this works just fine for SUNs. It only seems to work on BSD related systems like DECs and SUNs (I don't have any other BSD systems). HP-UX has the ut_host (remote host info), but they (the kernal/ login) don't fill in the information. Stardent (Titan P3)'s /etc/utmp is not cleanly layed out... the have multiple records for the same tty and they don't fill the ut_host entry with x-terms sessions (started via rsh). >The information for the REMOTEHOST is held in the world readable /etc/utmp >that the who utility reads for you. Your non-suid (non-prived) program >can scan /etc/utmp and extract the REMOTEHOST. This would be of use ... so here that code: /* remote_host.c - author: Bernie Duffy date: 6/21/91 cut / paste abuse code at will ... you can even remove this comment section if that saves you some disk space. :-) */ #include #include /* needed for HP-UX */ #include /* utmp struct */ main() { char tty_name[20]; int index; FILE *utmp_file; struct utmp user_entry; utmp_file = fopen("/etc/utmp", "r"); strcat (tty_name, ttyname(0)); /* only need the end part tty... */ index = strlen(tty_name); while (--index) if (tty_name[index] == '/') break; index++; while (fread((char *)&user_entry, sizeof(user_entry), 1, utmp_file) == 1) if (strcmp (&tty_name[index], user_entry.ut_line) == 0) { printf("user = %-10s REMOTEHOST = %s\n", user_entry.ut_name, user_entry.ut_host); break; } fclose (utmp_file); } Have fun, Bernie bernie@pinhead.acs.umbc.edu UMBC: the only University with "County" in its name... that's why they want to change it. MD has lots of schools and very few big cities. -- Bernie Duffy Systems Programmer II | Bitnet : BERNIE@UMBC2 Academic Computing Services - L005e | Internet : BERNIE@UMBC2.UMBC.EDU Univ. of Maryland Baltimore County | UUCP : ...!uunet!umbc3!bernie Baltimore, MD 21228 (U.S.A.) | W: (301) 455-3231 H: (301) 744-2954