|
|
1.1 root 1: #include <stdio.h>
2: #include <sysexits.h>
3: #include <string.h>
4:
5: /*
6: * globals for ipc
7: */
8:
9: int ipcdebug = 0;
10:
11: extern int ipcerrno;
12:
13: extern int tcp_connect();
14: extern int dk_connect();
15: extern int mx_connect();
16: extern int proxy_connect();
17:
18: extern int tcp_close();
19: extern int dk_close();
20:
21: #define INETPROXY "tcp!inet.research.att.com!402"
22: /* #define INETPROXY "dk!nj/astro/inet.proxy"*/
23:
24: #define ATTPROXY "tcp!att-in.att.com!402"
25: /* #define ATTPROXY "dk!oh/cbl/att-in.proxy"*/
26:
27: #ifndef PROXY
28: #define PROXY ATTPROXY
29: #endif
30:
31: struct conntype {
32: char *prefix;
33: int (*connector)();
34: int (*closer)();
35: char *prhost;
36: } conntype[] = {
37: {"tcp", tcp_connect, tcp_close, NULL},
38: {"dk", dk_connect, dk_close, NULL},
39: {"mx", mx_connect, tcp_close, NULL},
40: {"proxy", proxy_connect, NULL, PROXY},
41: {"inet", proxy_connect, NULL, INETPROXY},
42: {"att", proxy_connect, NULL, ATTPROXY},
43: {NULL, NULL, NULL, NULL}
44: };
45:
46: #define MAXFD 32 /* maximum file descriptors we handle */
47: int (*closelist[MAXFD])();
48:
49: /*
50: * ipcopen - determine the network and call the open processor for it.
51: * name is of the form network!host!service
52: * param is passed on, for what it is worth.
53: */
54: int
55: ipcopen(name, param)
56: char *name, *param;
57: {
58: int fd;
59: struct conntype *ct;
60: char buf[100];
61: char *dialer = buf, *dialno;
62:
63: if (ipcdebug) {
64: setbuf(stderr, (char *)0);
65: fprintf(stderr, "ipcopen `%s` `%s`\n", name, param);
66: }
67:
68: strncpy(buf, name, sizeof(buf));
69: buf[sizeof(buf)] = '\0';
70: dialno = strchr(buf, '!');
71: if (dialno != NULL)
72: *dialno++ = '\0';
73:
74: if ((*dialer) == '\0') {
75: ipcseterror(EX_USAGE, "Dialer name missing", "Can't dial");
76: return -1;
77: }
78: for (ct = conntype; ct->prefix; ct++)
79: if (strcmp(ct->prefix, dialer) == 0)
80: break;
81: if (ct->prefix == NULL) {
82: ipcseterror(EX_USAGE, "Unknown network type", "Can't dial");
83: return -1;
84: }
85:
86: if (ipcdebug)
87: fprintf(stderr, "Connecting to network %s %s\n",
88: dialer, dialno);
89: if (ct->prhost == NULL) { /*not proxy connect*/
90: fd = (ct->connector)(dialno, param);
91: if ((fd >= 0) && (fd <= MAXFD))
92: closelist[fd] = ct->closer;
93: } else
94: fd = proxy_connect(dialno, param, ct->prhost);
95:
96: if (ipcdebug)
97: fprintf(stderr, "Ipcopen returning %d, err=%d\n",
98: fd, ipcerrno);
99: return fd;
100: }
101:
102: int
103: ipcclose(fd)
104: int fd;
105: {
106: if (ipcdebug)
107: fprintf(stderr, "Closing fd %d\n", fd);
108: if ((fd >= 0) && (fd <= MAXFD) && (closelist[fd] != 0)) {
109: int rc = (closelist[fd])(fd);
110: closelist[fd] = 0;
111: return rc;
112: } else
113: return close(fd);
114: }
115:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.