1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33: #include "bsd.h"
34:
35: #if defined(TALK_43) || defined(TALK_42)
36:
37: #include <sys/cdefs.h>
38: #ifndef lint
39: #if 0
40: static char sccsid[] = "@(#)ctl_transact.c 5.2 (Berkeley) 3/13/86";
41: #else
42: __RCSID("$NetBSD: ctl_transact.c,v 1.6 2003/06/11 12:00:22 wiz Exp $");
43: #endif
44: #endif
45:
46: #include <sys/time.h>
47: #include <unistd.h>
48: #include "hunt.h"
49: #include "talk_ctl.h"
50:
51: #define CTL_WAIT 2
52: #define MAX_RETRY 5
53:
54:
55:
56:
57:
58:
59: void
60: ctl_transact(target, msg, type, rp)
61: struct in_addr target;
62: CTL_MSG msg;
63: int type;
64: CTL_RESPONSE *rp;
65: {
66: struct pollfd set[1];
67: int nready, cc, retries;
68:
69: nready = 0;
70: msg.type = type;
71: daemon_addr.sin_addr = target;
72: daemon_addr.sin_port = daemon_port;
73: set[0].fd = ctl_sockt;
74: set[0].events = POLLIN;
75:
76:
77:
78:
79:
80: do {
81:
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)) {
86: if (errno == EINTR)
87: continue;
88: p_error("Error on write to talk daemon");
89: }
90: nready = poll(set, 1, CTL_WAIT * 1000);
91: if (nready < 0) {
92: if (errno == EINTR)
93: continue;
94: p_error("Error waiting for daemon response");
95: }
96: if (nready != 0)
97: break;
98: }
99: if (retries <= 0)
100: break;
101:
102:
103:
104:
105:
106: do {
107: cc = recv(ctl_sockt, (char *)rp, sizeof (*rp), 0);
108: if (cc < 0) {
109: if (errno == EINTR)
110: continue;
111: p_error("Error on read from talk daemon");
112: }
113:
114: nready = poll(set, 1, 0);
115: } while (nready > 0 && (
116: #ifdef TALK_43
117: rp->vers != TALK_VERSION ||
118: #endif
119: rp->type != type));
120: } while (
121: #ifdef TALK_43
122: rp->vers != TALK_VERSION ||
123: #endif
124: rp->type != type);
125: rp->id_num = ntohl(rp->id_num);
126: #ifdef TALK_43
127: rp->addr.sa_family = ntohs(rp->addr.sa_family);
128: # else
129: rp->addr.sin_family = ntohs(rp->addr.sin_family);
130: # endif
131: }
132: #endif