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 1994 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 * Copyright (c) 2016 by Delphix. All rights reserved.
43 #pragma ident "%Z%%M% %I% %E% SMI"
52 #define signal(s, f) sigset(s, f)
56 * There wasn't an invitation waiting, so send a request containing
57 * our socket address to the remote talk daemon so it can invite
61 static int local_id
, remote_id
;
64 * the msg.id's for the invitations
65 * on the local and remote machines.
66 * These are used to delete the invitations.
69 static jmp_buf invitebuf
;
71 static void re_invite();
72 static void announce_invite();
78 struct itimerval itimer
;
79 CTL_RESPONSE response
;
81 itimer
.it_value
.tv_sec
= RING_WAIT
;
82 itimer
.it_value
.tv_usec
= 0;
83 itimer
.it_interval
= itimer
.it_value
;
85 if (listen(sockt
, 5) != 0) {
86 p_error(gettext("Error on attempt to listen for caller"));
90 msg
.id_num
= -1; /* an impossible id_num */
92 invitation_waiting
= 1;
97 * shut off the automatic messages for a while,
98 * so we can use the interupt timer to resend the invitation
102 setitimer(ITIMER_REAL
, &itimer
, (struct itimerval
*)0);
103 message(gettext("Waiting for your party to respond"));
104 signal(SIGALRM
, re_invite
);
105 (void) setjmp(invitebuf
);
107 while ((new_sockt
= accept(sockt
, 0, 0)) < 0) {
108 if (errno
!= EINTR
) {
109 p_error(gettext("Unable to connect with your party"));
111 /* we just returned from a interupt, keep trying */
120 * have the daemons delete the invitations now that we have connected.
123 current_state
= strdup(gettext("Waiting for your party to respond"));
126 msg
.id_num
= local_id
;
127 ctl_transact(my_machine_addr
, msg
, DELETE
, &response
);
128 msg
.id_num
= remote_id
;
129 ctl_transact(rem_machine_addr
, msg
, DELETE
, &response
);
130 invitation_waiting
= 0;
133 /* routine called on interupt to re-invite the callee */
138 message(gettext("Ringing your party again"));
140 /* force a re-announce */
141 msg
.id_num
= remote_id
+ 1;
143 longjmp(invitebuf
, 1);
146 /* transmit the invitation and process the response */
151 CTL_RESPONSE response
;
154 gettext("Trying to connect to your party's talk daemon");
156 ctl_transact(rem_machine_addr
, msg
, ANNOUNCE
, &response
);
157 remote_id
= response
.id_num
;
159 if (response
.answer
!= SUCCESS
) {
161 switch (response
.answer
) {
164 message(gettext("Your party is not logged on"));
167 case MACHINE_UNKNOWN
:
169 gettext("Target machine does not recognize us"));
172 case UNKNOWN_REQUEST
:
174 gettext("Target machine can not handle remote talk"));
179 gettext("Target machine is too confused to talk to us"));
182 case PERMISSION_DENIED
:
183 message(gettext("Your party is refusing messages"));
190 /* leave the actual invitation on my talk daemon */
192 ctl_transact(my_machine_addr
, msg
, LEAVE_INVITE
, &response
);
193 local_id
= response
.id_num
;
200 /* tell the daemon to remove your invitation */
205 * this is just a extra clean up, so just send it
206 * and don't wait for an answer
209 msg
.id_num
= remote_id
;
210 daemon_addr
.sin_addr
= rem_machine_addr
;
211 if (sendto(ctl_sockt
, (char *)&msg
, sizeof (CTL_MSG
), 0,
212 (struct sockaddr
*)&daemon_addr
,
213 sizeof (daemon_addr
)) != sizeof (CTL_MSG
)) {
214 perror(gettext("send_delete remote"));
217 msg
.id_num
= local_id
;
218 daemon_addr
.sin_addr
= my_machine_addr
;
219 if (sendto(ctl_sockt
, (char *)&msg
, sizeof (CTL_MSG
), 0,
220 (struct sockaddr
*)&daemon_addr
,
221 sizeof (daemon_addr
)) != sizeof (CTL_MSG
)) {
222 perror(gettext("send_delete local"));