xref: /titanic_50/usr/src/cmd/mailx/hostname.c (revision 2df1fe9ca32bb227b9158c67f5c00b54c20b10fd)
1 /*
2  * CDDL HEADER START
3  *
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.
8  *
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.
13  *
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]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 1998 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
28 /*	  All Rights Reserved  	*/
29 
30 
31 /*
32  * University Copyright- Copyright (c) 1982, 1986, 1988
33  * The Regents of the University of California
34  * All Rights Reserved
35  *
36  * University Acknowledgment- Portions of this document are derived from
37  * software developed by the University of California, Berkeley, and its
38  * contributors.
39  */
40 
41 #pragma ident	"%Z%%M%	%I%	%E% SMI"
42 
43 /*
44  * mailx -- a modified version of a University of California at Berkeley
45  *	mail program
46  *
47  * Code to figure out what host we are on.
48  */
49 
50 #include "rcv.h"
51 #include "configdefs.h"
52 #include <sys/utsname.h>
53 #include <locale.h>
54 
55 #define	MAILCNFG	"/etc/mail/mailcnfg"
56 
57 char host[64];
58 char domain[128];
59 /*
60  * Initialize the network name of the current host.
61  */
62 void
63 inithost(void)
64 {
65 	register struct netmach *np;
66 	struct utsname name;
67 	char *fp;
68 
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);
75 	}
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);
84 	}
85 	np->nt_machine = host;
86 	np++;
87 	np->nt_machine = domain;
88 	if (debug) fprintf(stderr, "host '%s', domain '%s'\n", host, domain);
89 }
90