Annotation of researchv10no/ipc/mgrs/dkmgr/dial.c, revision 1.1

1.1     ! root        1: #include <sys/types.h>
        !             2: #include <sys/stat.h>
        !             3: #include <sys/filio.h>
        !             4: #include <dk.h>
        !             5: #include <dkerr.h>
        !             6: #include <stdio.h>
        !             7: #include <signal.h>
        !             8: #include <errno.h>
        !             9: #include <ipc.h>
        !            10: #include <libc.h>
        !            11: #include "defs.h"
        !            12: #include <dkwindow.h>
        !            13: #include <sys/dkio.h>
        !            14: 
        !            15: /* imported */
        !            16: extern int     rdk_ld;
        !            17: extern int     dkp_ld;
        !            18: extern int     dt_ld;
        !            19: extern         int     errno;
        !            20: extern int unit;
        !            21: extern int lastdkchan;
        !            22: 
        !            23: 
        !            24: int
        !            25: net_dial(ip)
        !            26:        ipcinfo *ip;
        !            27: {
        !            28:        return dkdial(ip, 3);
        !            29: }
        !            30: 
        !            31: int
        !            32: net_announce(ip)
        !            33:        ipcinfo *ip;
        !            34: {
        !            35:        register char *dp;
        !            36: 
        !            37:        /*
        !            38:         * hack: assertively set unit
        !            39:         *   when announcing, use traffic type to decide on interface to use
        !            40:         */
        !            41:        if (unit == 'b') {
        !            42: 
        !            43:                /* get type of request and properties */
        !            44:                unit = '0';
        !            45:                for(dp = ip->param; *dp; dp++) {
        !            46:                        for(;*dp && *dp==' '; dp++);
        !            47:                        if (strncmp(dp, "heavy", 5)==0 && (dp[5]=='\0'||dp[5]==' '))
        !            48:                                unit = '2';
        !            49:                        for(;*dp && *dp!=' '; dp++);
        !            50:                }
        !            51:        }
        !            52: 
        !            53:        return dkdial(ip, 2);
        !            54: }
        !            55: 
        !            56: int
        !            57: net_redial(ip)
        !            58:        ipcinfo *ip;
        !            59: {
        !            60:        return -1;
        !            61: }
        !            62: 
        !            63: int
        !            64: dkdial(ip, serv)
        !            65:        ipcinfo *ip;
        !            66:        int serv;
        !            67: {
        !            68:        int fd;
        !            69:        int listener;
        !            70:        int i;
        !            71:        struct listenin d;
        !            72:        char dialstr[128];
        !            73:        char dialtone[2];
        !            74:        register char *dp, *cp;
        !            75:        int chan;
        !            76:        struct dialout reply;
        !            77:        int traffic=0;
        !            78:        int al_catch();
        !            79: 
        !            80:        /* get type of request and properties */
        !            81:        for(dp = ip->param; *dp; dp++) {
        !            82:                for(;*dp && *dp==' '; dp++);
        !            83:                if (strncmp(dp, "heavy", 5)==0 && (dp[5]=='\0'||dp[5]==' '))
        !            84:                        traffic = 2;
        !            85:                for(;*dp && *dp!=' '; dp++);
        !            86:        }
        !            87: 
        !            88:        /* establish the initial connection */
        !            89:        signal(SIGALRM, al_catch);
        !            90:        fd = dkchan(traffic, unit, &chan);
        !            91:        if (fd < 0)
        !            92:                return ABORT(EBUSY, "out of output channels", NULLINFO);
        !            93:        dkproto(fd, dkp_ld);
        !            94:        ioctl(fd, FIOPUSHLD, &rdk_ld);
        !            95: 
        !            96:        /* set up the parameter block for the initial request */
        !            97:        d.l_type = T_SRV;
        !            98:        d.l_lchan = chan;
        !            99:        d.l_srv = 256 - serv;
        !           100:        d.l_param0 = traffic;
        !           101:        d.l_param1 = 0;
        !           102:        d.l_param2 = 0;
        !           103:        d.l_param3 = 0;
        !           104:        d.l_param4 = 0;
        !           105:        d.l_param5 = 0;
        !           106: 
        !           107:        /*
        !           108:         *  Convert first two '!'s to '.'s to comply with generic's form
        !           109:         *  of destination.service[.more-things].  Escape any '.'s in the
        !           110:         *  service part with '\'s.
        !           111:         */
        !           112:        for(i=0, cp=ip->name, dp=dialstr; *cp; cp++)
        !           113:                if (i<2 && *cp=='!'){
        !           114:                        *dp++ = '.';
        !           115:                        i++;
        !           116:                } else if (i==1 && *cp=='.') {
        !           117:                        *dp++ = '\\';
        !           118:                        *dp++ = '.';
        !           119:                } else if (*cp=='\n') {
        !           120:                        close(fd);
        !           121:                        return ABORT(EACCES, "illegal dial string", NULLINFO);
        !           122:                } else
        !           123:                        *dp++ = *cp;
        !           124:        *dp = '\0';
        !           125:        strcat(dialstr, "\n");
        !           126:        strcat(dialstr, ip->user);
        !           127:        strcat(dialstr, "\n");
        !           128:        alarm(15);
        !           129:        listener = dkctlchan(traffic, unit);
        !           130:        if (listener < 0)
        !           131:                return ABORT(errno,"can't get dk control channel",NULLINFO);
        !           132:        i = write(listener, (char *)&d, sizeof(d));
        !           133:        close(listener);
        !           134:        if (i != sizeof(d)) {
        !           135:                close(fd);
        !           136:                return ABORT(EIO, "can't dial out on dk", NULLINFO);
        !           137:        }
        !           138:        alarm(15);
        !           139:        i = read(fd, dialtone, 1);
        !           140:        if (i < 0) {
        !           141:                close(fd);
        !           142:                return ABORT(EIO, "no dial tone from dk", NULLINFO);
        !           143:        }
        !           144:        if (dialtone[0] != 'O') {
        !           145:                close(fd);
        !           146:                return ABORT(EIO, "wrong dial tone from dk", NULLINFO);
        !           147:        }
        !           148:        ioctl(fd, DIOCSTOP, 0);
        !           149:        alarm(60);
        !           150:        logevent("%s", dialstr);
        !           151:        write(fd, dialstr, strlen(dialstr));
        !           152:        i = read(fd, (char *)&reply, sizeof reply);
        !           153:        if (i <= 0) {
        !           154:                close(fd);
        !           155:                return ABORT(EIO,"remote system doesn't respond",
        !           156:                                (ipcinfo *)NULL);
        !           157:        }
        !           158: 
        !           159:        alarm(0);
        !           160:        /* successful reply, analyze it */
        !           161:        if (reply.srv!=D_OPEN) {
        !           162:                close(fd);
        !           163:                dktouerr(reply.param1&0x7f);
        !           164:                return -1;
        !           165:        }
        !           166:        if (W_VALID(reply.param4)) {    /* check window sizes */
        !           167:                char ws[5];
        !           168:                long wins = W_VALUE(W_DEST(reply.param4))>>2;
        !           169:                /* use 3 X wins/4 */
        !           170:                ws[0] = wins;
        !           171:                ws[1] = wins>>8;
        !           172:                ws[2] = wins>>16;
        !           173:                ws[3] = wins>>24;
        !           174:                ws[4] = 3;
        !           175:                ioctl(fd, DIOCXWIN, ws);
        !           176:        }
        !           177:        if (dkproto(fd, dkp_ld) < 0) {
        !           178:                close(fd);
        !           179:                return ABORT(EIO, "can't push line discipline",NULLINFO);
        !           180:        }
        !           181:        ioctl(fd, FIOPOPLD, 0);         /* dump rdk */
        !           182:        ip->machine = "";
        !           183:        ip->myname = "";
        !           184:        return fd;
        !           185: }
        !           186: 
        !           187: al_catch()
        !           188: {
        !           189: }

unix.superglobalmegacorp.com

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