|
|
1.1 ! root 1: #include <sys/types.h> ! 2: #include <sys/stat.h> ! 3: #include <sys/ioctl.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: ! 22: ! 23: int ! 24: net_dial(ip) ! 25: ipcinfo *ip; ! 26: { ! 27: return dkdial(ip, 3); ! 28: } ! 29: ! 30: int ! 31: net_announce(ip) ! 32: ipcinfo *ip; ! 33: { ! 34: return dkdial(ip, 2); ! 35: } ! 36: ! 37: int ! 38: dkdial(ip, serv) ! 39: ipcinfo *ip; ! 40: int serv; ! 41: { ! 42: int fd; ! 43: int listener; ! 44: int i; ! 45: struct listenin d; ! 46: char dialstr[BUFSIZE]; ! 47: char dialtone[2]; ! 48: register char *dp, *cp; ! 49: struct stat st; ! 50: struct dialout reply; ! 51: int traffic=0; ! 52: ! 53: /* get type of request and properties */ ! 54: for(dp = ip->param; *dp; dp++) { ! 55: for(;*dp && *dp==' '; dp++); ! 56: if (strncmp(dp, "heavy", 5)==0 && (dp[5]=='\0'||dp[5]==' ')) ! 57: traffic = 2; ! 58: for(;*dp && *dp!=' '; dp++); ! 59: } ! 60: ! 61: /* establish the initial connection */ ! 62: fd = dkchan(traffic, unit); ! 63: if (fd < 0) ! 64: return ABORT(EBUSY, "out of output channels", NULLINFO); ! 65: dkproto(fd, dkp_ld); ! 66: ioctl(fd, FIOPUSHLD, &rdk_ld); ! 67: ! 68: /* set up the parameter block for the initial request */ ! 69: fstat(fd, &st); ! 70: d.l_type = T_SRV; ! 71: d.l_lchan = minor(st.st_rdev); ! 72: d.l_srv = 256 - serv; ! 73: d.l_param0 = traffic; ! 74: d.l_param1 = 0; ! 75: d.l_param2 = 0; ! 76: d.l_param3 = 0; ! 77: d.l_param4 = 0; ! 78: d.l_param5 = 0; ! 79: ! 80: /* ! 81: * convert '!'s to '.'s . escape all '.'s after the first '!'. ! 82: */ ! 83: for(cp=ip->name, dp=dialstr; *cp; cp++) ! 84: if (*cp=='!'){ ! 85: *dp++ = '.'; ! 86: cp++; ! 87: break; ! 88: } else ! 89: *dp++ = *cp; ! 90: for(; *cp; cp++) ! 91: if (*cp=='!'){ ! 92: *dp++ = '.'; ! 93: } else if (*cp=='.'){ ! 94: *dp++ = '\\'; ! 95: *dp++ = '.'; ! 96: } else ! 97: *dp++ = *cp; ! 98: *dp = '\0'; ! 99: strcat(dialstr, "\n"); ! 100: strcat(dialstr, ip->user); ! 101: strcat(dialstr, "\n"); ! 102: listener = dkctlchan(); ! 103: if (listener < 0) ! 104: return ABORT(errno,"can't get dk control channel",NULLINFO); ! 105: i = write(listener, (char *)&d, sizeof(d)); ! 106: close(listener); ! 107: if (i != sizeof(d)) { ! 108: close(fd); ! 109: return ABORT(EIO, "can't dial out on dk", NULLINFO); ! 110: } ! 111: i = read(fd, dialtone, 1); ! 112: if (i < 0) { ! 113: close(fd); ! 114: return ABORT(EIO, "no dial tone from dk", NULLINFO); ! 115: } ! 116: if (dialtone[0] != 'O') { ! 117: close(fd); ! 118: return ABORT(EIO, "wrong dial tone from dk", NULLINFO); ! 119: } ! 120: ioctl(fd, DIOCSTOP, 0); ! 121: write(fd, dialstr, strlen(dialstr)); ! 122: i = read(fd, (char *)&reply, sizeof reply); ! 123: if (i <= 0) { ! 124: close(fd); ! 125: return ABORT(EIO,"remote system doesn't respond", ! 126: (ipcinfo *)NULL); ! 127: } ! 128: ! 129: /* successful reply, analyze it */ ! 130: if (reply.srv!=D_OPEN) { ! 131: close(fd); ! 132: dktouerr(reply.param1&0x7f); ! 133: return -1; ! 134: } ! 135: if (dkproto(fd, dkp_ld) < 0) { ! 136: close(fd); ! 137: return ABORT(EIO, "can't push line discipline",NULLINFO); ! 138: } ! 139: if (W_VALID(reply.param4)) { /* check window sizes */ ! 140: char ws[5]; ! 141: long wins = W_VALUE(reply.param4)>>2; ! 142: /* use 3 X wins/4 */ ! 143: ws[0] = wins; ! 144: ws[1] = wins>>8; ! 145: ws[2] = wins>>16; ! 146: ws[3] = wins>>24; ! 147: ws[4] = 3; ! 148: ioctl(fd, DIOCXWIN, ws); ! 149: } ! 150: ioctl(fd, FIOPOPLD, 0); /* dump rdk */ ! 151: ip->myname = "who_knows"; ! 152: return fd; ! 153: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.