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
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]
23 * Copyright 1997 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
31 * University Copyright- Copyright (c) 1982, 1986, 1988
32 * The Regents of the University of California
35 * University Acknowledgment- Portions of this document are derived from
36 * software developed by the University of California, Berkeley, and its
40 #pragma ident "%Z%%M% %I% %E% SMI"
46 #include <sys/systeminfo.h>
48 char *getlogin(), *ttyname(int);
53 * Determine the local and remote user, tty, and machines
56 struct hostent
*gethostbyname();
63 char hostname
[HOST_NAME_LENGTH
+ 1];
66 char *my_machine_name
;
67 char *rem_machine_name
;
75 "Usage: talk %s\n", gettext("address [terminal]"));
80 gettext("Standard input must be a tty, not a pipe or a file\n"));
86 gettext("Standard output must be a tty, not a pipe or a file\n"));
90 if ((my_name
= getlogin()) == NULL
) {
91 struct passwd
*pass
= getpwuid(getuid());
93 my_name
= pass
->pw_name
;
95 if (my_name
== NULL
) {
97 gettext("Who are you? You have no entry in /etc/utmp! Aborting..\n"));
101 name_length
= HOST_NAME_LENGTH
;
102 (void) sysinfo(SI_HOSTNAME
, hostname
, name_length
);
103 my_machine_name
= hostname
;
105 my_tty
= strrchr(ttyname(0), '/') + 1;
108 * check for, and strip out, the machine name of the target
111 for (ptr
= argv
[1]; *ptr
!= '\0' &&
115 *ptr
!= '.'; ptr
++) {
120 /* this is a local to local talk */
123 rem_machine_name
= my_machine_name
;
130 rem_machine_name
= ptr
+ 1;
132 /* host.user or host!user or host:user */
134 rem_machine_name
= argv
[1];
141 rem_tty
= argv
[2]; /* tty name is arg 2 */
146 get_addrs(my_machine_name
, rem_machine_name
);
148 /* Load these useful values into the standard message header */
152 strncpy(msg
.l_name
, my_name
, NAME_SIZE
);
153 msg
.l_name
[NAME_SIZE
- 1] = '\0';
155 strncpy(msg
.r_name
, rem_name
, NAME_SIZE
);
156 msg
.r_name
[NAME_SIZE
- 1] = '\0';
158 strncpy(msg
.r_tty
, rem_tty
, TTY_SIZE
);
159 msg
.r_tty
[TTY_SIZE
- 1] = '\0';