home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / TELECOM / palias10.lzh / BNU / PALIAS / local.c < prev    next >
Text File  |  1993-08-02  |  2KB  |  92 lines

  1. /* pathalias -- by steve bellovin, as told to peter honeyman */
  2. #ifndef lint
  3. static char    *sccsid = "@(#)local.c    9.2 88/06/10";
  4. #endif /* lint */
  5.  
  6. #include <stdio.h>
  7. #include "config.h"
  8.  
  9. #ifdef OSK
  10. #include "osk.c"
  11. #endif
  12.  
  13. #ifdef    UNAME
  14. #include <sys/utsname.h>
  15.  
  16. char    *
  17. local()
  18. {
  19.     static struct utsname utsname;
  20.     extern int uname();
  21.  
  22.     (void) uname(&utsname);
  23.     return(utsname.nodename);
  24. }
  25.  
  26. #else /* !UNAME */
  27.  
  28. char    *
  29. local()
  30. {
  31.     static char lname[64];
  32.     extern int gethostname();
  33.  
  34.     (void) gethostname(lname, (int) sizeof(lname));
  35.     lname[sizeof(lname)] = 0;
  36.     return(lname);
  37. }
  38.  
  39. #ifndef GETHOSTNAME
  40.  
  41. STATIC int
  42. gethostname(name, len)
  43.     char *name;
  44.     int len;
  45. {    FILE *whoami;
  46.     char *ptr;
  47.     extern int pclose();
  48.     extern FILE *fopen(), *popen();
  49.  
  50.     *name = '\0';
  51.  
  52.     /* try /etc/whoami */
  53.     if ((whoami = fopen("/etc/whoami", "r")) != 0) {
  54.         (void) fgets(name, len, whoami);
  55.         (void) fclose(whoami);
  56.         if ((ptr = index(name, '\n')) != 0)
  57.             *ptr = '\0';
  58.     }
  59.     if (*name)
  60.         return 0;
  61.  
  62.     /* try /usr/include/whoami.h */
  63.     if ((whoami = fopen("/usr/include/whoami.h", "r")) != 0) {
  64.         while (!feof(whoami)) {
  65.             char    buf[100];
  66.  
  67.             if (fgets(buf, 100, whoami) == 0)
  68.                 break;
  69.             if (sscanf(buf, "#define sysname \"%[^\"]\"", name))
  70.                 break;
  71.         }
  72.         (void) fclose(whoami);
  73.         if (*name)
  74.             return 0;
  75.     }
  76.  
  77.     /* ask uucp */
  78.     if ((whoami = popen("uuname -l", "r")) != 0) {
  79.         (void) fgets(name, len, whoami);
  80.         (void) pclose(whoami);
  81.         if ((ptr = index(name, '\n')) != 0)
  82.             *ptr = '\0';
  83.     }
  84.     if (*name)
  85.         return 0;
  86.     
  87.     /* aw hell, i give up!  is this really unix? */
  88.     return -1;
  89. }
  90. #endif /* GETHOSTNAME */
  91. #endif /* UNAME */
  92.