]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - hunt/huntd/ctl_transact.c
1 /* $NetBSD: ctl_transact.c,v 1.6 2003/06/11 12:00:22 wiz Exp $ */
3 * Copyright (c) 1983-2003, Regents of the University of California.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
10 * + Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * + Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * + Neither the name of the University of California, San Francisco nor
16 * the names of its contributors may be used to endorse or promote
17 * products derived from this software without specific prior written
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 #if defined(TALK_43) || defined(TALK_42)
37 #include <sys/cdefs.h>
40 static char sccsid
[] = "@(#)ctl_transact.c 5.2 (Berkeley) 3/13/86";
42 __RCSID("$NetBSD: ctl_transact.c,v 1.6 2003/06/11 12:00:22 wiz Exp $");
51 #define CTL_WAIT 2 /* time to wait for a response, in seconds */
55 * SOCKDGRAM is unreliable, so we must repeat messages if we have
56 * not received an acknowledgement within a reasonable amount
60 ctl_transact(target
, msg
, type
, rp
)
61 struct in_addr target
;
67 int nready
, cc
, retries
;
71 daemon_addr
.sin_addr
= target
;
72 daemon_addr
.sin_port
= daemon_port
;
73 set
[0].fd
= ctl_sockt
;
74 set
[0].events
= POLLIN
;
77 * Keep sending the message until a response of
78 * the proper type is obtained.
81 /* resend message until a response is obtained */
82 for (retries
= MAX_RETRY
; retries
> 0; retries
-= 1) {
83 cc
= sendto(ctl_sockt
, (char *)&msg
, sizeof (msg
), 0,
84 &daemon_addr
, sizeof (daemon_addr
));
85 if (cc
!= sizeof (msg
)) {
88 p_error("Error on write to talk daemon");
90 nready
= poll(set
, 1, CTL_WAIT
* 1000);
94 p_error("Error waiting for daemon response");
102 * Keep reading while there are queued messages
103 * (this is not necessary, it just saves extra
104 * request/acknowledgements being sent)
107 cc
= recv(ctl_sockt
, (char *)rp
, sizeof (*rp
), 0);
111 p_error("Error on read from talk daemon");
113 /* an immediate poll */
114 nready
= poll(set
, 1, 0);
115 } while (nready
> 0 && (
117 rp
->vers
!= TALK_VERSION
||
122 rp
->vers
!= TALK_VERSION
||
125 rp
->id_num
= ntohl(rp
->id_num
);
127 rp
->addr
.sa_family
= ntohs(rp
->addr
.sa_family
);
129 rp
->addr
.sin_family
= ntohs(rp
->addr
.sin_family
);