Merge commit 'b1e7e97d3b60469b243b3b2e22c7d8cbd11c7c90'
[unleashed.git] / usr / src / cmd / mailx / hostname.c
blob7c851f2a6989a157dab8099d85f7e9c7f301b550
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
20 * CDDL HEADER END
23 * Copyright 1998 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
32 * University Copyright- Copyright (c) 1982, 1986, 1988
33 * The Regents of the University of California
34 * All Rights Reserved
36 * University Acknowledgment- Portions of this document are derived from
37 * software developed by the University of California, Berkeley, and its
38 * contributors.
41 #pragma ident "%Z%%M% %I% %E% SMI"
44 * mailx -- a modified version of a University of California at Berkeley
45 * mail program
47 * Code to figure out what host we are on.
50 #include "rcv.h"
51 #include "configdefs.h"
52 #include <sys/utsname.h>
53 #include <locale.h>
55 #define MAILCNFG "/etc/mail/mailcnfg"
57 char host[64];
58 char domain[128];
60 * Initialize the network name of the current host.
62 void
63 inithost(void)
65 register struct netmach *np;
66 struct utsname name;
67 char *fp;
69 xsetenv(MAILCNFG);
70 if (fp = xgetenv("CLUSTER")) {
71 nstrcpy(host, sizeof (host), fp);
72 } else {
73 uname(&name);
74 nstrcpy(host, sizeof (host), name.nodename);
76 snprintf(domain, sizeof (domain), "%s%s", host, maildomain());
77 for (np = netmach; np->nt_machine != 0; np++)
78 if (strcmp(np->nt_machine, EMPTY) == 0)
79 break;
80 if (np->nt_machine == 0) {
81 printf(
82 gettext("Cannot find empty slot for dynamic host entry\n"));
83 exit(1);
85 np->nt_machine = host;
86 np++;
87 np->nt_machine = domain;
88 if (debug) fprintf(stderr, "host '%s', domain '%s'\n", host, domain);