7
/* #include <get_hostname.h>
9
/* const char *get_hostname()
11
/* get_hostname() returns the local hostname as obtained
12
/* via gethostname() or its moral equivalent. This routine
13
/* goes to great length to avoid dependencies on any network
16
/* Fatal errors: no hostname, invalid hostname.
22
/* The Secure Mailer license must be distributed with this software.
25
/* IBM T.J. Watson Research
27
/* Yorktown Heights, NY 10598, USA
33
#include <sys/param.h>
37
#if (MAXHOSTNAMELEN < 256)
39
#define MAXHOSTNAMELEN 256
42
/* Utility library. */
46
#include "valid_hostname.h"
47
#include "get_hostname.h"
51
static char *my_host_name;
53
/* get_hostname - look up my host name */
55
const char *get_hostname(void)
57
char namebuf[MAXHOSTNAMELEN + 1];
60
* The gethostname() call is not (or not yet) in ANSI or POSIX, but it is
61
* part of the socket interface library. We avoid the more politically-
62
* correct uname() routine because that has no portable way of dealing
63
* with long (FQDN) hostnames.
65
if (my_host_name == 0) {
66
if (gethostname(namebuf, sizeof(namebuf)) < 0)
67
msg_fatal("gethostname: %m");
68
namebuf[MAXHOSTNAMELEN] = 0;
69
if (valid_hostname(namebuf, DO_GRIPE) == 0)
70
msg_fatal("unable to use my own hostname");
71
my_host_name = mystrdup(namebuf);
73
return (my_host_name);