home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / mm / mm-0.90 / hname.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-12-18  |  1.9 KB  |  107 lines

  1. /*
  2.  * Copyright (c) 1986, 1990 by The Trustees of Columbia University in
  3.  * the City of New York.  Permission is granted to any individual or
  4.  * institution to use, copy, or redistribute this software so long as it
  5.  * is not sold for profit, provided this copyright notice is retained.
  6.  */
  7.  
  8. #ifndef lint
  9. static char *rcsid = "$Header: /f/src2/encore.bin/cucca/mm/tarring-it-up/RCS/hname.c,v 2.1 90/10/04 18:24:31 melissa Exp $";
  10. #endif
  11.  
  12. /*
  13.  * hname - return the local hostname
  14.  *
  15.  */
  16.  
  17. #include "mm.h"
  18.  
  19. #ifndef MAXHOSTNAMELEN
  20. #define MAXHOSTNAMELEN 64
  21. #endif
  22.  
  23. #ifdef MMHOSTNAME
  24. char *
  25. hname ()
  26. {
  27.     return (char *) MMHOSTNAME;
  28. }
  29.  
  30. isourhost (host)
  31. {
  32.     return (ustrcmp (host, MMHOSTNAME) == 0);
  33. }
  34. #else
  35.  
  36. #ifdef GETHOSTNAME
  37. #include <netdb.h>
  38.  
  39. char *
  40. hname ()
  41. {
  42.     char name[MAXHOSTNAMELEN], *result;        
  43.     struct hostent *h, *gethostbyname();
  44.  
  45.     gethostname(name, sizeof name);
  46.     if (h = gethostbyname(name)) {    /* get host entry */
  47.     result = malloc (strlen (h->h_name) +1);
  48.     if (result)
  49.         strcpy (result, h->h_name);
  50.     else
  51.         panic ("hname: no space\n");
  52.     }
  53.  
  54.     return result;
  55. }
  56.  
  57. /*
  58.  * This is too expensive--needs to be redone.
  59.  */
  60. isourhost (host)
  61. char *host;
  62. {
  63.     char name[MAXHOSTNAMELEN];
  64.     struct hostent *h, *gethostbyname ();
  65.     char **aliases;
  66.  
  67.     /* don't bother the nameserver if we don't have to */
  68.     if (ustrcmp (host, ourhostname) == 0)
  69.     return true;
  70.  
  71.     if (h = gethostbyname (host)) {
  72.     if (ustrcmp (h->h_name, ourhostname) == 0)
  73.         return true;
  74.     }
  75.  
  76.     return false;
  77. }
  78. #else
  79. #ifdef DOUNAME
  80. /*
  81.  * XXX - not tested
  82.  */
  83. #include <sys/utsname>
  84.  
  85. char *
  86. hname ()
  87. {
  88.     char *result;
  89.     struct utsname name;
  90.  
  91.     uname (&name);
  92.     result = malloc (strlen (name.nodename) + 4);
  93.     if (result)
  94.     strcpy (result, name.nodename);
  95.     else
  96.     panic ("hname: no space\n");
  97.     return result;
  98. }
  99.  
  100. isourhost (host)
  101. {
  102.     return (ustrcmp (host, ourhostname) == 0);
  103. }
  104. #endif /* !DOUNAME */ */
  105. #endif /* !GETHOSTNAME */
  106. #endif /* !defined (MMHOSTNAME) */
  107.