RE: 4GL
Posted in 1998
---------- From: h.j. sanders[SMTP:hjs@worldonline.nl] Sent: Tuesday, March 24, 1998 10:11 AM does anyone know where the remote hostname as shown with who -u is stored so I can retrieve it with fgl_getenv() The code below is for the local host name... Remote host names are harder and require access to DNS name lookup and/or BIND and other esoteric parts of the TCP/IP world. You would need to investigate gethostbyaddr(3) and its relations, depending on how you are going identify the hosts which are in use. The actual information for who comes from an administrative file, the utmp file; see utmp(3) for information on that data structure. You'd also have to consider much more carefully how you get the addresses to be translated into the code that does the translation. I trust you would not be doing that with fgl_getenv()! For a local hostname, I suppose you could write the following: #include <sys/utsname.h> #include <unistd.h> #include <stdio.h> #include <stdlib.h> #include <errno.h> #include "fglsys.h" /* Or fglusr.h - I forget which; for fgl_fatal() */ int set_hostname_environment(int nargs) { char *env = malloc(sizeof("HOSTNAME=") + SYS_NMLN); struct utsname u; if (nargs != 0) fgl_fatal(__FILE__, __LINE__, -1318); if (env == 0) /* My memory is failing; as well as I4GL's */ fgl_fatal(__FILE__, __LINE__, -1349); if (uname(&u) != 0) fgl_fatal(__FILE__, __LINE__, -errno); sprintf(env, "HOSTNAME=%s", u.sysname); putenv(env); return(0); } You can then call fgl_getenv("HOSTNAME") to retrieve the value so carefully set by set_hostname_environment(), but on average I'd write get_hostname() to return the string directly - left as an exercise for the reader! :-) Yours, Jonathan Leffler (jleffler@visa.com) #include <bother.ms-exchange.h> PS: Untested code -- I could have the arguments to fgl_fatal in the wrong order; I only read the manual page for uname(2); the SYS_NMLN macro is defined in sys/utsname.h according to the Solaris man page; I'm not certain that I've got the header where putenv(3) is declared.