Annotation of 43BSD/etc/timed/acksend.c, revision 1.1

1.1     ! root        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: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.