* Copyright (c) 1983 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
static char sccsid
[] = "@(#)look_up.c 5.1 (Berkeley) %G%";
* See if the local daemon has a invitation for us
/* the rest of msg was set up in get_names */
/* must be initiating a talk */
if (!look_for_invite(&response
))
* There was an invitation waiting for us,
* so connect with the other (hopefully waiting) party
current_state
= "Waiting to connect with caller";
if (connect(sockt
, &response
.addr
, sizeof(response
.addr
)) != -1)
if (errno
== ECONNREFUSED
) {
* The caller gave up, but his invitation somehow
* was not cleared. Clear it and initiate an
* invitation. (We know there are no newer invitations,
ctl_transact(his_machine_addr
, msg
, DELETE
, &response
);
p_error("Unable to connect with initiator");
* Look for an invitation on 'machine'
look_for_invite(response
)
struct in_addr machine_addr
;
current_state
= "Checking for invitation on caller's machine";
ctl_transact(his_machine_addr
, msg
, LOOK_UP
, response
);
/* the switch is for later options, such as multiple invitations */
switch (response
->answer
) {
msg
.id_num
= response
->id_num
;
/* there wasn't an invitation waiting for us */
* heuristic to detect if need to reshuffle CTL_RESPONSE structure
#define swapshort(a) (((a << 8) | ((unsigned short) a >> 8)) & 0xffff)
#define swaplong(a) ((swapshort(a) << 16) | (swapshort(((unsigned)a >> 16))))
struct ctl_response_vax
{
struct ctl_response_vax swaprsp
;
if (rsp
->addr
.sin_family
!= AF_INET
) {
bcopy(rsp
, &swaprsp
, sizeof(CTL_RESPONSE
));
swaprsp
.addr
.sin_family
= swapshort(swaprsp
.addr
.sin_family
);
if (swaprsp
.addr
.sin_family
== AF_INET
) {
rsp
->addr
= swaprsp
.addr
;
rsp
->type
= swaprsp
.type
;
rsp
->answer
= swaprsp
.answer
;
rsp
->id_num
= swaplong(swaprsp
.id_num
);
struct ctl_response_sun
{
struct ctl_response_sun swaprsp
;
if (rsp
->addr
.sin_family
!= AF_INET
) {
bcopy(rsp
, &swaprsp
, sizeof(struct ctl_response_sun
));
if (swaprsp
.sin_family
== swapshort(AF_INET
)) {
rsp
->type
= swaprsp
.type
;
rsp
->answer
= swaprsp
.answer
;
rsp
->id_num
= swapshort(swaprsp
.id_num1
)
| (swapshort(swaprsp
.id_num2
) << 16);
rsp
->addr
.sin_family
= swapshort(swaprsp
.sin_family
);
rsp
->addr
.sin_port
= swaprsp
.sin_port
;
rsp
->addr
.sin_addr
.s_addr
=
swaprsp
.sin_addr2
| (swaprsp
.sin_addr1
<< 16);