Patrick Welche <prlw1@cam.ac.uk>
[netbsd-mini2440.git] / external / ibm-public / postfix / dist / src / util / get_domainname.c
blobb8deb323cdf5b17dd12ac85ffc4006805ebc7f6a
1 /* $NetBSD$ */
3 /*++
4 /* NAME
5 /* get_domainname 3
6 /* SUMMARY
7 /* network domain name lookup
8 /* SYNOPSIS
9 /* #include <get_domainname.h>
11 /* const char *get_domainname()
12 /* DESCRIPTION
13 /* get_domainname() returns the local domain name as obtained
14 /* by stripping the hostname component from the result from
15 /* get_hostname(). The result is the hostname when get_hostname()
16 /* does not return a FQDN form ("foo"), or its result has only two
17 /* components ("foo.com").
18 /* DIAGNOSTICS
19 /* Fatal errors: no hostname, invalid hostname.
20 /* SEE ALSO
21 /* get_hostname(3)
22 /* LICENSE
23 /* .ad
24 /* .fi
25 /* The Secure Mailer license must be distributed with this software.
26 /* AUTHOR(S)
27 /* Wietse Venema
28 /* IBM T.J. Watson Research
29 /* P.O. Box 704
30 /* Yorktown Heights, NY 10598, USA
31 /*--*/
33 /* System library. */
35 #include <sys_defs.h>
36 #include <string.h>
38 /* Utility library. */
40 #include "mymalloc.h"
41 #include "get_hostname.h"
42 #include "get_domainname.h"
44 /* Local stuff. */
46 static char *my_domain_name;
48 /* get_domainname - look up my domain name */
50 const char *get_domainname(void)
52 const char *host;
53 const char *dot;
56 * Use the hostname when it is not a FQDN ("foo"), or when the hostname
57 * actually is a domain name ("foo.com").
59 if (my_domain_name == 0) {
60 host = get_hostname();
61 if ((dot = strchr(host, '.')) == 0 || strchr(dot + 1, '.') == 0) {
62 my_domain_name = mystrdup(host);
63 } else {
64 my_domain_name = mystrdup(dot + 1);
67 return (my_domain_name);