1: /*
2: * Copyright (c) 1985 Regents of the University of California.
3: * All rights reserved. The Berkeley software License Agreement
4: * specifies the terms and conditions for redistribution.
5: */
6:
7: #ifndef lint
8: static char sccsid[] = "@(#)acksend.c 2.4 (Berkeley) 5/27/86";
9: #endif not lint
10:
11: #include "globals.h"
12: #include <protocols/timed.h>
13:
14: #define RECEIVED 0
15: #define LOST 1
16: #define SECFORACK 1 /* seconds */
17: #define USECFORACK 0 /* microseconds */
18: #define MAXCOUNT 5
19:
20: struct tsp *answer;
21:
22: /*
23: * Acksend implements reliable datagram transmission by using sequence
24: * numbers and retransmission when necessary.
25: * `name' is the name of the destination
26: * `addr' is the address to send to
27: * If `name' is ANYADDR, this routine implements reliable broadcast.
28: */
29:
30: struct tsp *acksend(message, addr, name, ack, net)
31: struct tsp *message;
32: struct sockaddr_in *addr;
33: char *name;
34: int ack;
35: struct netinfo *net;
36: {
37: int count;
38: int flag;
39: extern u_short sequence;
40: struct timeval tout;
41: struct tsp *readmsg();
42:
43: count = 0;
44:
45: message->tsp_vers = TSPVERSION;
46: message->tsp_seq = sequence;
47: if (trace) {
48: fprintf(fd, "acksend: ");
49: if (name == ANYADDR)
50: fprintf(fd, "broadcast: ");
51: else
52: fprintf(fd, "%s: ", name);
53: print(message, addr);
54: }
55: bytenetorder(message);
56: do {
57: if (sendto(sock, (char *)message, sizeof(struct tsp), 0, addr,
58: sizeof(struct sockaddr_in)) < 0) {
59: syslog(LOG_ERR, "acksend: sendto: %m");
60: exit(1);
61: }
62: tout.tv_sec = SECFORACK;
63: tout.tv_usec = USECFORACK;
64: answer = readmsg(ack, name, &tout, net);
65: if (answer != NULL) {
66: if (answer->tsp_seq != sequence) {
67: if (trace)
68: fprintf(fd, "acksend: seq # %d != %d\n",
69: answer->tsp_seq, sequence);
70: continue;
71: }
72: flag = RECEIVED;
73: } else {
74: flag = LOST;
75: if (++count == MAXCOUNT) {
76: break;
77: }
78: }
79: } while (flag != RECEIVED);
80: sequence++;
81: return(answer);
82: }
Defined functions
acksend
defined in line
30; used 28 times
- in /usr/src/etc/timed/candidate.c line
29,
91
- in /usr/src/etc/timed/correct.c line
30,
55
- in /usr/src/etc/timed/master.c line
51,
186,
208,
214,
252,
368,
374,
506,
522
- in /usr/src/etc/timed/slave.c line
30,
269,
302,
358,
367,
391,
397,
415,
466,
474,
507,
515
- in /usr/src/etc/timed/timed.c line
424,
433,
489
Defined variables
sccsid
defined in line
8;
never used
Defined macros
LOST
defined in line
15; used 1 times