]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - hunt/huntd/ctl_transact.c
1 /* $NetBSD: ctl_transact.c,v 1.2 1997/10/10 16:33:01 lukem Exp $ */
3 * Copyright (c) 1983 Regents of the University of California.
4 * All rights reserved. The Berkeley software License Agreement
5 * specifies the terms and conditions for redistribution.
10 #if defined(TALK_43) || defined(TALK_42)
12 #include <sys/cdefs.h>
15 static char sccsid
[] = "@(#)ctl_transact.c 5.2 (Berkeley) 3/13/86";
17 __RCSID("$NetBSD: ctl_transact.c,v 1.2 1997/10/10 16:33:01 lukem Exp $");
26 #define CTL_WAIT 2 /* time to wait for a response, in seconds */
30 * SOCKDGRAM is unreliable, so we must repeat messages if we have
31 * not recieved an acknowledgement within a reasonable amount
35 ctl_transact(target
, msg
, type
, rp
)
36 struct in_addr target
;
41 fd_set read_mask
, ctl_mask
;
42 int nready
, cc
, retries
;
47 daemon_addr
.sin_addr
= target
;
48 daemon_addr
.sin_port
= daemon_port
;
49 FD_SET(ctl_sockt
, &ctl_mask
);
52 * Keep sending the message until a response of
53 * the proper type is obtained.
56 wait
.tv_sec
= CTL_WAIT
;
58 /* resend message until a response is obtained */
59 for (retries
= MAX_RETRY
; retries
> 0; retries
-= 1) {
60 cc
= sendto(ctl_sockt
, (char *)&msg
, sizeof (msg
), 0,
61 (struct sockaddr
*)&daemon_addr
, sizeof (daemon_addr
));
62 if (cc
!= sizeof (msg
)) {
65 p_error("Error on write to talk daemon");
68 nready
= select(32, &read_mask
, 0, 0, &wait
);
72 p_error("Error waiting for daemon response");
80 * Keep reading while there are queued messages
81 * (this is not necessary, it just saves extra
82 * request/acknowledgements being sent)
85 cc
= recv(ctl_sockt
, (char *)rp
, sizeof (*rp
), 0);
89 p_error("Error on read from talk daemon");
92 /* an immediate poll */
94 nready
= select(32, &read_mask
, 0, 0, &wait
);
95 } while (nready
> 0 && (
97 rp
->vers
!= TALK_VERSION
||
102 rp
->vers
!= TALK_VERSION
||
105 rp
->id_num
= ntohl(rp
->id_num
);
107 rp
->addr
.sa_family
= ntohs(rp
->addr
.sa_family
);
109 rp
->addr
.sin_family
= ntohs(rp
->addr
.sin_family
);