|
|
1.1 root 1: #define DKMSGS 1
2: #include <sys/types.h>
3: #include <stdio.h>
4: #include <dk.h>
5: #include <pwd.h>
6: #include <signal.h>
7: #include <sys/ioctl.h>
8: #include "dkdial.h"
9: #include <sys/stat.h>
10: #include <dkwindow.h>
11:
12: void alarmcatch();
13: char *getlogin();
14: struct dialout reply;
15: int pipefd;
16:
17: main (argc, argv)
18: int argc;
19: char **argv;
20: {
21: int fd, server;
22: int retval, listener;
23: struct listenin d;
24: register char **p;
25: struct stat st;
26: char dialstr[64];
27: char dialtone[2];
28: int rc;
29: int traffic;
30: register char *cp;
31:
32: /* pick up and decode arguments */
33: if (argc != 6)
34: bugout(ILLEG);
35: p = argv + 1;
36: fd = atoi (*p++);
37: pipefd = atoi (*p++);
38: server = atoi (*p++);
39: if (server==1)
40: server = 3;
41: traffic = atoi(*p++);
42: strcpy(dialstr, *p);
43: cp = dialstr;
44: while (*cp) {
45: if (*cp == '\n')
46: *cp = '\0';
47: cp++;
48: }
49:
50: /* set up the parameter block for the initial request */
51: fstat(fd, &st);
52: d.l_type = T_SRV;
53: d.l_lchan = minor(st.st_rdev);
54: d.l_srv = 256 - server;
55: d.l_param0 = traffic;
56: /*
57: d.l_param0 = WINDOW(WS_4K, WS_4K, traffic);
58: */
59: d.l_param1 = 0;
60: d.l_param2 = 0;
61: d.l_param3 = 0;
62: d.l_param4 = 0;
63: d.l_param5 = 0;
64: strcat(dialstr, "\n");
65: cp = getlogin();
66: if (cp == 0)
67: bugout(NOUID);
68: strcat(dialstr, cp);
69: strcat(dialstr, "\n");
70: signal (SIGALRM, alarmcatch);
71: alarm (15);
72: listener = dkctlchan(traffic);
73: if (listener < 0)
74: bugout(NOMGR);
75: rc = write(listener, (char *)&d, sizeof(d));
76: if (rc != sizeof(d))
77: bugout(NODIALT);
78: close(listener);
79: alarm (15);
80: rc = read(fd, dialtone, 1);
81: if (rc < 0)
82: bugout(NODIALT);
83: if (dialtone[0] != 'O')
84: bugout(NODIALT);
85: ioctl(fd, DIOCSTOP, 0);
86: write(fd, dialstr, strlen(dialstr));
87: alarm(60);
88: rc = read(fd, &reply, sizeof reply);
89: alarm (0);
90: if (rc <= 0)
91: bugout(NOREP);
92: write(pipefd, &reply, sizeof reply);
93:
94: /* assume normal exit */
95: retval = NORM;
96:
97: /* successful reply, analyze it */
98: switch (reply.srv) {
99: case D_OPEN:
100: if (W_VALID(reply.param4)) { /* check window size */
101: char ws[5];
102: long wins = W_VALUE(W_DEST(reply.param4))>>2;
103: /* use 3 X wins/4 */
104: ws[0] = wins;
105: ws[1] = wins>>8;
106: ws[2] = wins>>16;
107: ws[3] = wins>>24;
108: ws[4] = 3;
109: ioctl(fd, DIOCXWIN, ws);
110: }
111: break;
112:
113: case D_FAIL:
114: exit(ERRBASE + (reply.param1&0x7f));
115: }
116: return retval;
117: }
118:
119: void
120: alarmcatch()
121: {
122: }
123:
124: /*
125: * write some sort of reply
126: * (obsolete, but some old callers use it)
127: */
128: bugout(r)
129: {
130: reply.srv = D_FAIL;
131: write(pipefd, (char *)&reply, sizeof(reply));
132: exit(r);
133: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.