setting REMOTEHOST on rlogins

Bernard J. Duffy bernie at umbc3.umbc.edu
Sat Jun 22 09:41:20 AEST 1991


In article <1991Jun21.173050.9868 at umbc3.umbc.edu> bernie at umbc3.umbc.edu (Bernard J. Duffy) writes:
>In article <1991Jun12.174725 at spruce.gsfc.nasa.gov> karl at 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 <stdio.h>
#include <sys/types.h>  /* needed for HP-UX */
#include <utmp.h>  /* 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 at 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 at UMBC2
Academic Computing Services - L005e  | Internet  :  BERNIE at 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 



More information about the Comp.sys.sgi mailing list