home *** CD-ROM | disk | FTP | other *** search
/ Hackers Toolkit v2.0 / Hackers_Toolkit_v2.0.iso / HTML / archive / Unix / c-src / atap.c < prev    next >
Text File  |  1999-11-04  |  38KB  |  1,385 lines

  1. #!/bin/sh
  2. # This is a shell archive (shar 3.32)
  3. # made 01/30/1995 19:52 UTC by root@bbisun
  4. # Source directory /usr/local/src/bbidev/tap/src
  5. #
  6. # existing files WILL be overwritten
  7. #
  8. # This shar contains:
  9. # length  mode       name
  10. # ------ ---------- ------------------------------------------
  11. #  15398 -r--r--r-- README
  12. #   2483 -r--r--r-- INSTALL
  13. #   1671 -r--r--r-- Makefile
  14. #   1528 -r-xr-xr-x load
  15. #    270 -r-xr-xr-x unload
  16. #   8096 -r--r--r-- tap.c
  17. #    267 -r--r--r-- tap.h
  18. #   2658 -r--r--r-- tapmon.c
  19. #   1386 -r--r--r-- streams.c
  20. #
  21. if touch 2>&1 | fgrep 'amc' > /dev/null
  22.  then TOUCH=touch
  23.  else TOUCH=true
  24. fi
  25. # ============= README ==============
  26. echo "x - extracting README (Text)"
  27. sed 's/^X//' << 'SHAR_EOF' > README &&
  28. X#       @(#)README    1.28 1/30/95
  29. X#
  30. X############################################################################
  31. X#   This is the STREAMS tap module/driver pseudo-device. aka WATER-WORKS
  32. X############################################################################
  33. X#
  34. X# runs on:
  35. X#        sun3/50 4.1.1
  36. X#        sun4/75 4.1.2
  37. X#        sun4/670 4.1.2 (multi-processor)
  38. X#
  39. X
  40. XCOPYRIGHT:
  41. X        - you want COPYRIGHT ? i will give you COPYRIGHT.
  42. X          Copyright (c) 1992 Simon Ney -- All Rights Reserved
  43. X
  44. X
  45. X                                ---------------
  46. X
  47. X
  48. XDESCRIPTION:
  49. X        - the device is a monitor/manipulator for other STREAMS-devices
  50. X          such as standard UNIX control-terminals.
  51. X
  52. X        - this driver is a kernel-loadable-module. (==>no reboot required)
  53. X
  54. X        - it is a combination of a STREAMS-module and a STREAMS-driver.
  55. X
  56. X                tap     - is the name of the pushable/poppable STREAMS-modules.
  57. X                tapc*   - are the names of the STREAMS-driver nodes (special
  58. X                          files)..
  59. X
  60. X        - the tap-modules must first manually pushed/popped on each stream
  61. X          to be monitored or manipulated, independ if the tapc-driver is
  62. X          open or not. see also ioctl(fd,I_PUSH|I_POP,"tap").
  63. X
  64. X        - the first module pushed become the id 0, the second 1, and so on...
  65. X          if any of these modules are popped the next pushed will become
  66. X          the old id of the previous popped module. the module ids are
  67. X          always unique, and are assigned first fit.
  68. X          the maximal number of tap-modules pushed is NTAP (see tap.h).
  69. X
  70. X        - a pushed-tap-module act as NULL-streams-MODULE (pass data from below
  71. X          to above and data from above to below) unless it is connected with
  72. X          the tapc-driver.
  73. X
  74. X        - now if a minor device of the tapc-driver is opened the minor
  75. X          device-number is used to check if such tap-module is pushed
  76. X          (minor number = tap-id). if no such module id is present a
  77. X          ENETUNREACH (Network is unreachable) error is returned by open().
  78. X          if the module id (minor device number) can be found, a connection
  79. X          to the pushed-tap-module is established.
  80. X
  81. X        - all minor-device-nodes can only open by one user at a time,
  82. X          the second open() on the same minor device returns a EBUSY (Device
  83. X          busy) error.
  84. X
  85. X        - if the open() has the O_NDELAY flag set a TAP_REVERSE flag
  86. X          is internal set in the driver. the TAP_REVERSE flag can only
  87. X          set by the super-user, a non-superuser open() returns a EACCES
  88. X          (Permission denied) error.
  89. X
  90. X        - now data can be received/send from/to the pushed-tap-module
  91. X          with read() and write().
  92. X
  93. X        - if the TAP_REVERSE flag is not set, data received by the tap-module
  94. X          from the above modules/streamshead (upper-stream) is duplicated
  95. X          and send to the read-side of the tapc-driver, and can be read by
  96. X          the user process that opened the tapc-driver.
  97. X          data written with write() by the process that opened the tapc-driver
  98. X          are send to modules/streamshead above the tap-module (upper-stream).
  99. X
  100. X        - if the TAP_REVERSE flag is set, data received by the tap-module
  101. X          from the module/driver below the tap-module (lower-stream) is
  102. X          duplicated and send to the read-side of the tapc-driver, and can
  103. X          be read by the user process that opened the tapc-driver.
  104. X          data written with write() by the process that opened the tapc-driver
  105. X          are send to the modules/driver below the tap-module (lower-stream).
  106. X
  107. X        - if the tapc-driver is closed the messages are not dupclicated as
  108. X          long as the tapc-driver is re-open. (the tap-modules remains
  109. X          pushed)
  110. X
  111. X        - if data is written by the tapc-driver and the connected module
  112. X          was popped a ENETCONNRESET (Connection reset by peer) error is
  113. X          return to the write().
  114. X
  115. X        - if the stream that has the tap-module pushed is closed, all modules
  116. X          on this stream are popped by the system. but there is a configuration
  117. X          option in sunos to autopush any modules on open() (that's different
  118. X          in a SYSV environment).
  119. X
  120. X
  121. X                                ---------------
  122. X
  123. X
  124. XFIGURES:
  125. X       (USER PROCESS)           (BIG BROTHER)
  126. X         (csh,vi)           (tapmon)    (tapmon -r)  (tip/cu/uucico)
  127. X         /dev/ttya         /dev/tapc0   /dev/tapc1      /dev/cua1
  128. X--------------------------------------------------------------------------------
  129. X        |ttya HEAD |       |tapc HEAD|  |tapc HEAD|   |cua1 HEAD |
  130. X        +----------+       +---------+  +---------+   +----------+
  131. X             | ^              | ^          | ^             | ^
  132. X             | |              | |          | |             | |
  133. X             | |           ...........  ...........        | |
  134. X             | |           . MORE    .  . MORE    .        | |
  135. X             | |           . MODULES .  . MODULES .        | |
  136. X             | |           ...........  ...........        | |
  137. X             | |              | |          | |             | |
  138. X             v |              v |          v |             | |
  139. X        ............       +---------+  +---------+   ............
  140. X        . MORE  (2).       |TAPC 0   |  |TAPC 1   |   . MORE (2) .
  141. X        . MODULES  .       |DRIVER   |  |DRIVER(1)|   . MODULES  .
  142. X        ............       +---------+  +---------+   ............
  143. X          (3)| ^(4)           | ^          | ^             | |         UPPER
  144. X             v |              | |          | |             v |         STREAMS
  145. X        +----------+          | |          | |        +----------+
  146. X        |    \ \   |          | |          | |        | TAP 1    |
  147. X        |     \ \--|<---------/ |          | \--------|\  MODULE |
  148. X        | TAP 0\---|------------/          \--------->| \  PUSHED|
  149. X        | MODULE   |                                  |\ \REVERSE|
  150. X        | PUSHED   |                                  | \ \ OPEN |
  151. X        |          |  <--- NORMAL       REVERSE--->   |  \ \     |
  152. X        +----------+                                  +----------+
  153. X             | ^                                       (4)| ^(3)        LOWER
  154. X             v |                                          v |           STREAMS
  155. X        ............                                  ............
  156. X        . MORE  (2).                                  . MORE     .
  157. X        . MODULES  .                                  . MODULES  .
  158. X        ............                                  ............
  159. X             | ^                                          | ^
  160. X             v |                                          v |
  161. X        +----------+                                  +----------+
  162. X        | zs DRIVER|                                  | zs DRIVER|
  163. X--------------------------------------------------------------------------------
  164. X    physical STREAMS device                      physical STREAMS device
  165. X         (terminal)                                    (modem)
  166. X         (intruder)                                (other systems)
  167. X
  168. X                                        ----------
  169. X                                        (1) - opened by O_NDELAY from root
  170. X                                        (2) - e.g. ttcompat,ldterm,kb,ms,
  171. X                                                   slip,ax25,pf,nbuf
  172. X                                        (3) - duplicated streams
  173. X                                        (4) - multiplexed streams
  174. X
  175. X
  176. XNOTE: the ,,physical STREAMS device'' above shown can be any streams device
  177. X      e.g.:      /dev/{tty*,console,nit,tcp,loop,mux,mti,kbd,mouse,*CLONE*}
  178. X                (nit and tcp is a clone device !)
  179. X      slip cant monitored because itself pops all modules pushed.
  180. X      the only way is to modify sliplogin.c to push the tap module below
  181. X      the slip module.
  182. X
  183. X
  184. X                                ---------------
  185. X
  186. X
  187. X
  188. XINSTALLATION:
  189. X        the current version has been tested under sunos 4.1.1 on a sun3/50
  190. X        and sunos 4.1.2 on a sun4/75. but i hope the version will run on any 
  191. X    sun with the loadable-driver /dev/vd,otherwise read the INSTALL file 
  192. X    and your STREAMS programming manual (the load of the pushable
  193. X    streams-module is done by hand on suns). if the modload(8) 
  194. X    fails or the use of the driver crashes the kernel let me know ...
  195. X
  196. X        to make the kernel-loadable module and automatic load into the kernel
  197. X        type (as root);
  198. X
  199. X                # make
  200. X
  201. X        the tapmon(1)+streams(1) user-commands are created.(the streams(1)
  202. X        command can be used to push/pop other non-tap streams modules,the
  203. X        tapmon(1) is a TAP-driver application).
  204. X        a possible old tap-module is automatically unloaded if a new is loaded
  205. X        (after multiple make commands).  the device nodes (/dev/tapc*) are
  206. X        created as expected.
  207. X
  208. X
  209. X
  210. X                                ---------------
  211. X
  212. X
  213. X
  214. XSOME EXAMPLES:
  215. X        now login from ttya before continue (or pick a already opened
  216. X        pseudo-tty from the window-system (NOT the one you will enter
  217. X        the following commands))
  218. X
  219. X                # streams -u tap < /dev/ttya
  220. X                # tapmon 0
  221. X
  222. X        this push a tap-module on the already open /dev/ttya serial-tty and
  223. X        then start the monitor/manipulator. all data send to /dev/ttya are
  224. X        now duplicated to your standard output,and all data send by you are
  225. X        send as input to the process on ttya, thats the same as you are sit
  226. X        in front of ttya.
  227. X        type CTRL-_ to leave the tapmon.
  228. X        NOTE: after leaving tapmon the tap-streams-modules remains pushed.
  229. X
  230. X        here an example output from ,,pstat -S'' while one tapmon is running:
  231. X
  232. X                   LOC     WRQ       VNODE     DEVICE   PGRP SIGIO  FLAGS
  233. X                 f05461e    f05583c   f0cdb94  59,  0      0     0  R
  234. X                  Write side:
  235. X                    NAME      COUNT FLG    MINPS  MAXPS  HIWAT  LOWAT
  236. X                    strwhead      0            0      0      0      0
  237. X                    tapc          0  R         0    INF      0      0
  238. X                  Read side:
  239. X                    tapc          0  R         0    INF      0      0
  240. X                    strrhead      0  R         0    INF   5120   1024
  241. X
  242. X
  243. X                   LOC     WRQ       VNODE     DEVICE   PGRP SIGIO  FLAGS
  244. X                 f0543e0    f0550ec   f0cc9f4  12,  1    905     0
  245. X                  Write side:
  246. X                    NAME      COUNT FLG    MINPS  MAXPS  HIWAT  LOWAT
  247. X                    strwhead      0            0      0      0      0
  248. X                    tap           0  R         0    INF      0      0
  249. X                    ttcompat      0  R         0    INF    300    200
  250. X                    ldterm        0  R         0    INF      1      0
  251. X                    zs            0  R         0    INF   2048    128
  252. X                  Read side:
  253. X                    zs            0  R         0    INF   2048    128
  254. X                    ldterm        0  R         0    128    500    200
  255. X                    ttcompat      0  R         0    INF   2048    128
  256. X                    tap           0  R         0    INF      0      0
  257. X                    strrhead      0            0    INF    300    200
  258. X
  259. X
  260. X        the kernel-loadable-module can only unloaded by ./unload or by
  261. X        modunload(1) if all tap-modules are popped and the /dev/tapc* devices
  262. X        are closed (if you are not sure look in ,,pstat -S'' for the
  263. X        string "tap" ).
  264. X
  265. X                # streams -o tap < /dev/ttya
  266. X                # ./unload
  267. X
  268. X        this pops the previous pushed module and unloads the
  269. X        kernel-loadable-module from the kernel...
  270. X
  271. X        NOTE: always use ./unload instead of modunload(8) because the Makefile
  272. X              keep track of the loaded kernel-modules !
  273. X
  274. X        another example is (if you not already done the ./unload operation
  275. X        above,otherwise you must reload the tapc/tap driver with another
  276. X        ,,make''):
  277. X
  278. X                # streams -o ttcompat -o ldterm \
  279. X                        -u tap -u ldterm -u ttcompat < /dev/ttya
  280. X                # tapmon 0
  281. X
  282. X        now you can monitor direct above the physical device and below
  283. X        the ldterm module and can see the line-editing functions of
  284. X        the ldterm and ttcompat modules.
  285. X        also signals send by you, such as CTRL-C are processes by the
  286. X        ldterm and ttcompat modules and send as signal to the process
  287. X        as expected (in the former example not, a CTRL-C was send as
  288. X        input byte 0x03 to the user-process)
  289. X
  290. X        here how to undo the last modules transaction:
  291. X
  292. X                # streams -o ttcompat -o ldterm -o tap -u ldterm \
  293. X                        -u ttcompat < /dev/ttya
  294. X
  295. X        NOTE: the order of ther streams(1) command is important (stack order).
  296. X
  297. X
  298. X
  299. X                                ---------------
  300. X
  301. X
  302. XKERNEL CONFIG:
  303. X        if you want to link the tapc/tap device-driver permanently to /vmunix
  304. X        be sure not to define TAPVD (see Makefile) and to ignore tap.h
  305. X        (see tap.h). follow the steps in the ,,INSTALL'' file.
  306. X
  307. X
  308. X                                ---------------
  309. X
  310. X
  311. XKNOWN BUGS:
  312. X        - CLONE open are currently disabled because it may crash the kernel,
  313. X          after 7 modules are pushed and 7 tapmons (using clone open) started
  314. X          in backgroup then close the stream that has the 7 modules pushed,
  315. X          and then reconnected to the tapmons with csh ,fg'' command, the 7th
  316. X          ,,fg'' crash the sun3sunos4.1.1 kernel with the following message:
  317. X                                        ****
  318. X         ,,assertion failed: vp->v_stream, file: ../../os/str_io.c, line 3823''
  319. X         ,,panic: assertion failed''
  320. X                                        ****
  321. X          the kernel-backtrace shows than it was called from some kernel
  322. X          select(), thats the first function tapmon calls after the CLONE open.
  323. X
  324. X         - if the BUG is fixed CLONE opens connects to the first unconnected
  325. X           module, and not the last pushed module!
  326. X
  327. X
  328. X                                ---------------
  329. X
  330. X
  331. XSECURITY NOTES:
  332. X        - the paranoid sysadmin must decide what permission he want to give to
  333. X          the /dev/tapc* devices (e.g. chmod 600 /dev/tapc*).
  334. X          the TAP_REVERSE mode can only be used by the super-user because
  335. X          it can be used to read clear text passwords during login-time and
  336. X          to get control of external devices such as modems and communication
  337. X          devices.
  338. X
  339. X        - a typical LUSER can start ,,pstat -S'' to see if BIG BROTHER is
  340. X          watching...
  341. X
  342. X
  343. X                                ---------------
  344. X
  345. X
  346. XCOMMENTS:
  347. X        - you can use TAP for education proposes if you push multiple
  348. X          tap-modules on a single stream or you can create BIG BROTHER trees,
  349. X          and make a UNIX alliance so that multiple users use the same
  350. X          shell,editor.... and can correct each other....or to help UNIX
  351. X          beginners....isnt it a some kind of human-neural-nets ?
  352. X
  353. X        - the only problem is the possible wrong terminal-emulation *sigh*.
  354. X          but there is a universal-terminal-emulation under X, and the screen
  355. X          command from Oliver Laumann.
  356. X
  357. X        - a MAN page is included in the next release.
  358. X
  359. X        - i hope my english is funny...
  360. X
  361. X        UNIX - is a registed bell of AT&T trademark laboratories.
  362. X
  363. X--
  364. XSimon Ney -- simon@bbisdn.isdn.cs.tu-berlin.de -- neural@cs.tu-berlin.de
  365. SHAR_EOF
  366. $TOUCH -am 0130205295 README &&
  367. chmod 0444 README ||
  368. echo "restore of README failed"
  369. set `wc -c README`;Wc_c=$1
  370. if test "$Wc_c" != "15398"; then
  371.     echo original size 15398, current size $Wc_c
  372. fi
  373. # ============= INSTALL ==============
  374. echo "x - extracting INSTALL (Text)"
  375. sed 's/^X//' << 'SHAR_EOF' > INSTALL &&
  376. X#
  377. X# @(#)INSTALL    1.25 5/8/93
  378. X#
  379. X
  380. XSTEPS TO CONFIGURE YOUR KERNEL FOR TAPC/TAP:
  381. X
  382. X                i recommend that you first try the kernel-loadable
  383. X                version of the driver by just type ,,make'' (see README)
  384. X                and make later the steps below...
  385. X
  386. X-------------------------------------------------------------------------
  387. X1.    Add:
  388. X
  389. X    sundev/tap.c        optional tap device-driver
  390. X
  391. X    to /usr/sys/`arch -k`/conf/files
  392. X
  393. X-------------------------------------------------------------------------
  394. X2.    Copy tap.c to /usr/sys/sundev/tap.c
  395. X
  396. X-------------------------------------------------------------------------
  397. X3.    Add
  398. X
  399. X        ...
  400. X      #include "tap.h"
  401. X      #if NTAP > 0
  402. X      extern struct streamtab tapcinfo;
  403. X      #define   tapctab &tapcinfo
  404. X      #else
  405. X      #define   tapctab 0
  406. X      #endif
  407. X        ...             (at the end of the cdevsw[])
  408. X      {
  409. X        nodev,          nodev,          nodev,          nodev,          /*104*/
  410. X        nodev,          nulldev,        nodev,          0,
  411. X        tapctab,        0,
  412. X      },
  413. X        ...
  414. X
  415. X      to /usr/sys/sun/conf.c
  416. X      (write down the major number (e.g. 104))
  417. X
  418. X-------------------------------------------------------------------------
  419. X4.    Add
  420. X
  421. X    ...
  422. X    #include "tap.h"
  423. X    ...
  424. X    #if    NTAP > 0
  425. X    extern struct streamtab tapinfo;
  426. X    #endif
  427. X    ...
  428. X    #if    NTAP > 0
  429. X        { "tap",    &tapinfo },
  430. X    #endif
  431. X    ...
  432. X
  433. X    to /usr/sys/sun/str_conf.c
  434. X
  435. X-------------------------------------------------------------------------
  436. X5.    Add
  437. X
  438. X    pseudo-device tap8  # STREAMS tapc/tap driver/module
  439. X
  440. X    to your /usr/sys/`arch -k`/conf/CONFIG file.
  441. X    (8 = maximal 8 modules and devices for the system,max 256)
  442. X-------------------------------------------------------------------------
  443. X6.    Configure your kernel and install and boot it
  444. X
  445. X      # cd /usr/sys/`arch -k`/conf
  446. X      # config CONFIG
  447. X      # cd ../CONFIG
  448. X      # make
  449. X      # cp /vmunix /vmunix.old
  450. X      # cp vmunix /
  451. X      # ls -l /dev/tapc*
  452. X      # rm -f /dev/tapc*
  453. X      # mknod /dev/tapc0 c 104 0  # major 104 is the number from step 3. above
  454. X      # mknod /dev/tapc1 c 104 1
  455. X        .
  456. X        .
  457. X        .
  458. X      # mknod /dev/tapc7 c 104 7
  459. X      # fastboot
  460. X
  461. X-------------------------------------------------------------------------
  462. X7.    In your TAP-SOURCE directory
  463. X
  464. X      # make install            # to install streams+tapmon in /usr/local/etc
  465. X-------------------------------------------------------------------------
  466. X
  467. SHAR_EOF
  468. $TOUCH -am 0508132093 INSTALL &&
  469. chmod 0444 INSTALL ||
  470. echo "restore of INSTALL failed"
  471. set `wc -c INSTALL`;Wc_c=$1
  472. if test "$Wc_c" != "2483"; then
  473.     echo original size 2483, current size $Wc_c
  474. fi
  475. # ============= Makefile ==============
  476. echo "x - extracting Makefile (Text)"
  477. sed 's/^X//' << 'SHAR_EOF' > Makefile &&
  478. X# @(#)Makefile    1.25 5/8/93
  479. X###############################################################################
  480. X#
  481. X#          --- kernel loadable-module tap streams-module/driver pseudo-device ---
  482. X#
  483. X#     SEE ALSO
  484. X#        modload(8)
  485. X#        modunload(8)
  486. X#        modstat(8)
  487. X#        vd(4)
  488. X#
  489. X# TAPDEBUG  -to show the tap structure every time a modstat(8) is started 
  490. X#
  491. X# TAPVD     -indicates kernel-loadable version
  492. X#
  493. X# TAPVDDUAL -must be defined only if a driver is already linked to /vmunix
  494. X#            and a additional loadable-driver should be loaded w/o confusing
  495. X#         duplicate module-names ( "tapc"/"tap" strings are changed
  496. X#         to "tapcvd"/"tapvd" )
  497. X#
  498. X###############################################################################
  499. X#
  500. X# TAPCLONE  -WARNING define ONLY after you have read the BUGS section 
  501. X#            in the README file
  502. X#
  503. X###############################################################################
  504. X
  505. XCFLAGS=    -O -DKERNEL -D`arch -k` -DTAPVD # -DTAPDEBUG ### -DTAPCLONE
  506. XINSDIR=    /usr/local/etc
  507. XFILES=    README INSTALL Makefile load unload tap.c tap.h tapmon.c streams.c
  508. XMIDF=    /tmp/MODULE_ID             # removed by reboot(8) and ./unload
  509. X
  510. Xall:    EXECS $(FILES) streams tapmon module
  511. X
  512. Xmodule:    tap.o  
  513. X    if( test -f $(MIDF) ) then \
  514. X        ./unload ; \
  515. X    fi
  516. X    modload -exec ./load tap.o
  517. X    modstat
  518. X
  519. Xtap.c:    tap.h
  520. X
  521. XEXECS:    load unload
  522. X    chmod a+x load unload
  523. X    touch $@                 # WELCOME TO WATER-WORKS ...
  524. X
  525. Xedit:
  526. X    sccs edit $(FILES)
  527. X    chmod a+x load unload
  528. X
  529. Xdelta:
  530. X    sccs delta $(FILES)
  531. X
  532. Xinstall:streams tapmon
  533. X    install -s -m 755 -o bin -g bin streams $(INSDIR)
  534. X    install -s -m 755 -o bin -g bin tapmon $(INSDIR)
  535. X
  536. Xclean:
  537. X    rm -f     EXECS tap.o tap tapmon streams
  538. X
  539. Xshar:    $(FILES)
  540. X    shar -c $(FILES) > tap1.25.shar
  541. X
  542. SHAR_EOF
  543. $TOUCH -am 0508132093 Makefile &&
  544. chmod 0444 Makefile ||
  545. echo "restore of Makefile failed"
  546. set `wc -c Makefile`;Wc_c=$1
  547. if test "$Wc_c" != "1671"; then
  548.     echo original size 1671, current size $Wc_c
  549. fi
  550. # ============= load ==============
  551. echo "x - extracting load (Text)"
  552. sed 's/^X//' << 'SHAR_EOF' > load &&
  553. X#! /bin/sh
  554. X# @(#)load    1.25 5/8/93
  555. X
  556. XPATH=/usr/ucb:/bin:/usr/bin:/usr/etc ; export PATH
  557. X
  558. X# --- change here ---
  559. XCDEVICE="/dev/tapc"
  560. XCMINORLIST="0 1 2 3 4 5 6 7"
  561. XPERM=600
  562. X#CLONEMAJOR=37    # is this standard ?
  563. X#CLONENAME=x    # dont change
  564. X
  565. X# ---- do not change below this line ----
  566. XMIDF="/tmp/MODULE_ID"
  567. XID=$1
  568. XTYPE=$2
  569. X
  570. Xif( test $# -lt 2 ) then
  571. X    echo "Indirect Usage is: modload -exec $0 module.o"
  572. X    exit 1
  573. Xfi
  574. X#-----------------------------------------------------
  575. Xcase $TYPE in
  576. X
  577. X    12345600)    
  578. X            # DRIVER
  579. X            BMAJOR=$3
  580. X            CMAJOR=$4
  581. X            for MINOR in $CMINORLIST
  582. X            do
  583. X                DEV=$CDEVICE$MINOR
  584. X                echo "$0: replace \"$DEV\"."
  585. X                rm -f $DEV
  586. X                mknod $DEV c $CMAJOR $MINOR
  587. X                chmod $PERM $DEV # for now
  588. X            done
  589. X            # CLONE stuff
  590. X            # DEV=$CDEVICE$CLONENAME
  591. X            # echo "$0: replace \"$DEV\" (CLONED CLONEMAJOR=$CLONEMAJOR)"
  592. X            # rm -f $DEV
  593. X            # mknod $DEV c $CLONEMAJOR $CMAJOR
  594. X            # chmod $PERM $DEV # for now
  595. X            ;;
  596. X
  597. X    12345607)    
  598. X            # PSEUDO
  599. X            BMAJOR=$3
  600. X            CMAJOR=$4
  601. X            for MINOR in $CMINORLIST
  602. X            do
  603. X                DEV=$CDEVICE$MINOR
  604. X                echo "$0: replace \"$DEV\"."
  605. X                rm -f $DEV
  606. X                mknod $DEV c $CMAJOR $MINOR
  607. X                chmod $PERM $DEV # for now
  608. X            done
  609. X            # CLONE stuff
  610. X            # DEV=$CDEVICE$CLONENAME
  611. X            # echo "$0: replace \"$DEV\" (CLONED CLONEMAJOR=$CLONEMAJOR)"
  612. X            # rm -f $DEV
  613. X            # mknod $DEV c $CLONEMAJOR $CMAJOR
  614. X            # chmod $PERM $DEV # for now
  615. X            ;;
  616. X
  617. X    12345606)    
  618. X            # USER
  619. X            ;;
  620. X
  621. X    *)        # ILLEGAL
  622. X            echo "$0: illegal module type \"$TYPE\" from modload"
  623. X            exit 1
  624. X            ;;
  625. Xesac
  626. X#-----------------------------------------------------
  627. Xecho $ID > $MIDF
  628. Xexit 0
  629. SHAR_EOF
  630. $TOUCH -am 0508132093 load &&
  631. chmod 0555 load ||
  632. echo "restore of load failed"
  633. set `wc -c load`;Wc_c=$1
  634. if test "$Wc_c" != "1528"; then
  635.     echo original size 1528, current size $Wc_c
  636. fi
  637. # ============= unload ==============
  638. echo "x - extracting unload (Text)"
  639. sed 's/^X//' << 'SHAR_EOF' > unload &&
  640. X#! /bin/sh
  641. X# @(#)unload    1.25 5/8/93
  642. X
  643. XPATH=/usr/ucb:/bin:/usr/bin:/usr/etc ; export PATH
  644. X
  645. XMIDF="/tmp/MODULE_ID"
  646. X
  647. Xif ( test -f $MIDF ) then
  648. X    
  649. X    if(modunload -id `cat $MIDF`) then
  650. X        rm $MIDF
  651. X    else
  652. X        modstat
  653. X        exit 1
  654. X    fi
  655. Xelse
  656. X    echo "no $MIDF file present"
  657. X    exit 1
  658. Xfi    
  659. Xexit 0
  660. SHAR_EOF
  661. $TOUCH -am 0508132093 unload &&
  662. chmod 0555 unload ||
  663. echo "restore of unload failed"
  664. set `wc -c unload`;Wc_c=$1
  665. if test "$Wc_c" != "270"; then
  666.     echo original size 270, current size $Wc_c
  667. fi
  668. # ============= tap.c ==============
  669. echo "x - extracting tap.c (Text)"
  670. sed 's/^X//' << 'SHAR_EOF' > tap.c &&
  671. X/*
  672. X * tap streams-module/driver kernel-loadable-module, aka WATER-WORKS 
  673. X * this is a combination of a STREAMS-module and a STREAMS-driver.
  674. X *
  675. X * Simon Ney -- neural@cs.tu-berlin.de -- simon@bbisun.uu.sub.org
  676. X */
  677. X
  678. X#include "tap.h"
  679. X#if    NTAP > 0
  680. X#include <sys/types.h>
  681. X#include <sys/stream.h>
  682. X#include <sys/stropts.h>
  683. X#include <sys/param.h>
  684. X#include <sys/errno.h>
  685. X#include <sys/user.h>
  686. X#include <sys/file.h>
  687. X#include <sys/termio.h> /*XX*/
  688. X#ifdef TAPVD
  689. X#include <sys/conf.h>
  690. X#include <sun/vddrv.h>
  691. X#endif TAPVD
  692. X
  693. X#ifndef lint
  694. Xstatic    char sccsid[] = "@(#)tap.c    1.26 5/8/93";
  695. X#endif
  696. X
  697. X/* 
  698. X * --- DRIVER PART --- 
  699. X */
  700. X
  701. X#ifdef TAPVDDUAL
  702. Xstatic struct module_info cminfo = { 0, "tapcvd", 0, INFPSZ, 0, 0 };
  703. X#else
  704. Xstatic struct module_info cminfo = { 0, "tapc", 0, INFPSZ, 0, 0 };
  705. X#endif
  706. X
  707. Xstatic int tapcopen(), tapcrput(), tapcwput(), tapcclose();
  708. X
  709. Xstatic struct qinit crinit = {
  710. X    tapcrput, NULL, tapcopen, tapcclose, NULL, &cminfo, NULL
  711. X};
  712. X
  713. Xstatic struct qinit cwinit = {
  714. X    tapcwput, NULL, NULL, NULL, NULL, &cminfo, NULL
  715. X};
  716. X
  717. X#ifdef TAPVD /* so we can have a permanent linked AND loadable version */
  718. Xstruct streamtab tapcvdinfo = { &crinit, &cwinit, NULL, NULL };
  719. X#else
  720. Xstruct streamtab tapcinfo = { &crinit, &cwinit, NULL, NULL };
  721. X#endif
  722. X
  723. X/*
  724. X * --- MODULE PART --- 
  725. X */
  726. X
  727. X#ifdef TAPVDDUAL
  728. Xstatic struct module_info minfo = { 0, "tapvd", 0, INFPSZ, 0, 0 };
  729. X#else
  730. Xstatic struct module_info minfo = { 0, "tap", 0, INFPSZ, 0, 0 };
  731. X#endif
  732. X
  733. Xstatic int tapopen(), taprput(), tapwput(), tapclose();
  734. X
  735. Xstatic struct qinit rinit = {
  736. X    taprput, NULL, tapopen, tapclose, NULL, &minfo, NULL
  737. X};
  738. X
  739. Xstatic struct qinit winit = {
  740. X    tapwput, NULL, NULL, NULL, NULL, &minfo, NULL
  741. X};
  742. X
  743. X#ifdef TAPVD /* so we can have a permanent linked AND loadable version */
  744. Xstruct streamtab tapvdinfo = { &rinit, &winit, NULL, NULL };
  745. X#else
  746. Xstruct streamtab tapinfo = { &rinit, &winit, NULL, NULL };
  747. X#endif
  748. X
  749. X/*
  750. X * the ,,TAP device'' structure 
  751. X */
  752. X
  753. Xstruct tap {
  754. X    queue_t *tapdm_queue;    /* queue from driver to module (set by module)*/
  755. X    queue_t *tapmd_queue;    /* queue from module to driver (set by driver)*/
  756. X#define TAP_REVERSE    1    /* if set connect to lower side else upper */
  757. X    unsigned int tap_flags;    /* currently only the TAP_REVERSE flag */
  758. X};
  759. Xstatic struct tap  tap_tap[NTAP];    /* static for now */
  760. Xstatic int tap_cnt = NTAP;
  761. X
  762. X/* 
  763. X * --- KERNEL-LOADABLE-MODULE SUPPORT --- 
  764. X */
  765. X
  766. X#ifdef TAPVD
  767. Xextern int nodev();
  768. X
  769. Xstatic struct cdevsw        tap_cdevsw = { 
  770. X    nodev, nodev, nodev, nodev, nodev, nodev, nodev, 0, 
  771. X    &tapcvdinfo, 0
  772. X};
  773. X
  774. Xstatic struct vdldrv tapvdldrv = {
  775. X    VDMAGIC_PSEUDO, "tapc/tap-1.26", 
  776. X#ifdef sun4m
  777. X    NULL,
  778. X    NULL, &tap_cdevsw, 0, 0,
  779. X    NULL,
  780. X    NULL, NULL, 0, 1
  781. X#else
  782. X    NULL,
  783. X#ifndef sun4c
  784. X    NULL, NULL, 0, 1,
  785. X#endif
  786. X    NULL, &tap_cdevsw, 0, 0    
  787. X#endif
  788. X};
  789. X
  790. X/*
  791. X * this is the pushable-STREAMS-module kernel-module-loader
  792. X */
  793. Xstatic    struct fmodsw *saved_fmp;
  794. X
  795. Xstatic struct fmodsw *loadfmodsw(name,str)
  796. Xchar *name;
  797. Xstruct streamtab *str;
  798. X{
  799. X    register struct fmodsw *fmp;
  800. X    register int i;
  801. X    extern struct fmodsw fmodsw[];
  802. X    extern int fmodcnt;
  803. X
  804. X    fmp = fmodsw;
  805. X    for(i=0;i<fmodcnt;i++,fmp++){
  806. X        if(fmp->f_str==0){
  807. X            strcpy(fmp->f_name,name);
  808. X            fmp->f_str = str;
  809. X            return(fmp);
  810. X        }
  811. X    }
  812. X    printf("tap: loadfmodsw: no free slot for '%s'\n",name);
  813. X    return(0);
  814. X}
  815. X
  816. Xstatic unloadfmodsw(fmp)
  817. X    struct fmodsw *fmp;
  818. X{
  819. X    fmp->f_name[0] = '\0';
  820. X    fmp->f_str = 0;
  821. X}
  822. X
  823. X/*
  824. X * this is the driver entry point routine. the name of the default entry
  825. X * point is xxxinit. it can be changed by using the "-entry" command to
  826. X * modload.
  827. X */
  828. X
  829. Xxxxinit(function_code,vdp,vdi,vds)
  830. Xunsigned int function_code;
  831. Xstruct vddrv *vdp;
  832. Xaddr_t vdi;
  833. Xstruct vdstat *vds;
  834. X{
  835. X    register int i;
  836. X    register struct tap *tap;
  837. X
  838. X    switch(function_code){
  839. X    case VDLOAD:
  840. X        if(saved_fmp){        /* ever occured */
  841. X            printf("tap: xxxinit:already loaded\n");
  842. X            return(ENXIO);
  843. X        }
  844. X#ifdef TAPVDDUAL
  845. X        if(!(saved_fmp=loadfmodsw("tapvd",&tapvdinfo))){
  846. X#else
  847. X        if(!(saved_fmp=loadfmodsw("tap",&tapvdinfo))){
  848. X#endif
  849. X            return(ENXIO);
  850. X        }
  851. X        vdp->vdd_vdtab = (struct vdlinkage *) &tapvdldrv;
  852. X        break;
  853. X    case VDUNLOAD:
  854. X        for(i=0,tap=tap_tap;i<tap_cnt;i++,tap++)
  855. X            if(tap->tapdm_queue||tap->tapmd_queue)
  856. X                return(EBUSY);    
  857. X        if(saved_fmp)
  858. X            unloadfmodsw(saved_fmp);
  859. X        break;
  860. X    case VDSTAT:
  861. X#ifdef TAPDEBUG
  862. X        for(i=0,tap=tap_tap;i<tap_cnt;i++,tap++)
  863. X            if(tap->tapdm_queue||tap->tapmd_queue)
  864. X                printf( "tap%d: dm=0x%x md=0x%x flags=0x%x\n",
  865. X                    i,tap->tapdm_queue,tap->tapmd_queue,
  866. X                    tap->tap_flags);
  867. X#endif
  868. X        break;
  869. X    default:
  870. X        return(EIO);
  871. X    }
  872. X    return(0);    /* return success */
  873. X}
  874. X#endif TAPVD
  875. X
  876. X/* --- MODULE PART --- */
  877. X
  878. Xstatic int tapopen(q, dev, flag, sflag)
  879. X    queue_t *q;
  880. X    dev_t   dev;
  881. X    int        flag;
  882. X    int    sflag;
  883. X{
  884. X    register int i;
  885. X    register struct tap *tap;
  886. X
  887. X    if(!(q->q_ptr)){
  888. X        /*
  889. X         * find first fit free slot
  890. X         */
  891. X        for(i=0,tap=tap_tap;i<tap_cnt;i++,tap++){
  892. X            if(!(tap->tapdm_queue)){
  893. X                WR(q)->q_ptr = (char *) tap;
  894. X                q->q_ptr = (char *) tap; /* mark as open */
  895. X                tap->tapdm_queue = q;    
  896. X                return(0);
  897. X            }
  898. X        }
  899. X        return(OPENFAIL);
  900. X    }
  901. X    return(0);    
  902. X}
  903. X
  904. Xstatic int tapwput(q, mp)
  905. X    queue_t    *q;    
  906. X    mblk_t    *mp;   
  907. X{
  908. X    mblk_t    *bp;       
  909. X    struct tap *tap;
  910. X    
  911. X    tap = (struct tap *)q->q_ptr;
  912. X    
  913. X    if((!(tap->tap_flags&TAP_REVERSE))&&tap->tapmd_queue){        
  914. X        if(mp->b_datap->db_type==M_DATA){
  915. X            if((bp=dupmsg(mp))!=NULL){    
  916. X                putnext(tap->tapmd_queue,bp);
  917. X            }
  918. X        }
  919. X    }
  920. X    putnext(q,mp);
  921. X}
  922. X    
  923. Xstatic int taprput(q, mp)
  924. X    queue_t    *q;    
  925. X    mblk_t    *mp;   
  926. X{
  927. X    mblk_t    *bp;       
  928. X    struct tap *tap;
  929. X    
  930. X    tap = (struct tap *)q->q_ptr;
  931. X    
  932. X    if((tap->tap_flags&TAP_REVERSE)&&tap->tapmd_queue){        
  933. X        if(mp->b_datap->db_type==M_DATA){
  934. X            if((bp=dupmsg(mp))!=NULL){    
  935. X                putnext(tap->tapmd_queue,bp);
  936. X            }
  937. X        }
  938. X    }
  939. X    putnext(q, mp);
  940. X}
  941. X
  942. Xstatic int tapclose(q, flag)
  943. X    queue_t    *q;
  944. X    int    flag;
  945. X{
  946. X    struct tap *tap;
  947. X
  948. X    tap = (struct tap *)q->q_ptr;
  949. X    /* here i want to send a HANGUP */
  950. X    tap->tapdm_queue = NULL;
  951. X}
  952. X
  953. X/* --- DRIVER PART --- */
  954. X
  955. Xstatic int tapcopen(q, dev, flag, sflag)
  956. X    queue_t *q;
  957. X    dev_t   dev;
  958. X    int        flag;
  959. X    int    sflag;
  960. X{
  961. X    struct tap *tap;
  962. X
  963. X#ifdef TAPCLONE
  964. X    /*
  965. X     * if CLONEOPEN, pick first unconnected module.
  966. X     * otherwise, check the minor device range.
  967. X     */
  968. X    printf("tapopen: q=0x%x dev=%d flag=%d  sflag=%d\n",q,dev,flag,sflag);
  969. X    if(sflag==CLONEOPEN) {
  970. X        for(dev=0;dev<tap_cnt;dev++){
  971. X            if((tap_tap[dev].tapmd_queue == NULL) &&
  972. X               (tap_tap[dev].tapdm_queue != NULL)){
  973. X                printf("tapopen: CLONE=%d\n",dev);
  974. X                break;
  975. X            }
  976. X        }
  977. X    } else {
  978. X        dev = minor(dev);
  979. X    }
  980. X#else
  981. X    /*
  982. X     * check if non-driver open 
  983. X     */
  984. X    if(sflag)
  985. X        return(OPENFAIL);
  986. X    dev = minor(dev);
  987. X#endif
  988. X
  989. X    if(dev>= tap_cnt)
  990. X        return(OPENFAIL);
  991. X    if(q->q_ptr){
  992. X        u.u_error = EBUSY;    /* only 1 user of tapc at a time ??? */
  993. X        return(OPENFAIL);
  994. X    }
  995. X
  996. X    tap = &tap_tap[dev];
  997. X    if(!(tap->tapdm_queue)){
  998. X        u.u_error = ENETUNREACH;    
  999. X        return(OPENFAIL);
  1000. X    }
  1001. X
  1002. X    /*
  1003. X     * if opened with O_NDELAY reverse the connection
  1004. X     */
  1005. X    if(flag&FNDELAY){
  1006. X        if(!suser()){
  1007. X            u.u_error = EACCES;
  1008. X            return(OPENFAIL);
  1009. X        }
  1010. X        tap->tap_flags |= TAP_REVERSE;
  1011. X    } else
  1012. X        tap->tap_flags &= ~TAP_REVERSE;
  1013. X
  1014. X    WR(q)->q_ptr = (char *)tap;
  1015. X    q->q_ptr = (char *)tap;
  1016. X    tap->tapmd_queue = q;
  1017. X    return(dev);    
  1018. X}
  1019. X
  1020. Xstatic int tapcwput(q, mp)
  1021. X    queue_t    *q;    
  1022. X    mblk_t    *mp;   
  1023. X{
  1024. X    switch(mp->b_datap->db_type){
  1025. X    case M_IOCTL: {            /* NAK all ioctl's */
  1026. X        /* struct iocblk *iocp; */
  1027. X
  1028. X        /* iocp = (struct iocblk *)mp->b_rptr; */
  1029. X        mp->b_datap->db_type=M_IOCNAK;
  1030. X        qreply(q,mp);
  1031. X        break;
  1032. X    }
  1033. X    case M_FLUSH:
  1034. X        if(*mp->b_rptr & FLUSHW)
  1035. X            flushq(q,0);
  1036. X        if(*mp->b_rptr & FLUSHR){
  1037. X            flushq(RD(q),0);
  1038. X            *mp->b_rptr &= ~FLUSHW;
  1039. X            qreply(q,mp);
  1040. X        } else
  1041. X            freemsg(mp);
  1042. X        break;
  1043. X    case M_DATA: {
  1044. X        struct tap *tap;
  1045. X        
  1046. X        tap = (struct tap *)q->q_ptr;    
  1047. X        if(tap->tapdm_queue) {
  1048. X            if(tap->tap_flags&TAP_REVERSE)
  1049. X                putnext(WR(tap->tapdm_queue), mp);    
  1050. X            else
  1051. X                putnext(tap->tapdm_queue, mp);    
  1052. X        } else {
  1053. X            (void)putctl1(RD(q)->q_next, M_ERROR, ECONNRESET); 
  1054. X            freemsg(mp);
  1055. X        }
  1056. X        break;
  1057. X    }
  1058. X        
  1059. X    default:        /* discard other messages */
  1060. X        freemsg(mp);
  1061. X    }
  1062. X}
  1063. X
  1064. Xstatic int tapcrput(q, mp)
  1065. X    queue_t    *q;    
  1066. X    mblk_t    *mp;   
  1067. X{
  1068. X    putnext(q, mp);        
  1069. X}
  1070. X
  1071. Xstatic int tapcclose(q, flag)
  1072. X    queue_t    *q;
  1073. X    int    flag;
  1074. X{
  1075. X    struct tap *tap;
  1076. X
  1077. X    tap = (struct tap *) q->q_ptr;
  1078. X    tap->tapmd_queue = NULL;
  1079. X}
  1080. X
  1081. X#endif  NTAP
  1082. SHAR_EOF
  1083. $TOUCH -am 0508132093 tap.c &&
  1084. chmod 0444 tap.c ||
  1085. echo "restore of tap.c failed"
  1086. set `wc -c tap.c`;Wc_c=$1
  1087. if test "$Wc_c" != "8096"; then
  1088.     echo original size 8096, current size $Wc_c
  1089. fi
  1090. # ============= tap.h ==============
  1091. echo "x - extracting tap.h (Text)"
  1092. sed 's/^X//' << 'SHAR_EOF' > tap.h &&
  1093. X/* 
  1094. X * @(#)tap.h    1.25 5/8/93
  1095. X */
  1096. X
  1097. X/*
  1098. X * NOTE:
  1099. X * this header file is only needed for the loadable version of the driver
  1100. X * if the driver is linked permanently to vmunix this file is generated 
  1101. X * by config(1)
  1102. X */
  1103. X
  1104. X#define NTAP 8    /* see also : ./load at CMINORLIST */
  1105. SHAR_EOF
  1106. $TOUCH -am 0508132093 tap.h &&
  1107. chmod 0444 tap.h ||
  1108. echo "restore of tap.h failed"
  1109. set `wc -c tap.h`;Wc_c=$1
  1110. if test "$Wc_c" != "267"; then
  1111.     echo original size 267, current size $Wc_c
  1112. fi
  1113. # ============= tapmon.c ==============
  1114. echo "x - extracting tapmon.c (Text)"
  1115. sed 's/^X//' << 'SHAR_EOF' > tapmon.c &&
  1116. X/*
  1117. X * read/write /dev/tapc* utility
  1118. X */
  1119. X#include <stdio.h>
  1120. X/* #include <ctype.h> */
  1121. X#include <sys/types.h>
  1122. X/* #include <sys/time.h> */
  1123. X#include <fcntl.h>
  1124. X#include <sys/filio.h>
  1125. X#include <sys/termios.h>
  1126. X
  1127. X#define STDIN    0
  1128. X#define STDOUT    1
  1129. X
  1130. X#define NAME    "/dev/tapc%d"
  1131. X#define CLONENAME "/dev/tapcx"
  1132. X
  1133. X#define ESCAPE    31    /* CTRL-_ */
  1134. X
  1135. X#ifndef lint
  1136. Xstatic    char sccsid[] = "@(#)tapmon.c    1.25 5/8/93";
  1137. X#endif
  1138. X
  1139. Xchar *myname;
  1140. X
  1141. Xint viatty;
  1142. Xstruct termios old,new;
  1143. X
  1144. Xusage()
  1145. X{
  1146. X    (void)fprintf(stderr,"Usage: %s [-r] <tap-id>\n",myname);
  1147. X    (void)fprintf(stderr,"       tap-id: 0-255|x\n");
  1148. X    exit(1);
  1149. X}
  1150. X
  1151. Xmain(argc,argv)
  1152. Xint argc;
  1153. Xchar *argv[];
  1154. X{
  1155. X    unsigned long id;
  1156. X    int f,r;
  1157. X    char name[sizeof(NAME)+3];
  1158. X    char *ptr;
  1159. X    int c,errflg=0,reverse=0;
  1160. X    extern char *optarg;
  1161. X    extern int optind;
  1162. X
  1163. X    myname=argv[0];
  1164. X
  1165. X
  1166. X    while ((c = getopt(argc, argv, "r")) != -1){
  1167. X        switch (c) {
  1168. X        case 'r':
  1169. X            reverse++;
  1170. X            break;
  1171. X        case '?':
  1172. X        default:
  1173. X            errflg++;
  1174. X        }
  1175. X    }
  1176. X    if (errflg||(optind+1)!=argc) {
  1177. X        usage();
  1178. X    }
  1179. X
  1180. X    if(!strcmp(argv[optind],"x"))
  1181. X        sprintf(name,CLONENAME);
  1182. X    else {
  1183. X        id=strtol(argv[optind],&ptr,0);
  1184. X        if(id>255||*ptr!='\0')
  1185. X            usage();
  1186. X        sprintf(name,NAME,id);
  1187. X    }
  1188. X
  1189. X    if((f=open(name,O_RDWR|(reverse?O_NDELAY:0)))<0){
  1190. X        perror(name);
  1191. X        exit(1);
  1192. X    }
  1193. X
  1194. X    ttyset(name);
  1195. X    r=connect(f);
  1196. X    close(f);
  1197. X    ttyreset();
  1198. X    return(r);
  1199. X}
  1200. X
  1201. Xttyset(name)
  1202. Xchar *name;
  1203. X{
  1204. X    if(isatty(STDIN)){
  1205. X        viatty=1;
  1206. X        fprintf(stderr,"CONNECTED TO %s\n",name);
  1207. X        fprintf(stderr,"ESCAPE CHARACTER IS CTRL-%c\n",ESCAPE+'@');
  1208. X        if(ioctl(STDIN,TCGETS,&old)==(-1)){
  1209. X            perror("TCGETS");
  1210. X            exit(1);
  1211. X        }
  1212. X        new=old;
  1213. X        new.c_iflag = 0;
  1214. X        /* new.c_oflag = 0;*/
  1215. X        new.c_lflag = 0;
  1216. X        if(ioctl(STDIN,TCSETS,&new)==(-1)){
  1217. X            perror("TCSETS");
  1218. X            exit(1);
  1219. X        }
  1220. X    }
  1221. X}
  1222. X
  1223. Xttyreset()
  1224. X{
  1225. X    if(viatty){
  1226. X        if(ioctl(STDIN,TCSETS,&old)==(-1)){
  1227. X            perror("TCSETS");
  1228. X            exit(1);
  1229. X        }
  1230. X        fprintf(stderr,"\nCONNECTION CLOSED\n");
  1231. X    }
  1232. X}
  1233. X
  1234. Xconnect(f)
  1235. X{
  1236. X    register int n,s;
  1237. X    int x,w;
  1238. X    fd_set fdset;
  1239. X    char buf[512];
  1240. X
  1241. X    s=sizeof(buf);
  1242. X    w=f+1;
  1243. X    FD_ZERO(&fdset);
  1244. X    FD_SET(STDIN,&fdset);
  1245. X    FD_SET(f,&fdset);
  1246. X
  1247. X    while((x=select(w,&fdset,NULL,NULL,NULL))){
  1248. X        if( FD_ISSET (f, &fdset)){
  1249. X            if(ioctl(f,FIONREAD,&n)==(-1)){
  1250. X                perror(myname);
  1251. X                return(10);
  1252. X            }
  1253. X            if(!n)
  1254. X                break;
  1255. X            n = (n<s)?n:s;
  1256. X            if(read(f,buf,n)!=n){
  1257. X                perror(myname);
  1258. X                return(11);
  1259. X            }
  1260. X            (void)write(STDOUT,buf,n);
  1261. X        }
  1262. X        if( FD_ISSET (STDIN, &fdset)){
  1263. X            if(ioctl(STDIN,FIONREAD,&n)==(-1)){
  1264. X                perror(myname);
  1265. X                return(12);
  1266. X            }
  1267. X            if(!n)
  1268. X                break;
  1269. X            n = (n<s)?n:s;
  1270. X            if(read(STDIN,buf,n)!=n){
  1271. X                perror(myname);
  1272. X                return(13);
  1273. X            }
  1274. X            if(viatty&&buf[0]==ESCAPE)
  1275. X                break;    
  1276. X            (void)write(f,buf,n);
  1277. X        }
  1278. X        FD_SET(STDIN,&fdset); /* again and again */
  1279. X        FD_SET(f,&fdset);
  1280. X    }
  1281. X    return(0);
  1282. X}
  1283. SHAR_EOF
  1284. $TOUCH -am 0508132093 tapmon.c &&
  1285. chmod 0444 tapmon.c ||
  1286. echo "restore of tapmon.c failed"
  1287. set `wc -c tapmon.c`;Wc_c=$1
  1288. if test "$Wc_c" != "2658"; then
  1289.     echo original size 2658, current size $Wc_c
  1290. fi
  1291. # ============= streams.c ==============
  1292. echo "x - extracting streams.c (Text)"
  1293. sed 's/^X//' << 'SHAR_EOF' > streams.c &&
  1294. X
  1295. X#include <stdio.h>
  1296. X#include <sys/stropts.h> 
  1297. X
  1298. X#ifndef lint
  1299. Xstatic    char sccsid[] = "@(#)streams.c    1.25 5/8/93";
  1300. X#endif
  1301. X
  1302. Xint silence = 0;
  1303. X
  1304. Xpop(fd,namewanted)
  1305. Xchar *namewanted;
  1306. X{
  1307. X    char name[64];
  1308. X
  1309. X    if(ioctl(fd, I_LOOK, name) != -1) {
  1310. X        if(!strcmp(name,namewanted)){
  1311. X            if(!silence)
  1312. X                (void)fprintf(stderr,"popping module: %s\n", name);
  1313. X            if(ioctl(fd,I_POP,0) == -1)
  1314. X                if(!silence)
  1315. X                    perror("ioctl I_POP");
  1316. X        }else{
  1317. X
  1318. X            if(!silence)
  1319. X                (void)fprintf(stderr,
  1320. X                "module %s not pop,module %s is on stack top\n",
  1321. X                namewanted,name);
  1322. X        }
  1323. X    } else {
  1324. X        if(!silence)
  1325. X            (void)fprintf(stderr,"no module on stack\n");
  1326. X    }
  1327. X}
  1328. X
  1329. Xpush(fd,name)
  1330. Xchar *name;
  1331. X{
  1332. X    int r;
  1333. X
  1334. X    if(!silence)
  1335. X        (void)fprintf(stderr,"pushing module: %s\n", name);
  1336. X    if ((r=ioctl(fd, I_PUSH, name)) < 0) 
  1337. X        if(!silence)
  1338. X            perror(name);
  1339. X}
  1340. X
  1341. Xmain(argc, argv)
  1342. Xint argc;
  1343. Xchar **argv;
  1344. X{
  1345. X    int c,errflg=0;
  1346. X    extern char *optarg;
  1347. X    extern int optind;
  1348. X
  1349. X    while ((c = getopt(argc, argv, "so:u:")) != -1){
  1350. X        switch (c) {
  1351. X        case 'o':
  1352. X            pop(0,optarg);
  1353. X            break;
  1354. X        case 'u':
  1355. X            push(0,optarg);
  1356. X            break;
  1357. X        case 's':
  1358. X            silence = ~silence;
  1359. X            break;
  1360. X        case '?':
  1361. X        default:
  1362. X            errflg++;
  1363. X        }
  1364. X    }
  1365. X    if (errflg||optind!=argc||argc==1) {
  1366. X        (void)fprintf(stderr, 
  1367. X            "Usage: %s [-s] [-o module-to-pop] [-u module-to-push] ...\n",
  1368. X            argv[0]);
  1369. X        (void)fprintf(stderr,
  1370. X            "       the order of all options is important\n");
  1371. X        exit (2);
  1372. X    }
  1373. X    return(0);
  1374. X}
  1375. SHAR_EOF
  1376. $TOUCH -am 0508132093 streams.c &&
  1377. chmod 0444 streams.c ||
  1378. echo "restore of streams.c failed"
  1379. set `wc -c streams.c`;Wc_c=$1
  1380. if test "$Wc_c" != "1386"; then
  1381.     echo original size 1386, current size $Wc_c
  1382. fi
  1383. exit 0
  1384.  
  1385.