Annotation of researchv10dc/ipc/internet/dkslip.c, revision 1.1

1.1     ! root        1: #include <stdio.h>
        !             2: #include <sgtty.h>
        !             3: #include <signal.h>
        !             4: 
        !             5: main(argc, argv)
        !             6: char *argv[];
        !             7: {
        !             8:        char buf[512];
        !             9:        int n, pid, cpid, ld, ptfd, rem;
        !            10:        extern cdkp_ld;
        !            11: 
        !            12:        if(argc != 3){
        !            13:                fprintf(stderr, "Usage: %s dk-host pt\n", argv[0]);
        !            14:                exit(1);
        !            15:        }
        !            16:        if((ptfd = open(argv[2], 2)) < 0){
        !            17:                perror(argv[2]);
        !            18:                exit(1);
        !            19:        }
        !            20:        rem = tdkdial(argv[1], 0);
        !            21:        if(rem < 0){
        !            22:                perror("tdkdial");
        !            23:                exit(1);
        !            24:        }
        !            25:        if(dkproto(rem, cdkp_ld) < 0){
        !            26:                perror("dkproto cdkp");
        !            27:                exit(1);
        !            28:        }
        !            29: 
        !            30:        if(read(rem, buf, 1) != 1){
        !            31:                perror("init read");
        !            32:                exit(1);
        !            33:        }
        !            34:        write(rem, "slip\r", 5);
        !            35: 
        !            36:        sleep(3);
        !            37: /*
        !            38:        read(rem, buf, sizeof(buf));
        !            39: */
        !            40:        write(rem, "forbes sl0\r", 11);
        !            41: 
        !            42:        signal(SIGHUP, SIG_IGN);
        !            43:        pid = getpid();
        !            44:        cpid = fork();
        !            45:        if(cpid == 0){
        !            46:                rint(rem, ptfd);
        !            47:                kill(pid, 9);
        !            48:                exit(0);
        !            49:        }
        !            50:        out(ptfd, rem);
        !            51:        kill(cpid, 9);
        !            52: }
        !            53: #define END 0300
        !            54: #define ESC 0333
        !            55: #define TRANS_END 0334
        !            56: #define TRANS_ESC 0335
        !            57: rint(rfd, wfd)
        !            58: {
        !            59:        static escaped = 0;
        !            60:        int count = 0, len;
        !            61:        unsigned int c;
        !            62:        unsigned char buf[4096];
        !            63:        unsigned char xbuf[512];
        !            64:        int i, n;
        !            65: 
        !            66:        len = 0;
        !            67:        while((n = read(rfd, xbuf, sizeof(xbuf))) > 0)
        !            68:        for(i = 0; i < n; i++){
        !            69:                c = xbuf[i];
        !            70:                if(escaped){
        !            71:                        if(c == TRANS_ESC){
        !            72:                                c = ESC;
        !            73:                        } else {
        !            74:                                c = END;
        !            75:                        }
        !            76:                        escaped = 0;
        !            77:                } else {
        !            78:                        if(c == ESC){
        !            79:                                escaped = 1;
        !            80:                                continue;
        !            81:                        } else if(c == END){
        !            82:                                if(write(wfd, buf, len) != len){
        !            83:                                        perror("write");
        !            84:                                        return;
        !            85:                                }
        !            86:                                escaped = count = len = 0;
        !            87:                                continue;
        !            88:                        }
        !            89:                }
        !            90:                buf[len++] = c;
        !            91:        }
        !            92: }
        !            93: 
        !            94: out(rfd, wfd)
        !            95: {
        !            96:        char buf[4096];
        !            97:        char xbuf[5000];
        !            98:        int xi;
        !            99:        int n;
        !           100:        unsigned char c;
        !           101:        int i;
        !           102: 
        !           103:        while((n = read(rfd, buf, sizeof(buf))) > 0){
        !           104:                xi = 0;
        !           105:                for(i = 0; i < n; i++){
        !           106:                        c = buf[i];
        !           107:                        if(c == ESC || c == END){
        !           108:                                xbuf[xi++] = '\333';
        !           109:                                c = (c == ESC ? TRANS_ESC : TRANS_END);
        !           110:                        }
        !           111:                        xbuf[xi++] = c;
        !           112:                }
        !           113:                xbuf[xi++] = '\300';
        !           114:                write(wfd, xbuf, xi);
        !           115:        }
        !           116: }

unix.superglobalmegacorp.com

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