2 * This part for NCR UNIX with is from Andrew Maffei (arm@aqua.whoi.edu). It
3 * assumes TLI throughout. In order to look up endpoint address information
4 * we must talk to the "timod" streams module. For some reason "timod" wants
5 * to sit directly on top of the device driver. Therefore we pop off all
6 * streams modules except the driver, install the "timod" module so that we
7 * can figure out network addresses, and then restore the original state.
11 static char sccsid[] = "@(#) ncr.c 1.1 94/12/28 17:42:34";
14 #include <sys/types.h>
17 #include <sys/tiuser.h>
23 #define MAX_MODULE_COUNT 10 /* XXX */
25 /* fromhost - tear down the streams stack then rebuild it */
27 void fromhost(struct request_info *request)
31 struct str_list str_list;
32 struct str_mlist mod_buffer[MAX_MODULE_COUNT];
35 str_list.sl_nmods = MAX_MODULE_COUNT;
36 str_list.sl_modlist = &mod_buffer[0];
39 * On systems with WIN streams support we have to be careful about what
40 * is on the stream we are passed. This code POPs off all modules above
41 * the pseudo driver, pushes timod, gets the host address information,
42 * pops timod and then pushes all modules back on the stream.
44 * Some state may be lost in this process. /usr/etc/tlid seems to do special
45 * things to the stream depending on the TCP port being serviced. (not a
46 * very nice thing to do!). It is unclear what to do if this code breaks
47 * - the stream may be left in an unknown condition.
49 if ((num_mod = ioctl(fd, I_LIST, NULL)) < 0)
50 tcpd_warn("fromhost: LIST failed: %m");
51 if (ioctl(fd, I_LIST, &str_list) < 0)
52 tcpd_warn("fromhost: LIST failed: %m");
55 * POP stream modules except for the driver.
57 for (i = 0; i < num_mod - 1; i++)
58 if (ioctl(fd, I_POP, 0) < 0)
59 tcpd_warn("fromhost: POP %s: %m", mod_buffer[i].l_name);
62 * PUSH timod so that host address ioctls can be executed.
64 if (ioctl(fd, I_PUSH, "timod") < 0)
65 tcpd_warn("fromhost: PUSH timod: %m");
69 * POP timod, we're done with it now.
71 if (ioctl(fd, I_POP, 0) < 0)
72 tcpd_warn("fromhost: POP timod: %m");
75 * Restore stream modules.
77 for (i = num_mod - 2; i >= 0; i--)
78 if (ioctl(fd, I_PUSH, mod_buffer[i].l_name) < 0)
79 tcpd_warn("fromhost: PUSH %s: %m", mod_buffer[i].l_name);