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 2000 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"
44 #include <sys/isa_defs.h>
47 #define bcopy(a, b, c) memcpy((b), (a), (c))
50 static int look_for_invite(CTL_RESPONSE
*);
51 static CTL_RESPONSE
swapresponse();
54 /* see if the local daemon has a invitation for us */
59 CTL_RESPONSE response
;
61 /* the rest of msg was set up in get_names */
63 msg
.ctl_addr
= ctl_addr
;
65 if (!look_for_invite(&response
)) {
67 /* we must be initiating a talk */
73 * there was an invitation waiting for us,
74 * so connect with the other (hopefully waiting) party
77 current_state
= gettext("Waiting to connect with caller");
79 response
= swapresponse(response
);
80 while (connect(sockt
, (struct sockaddr
*)&response
.addr
,
81 sizeof (response
.addr
)) != 0) {
82 if (errno
== ECONNREFUSED
) {
85 * the caller gave up, but the invitation somehow
86 * was not cleared. Clear it and initiate an
87 * invitation. (We know there are no newer invitations,
88 * the talkd works LIFO.)
91 ctl_transact(rem_machine_addr
, msg
, DELETE
, &response
);
95 } else if (errno
== EINTR
) {
97 /* we have returned from an interupt handler */
100 p_error(gettext("Unable to connect with initiator"));
107 /* look for an invitation on 'machine' */
110 look_for_invite(response
)
111 CTL_RESPONSE
*response
;
113 current_state
= gettext("Checking for invitation on caller's machine");
115 ctl_transact(rem_machine_addr
, msg
, LOOK_UP
, response
);
118 * switch is for later options, such as multiple invitations
121 switch (response
->answer
) {
125 msg
.id_num
= response
->id_num
;
129 /* there wasn't an invitation waiting for us */
135 * heuristic to detect if need to reshuffle CTL_RESPONSE structure
138 #if defined(_LITTLE_ENDIAN)
139 struct ctl_response_runrise
{
144 struct sockaddr_in addr
;
151 struct ctl_response_runrise swaprsp
;
153 if (rsp
.addr
.sin_family
!= AF_INET
) {
154 bcopy(&rsp
, &swaprsp
, sizeof (CTL_RESPONSE
));
155 if (swaprsp
.addr
.sin_family
== AF_INET
) {
156 rsp
.addr
= swaprsp
.addr
;
157 rsp
.type
= swaprsp
.type
;
158 rsp
.answer
= swaprsp
.answer
;
159 rsp
.id_num
= swaprsp
.id_num
;
166 #if defined(_BIG_ENDIAN)
167 struct ctl_response_sun3
{
170 unsigned short id_num2
;
171 unsigned short id_num1
;
182 struct ctl_response_sun3 swaprsp
;
184 if (rsp
.addr
.sin_family
!= AF_INET
) {
185 bcopy(&rsp
, &swaprsp
, sizeof (struct ctl_response_sun3
));
186 if (swaprsp
.sin_family
== AF_INET
) {
187 rsp
.type
= swaprsp
.type
;
188 rsp
.answer
= swaprsp
.answer
;
189 rsp
.id_num
= swaprsp
.id_num1
190 | (swaprsp
.id_num2
<< 16);
191 rsp
.addr
.sin_family
= swaprsp
.sin_family
;
192 rsp
.addr
.sin_port
= swaprsp
.sin_port
;
193 rsp
.addr
.sin_addr
.s_addr
=
194 (swaprsp
.sin_addr2
<< 16)| swaprsp
.sin_addr1
;