home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume4 / uumail3 / part2 / gethostnam.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-11-30  |  1.3 KB  |  71 lines

  1. #ifndef lint
  2. static char    sccsid[] = "@(#)gethostnam.c    6.1 (down!honey) 85/01/21";
  3. static char    rcsid[] = "$Header: gethostnam.c,v 6.3 85/11/23 05:30:04 UUCP Exp $";
  4. #endif lint
  5.  
  6. #ifndef GETHOSTNAME
  7. #include "uuconf.h"
  8.  
  9. void
  10. gethostname(name, len)
  11. char    *name;
  12. {
  13.     FILE    *whoami, *fopen(), *popen();
  14.     char    *ptr, *index();
  15. #if defined(SYSIII) && !defined(SYSTEMNAME)
  16.     struct utsname utsn;
  17. #endif
  18.  
  19.     *name = '\0';
  20. #ifndef SYSTEMNAME
  21. #ifdef SYSIII
  22.     if (uname(&utsn) != -1)
  23.     {
  24.         strcpy(name,utsn.nodename);
  25.         len = strlen(name);
  26.           return;
  27.     }
  28. #endif
  29. #endif
  30.  
  31. #ifdef SYSTEMNAME
  32.     /* try /usr/lib/uucp/SYSTEMNAME */
  33.     if ((whoami = fopen("/usr/lib/uucp/SYSTEMNAME", "r")) != 0) {
  34.         (void) fgets(name, len, whoami);
  35.         (void) fclose(whoami);
  36.         if ((ptr = index(name, '\n')) != 0)
  37.             *ptr = '\0';
  38.     }
  39.     if (*name)
  40.         return;
  41. #endif
  42.     /* try /usr/include/whoami.h */
  43.     if ((whoami = fopen("/usr/include/whoami.h", "r")) != 0) {
  44.         while (!feof(whoami)) {
  45.             char    buf[100];
  46.  
  47.             if (fgets(buf, 100, whoami) == 0)
  48.                 break;
  49.             if (sscanf(buf, "#define sysname \"%[^\"]\"", name))
  50.                 break;
  51.         }
  52.         (void) fclose(whoami);
  53.         if (*name)
  54.             return;
  55.     }
  56.  
  57.     /* ask uucp */
  58.     if ((whoami = popen("uuname -l", "r")) != 0) {
  59.         (void) fgets(name, len, whoami);
  60.         (void) pclose(whoami);
  61.         if ((ptr = index(name, '\n')) != 0)
  62.             *ptr = '\0';
  63.     }
  64.     if (*name)
  65.         return;
  66.     
  67.     /* failure */
  68.     return;
  69. }
  70. #endif GETHOSTNAME
  71.