home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / sources / unix / 275 < prev    next >
Encoding:
Text File  |  1992-09-09  |  56.2 KB  |  1,715 lines

  1. Newsgroups: comp.sources.unix
  2. Path: sparky!uunet!spool.mu.edu!decwrl!pa.dec.com!tp
  3. From: thoth@lightning.cis.ufl.edu (Robert H. Forsman, Jr)
  4. Subject: v26i076: netpipes -- BSD network pipe tools, Part01/01
  5. Message-ID: <1992Sep9.235949.21671@PA.dec.com>
  6. Originator: tp@cognition.pa.dec.com
  7. Sender: unix-sources-moderator@pa.dec.com
  8. Organization: DEC Palo Alto
  9. Date: Wed, 9 Sep 92 23:59:49 GMT
  10. Approved: vixie@pa.dec.com
  11. Lines: 1702
  12.  
  13. Submitted-By: thoth@lightning.cis.ufl.edu (Robert H. Forsman, Jr)
  14. Posting-Number: Volume 26, Issue 76
  15. Archive-Name: netpipes/part01
  16.  
  17.  
  18. faucet and hose:
  19.   These two utilities are useful for connecting arbitrary programs
  20. over sockets.  The power of the '|' character in the shell can now be
  21. used over the network.
  22.  
  23. [ Compiled and tested on Ultrix 4.2 and SunOS 4.1.*.  Faucet and hose
  24. are interesting utilities for working across the network, but remember
  25. that there is no provision for security in these tools. Also, you make
  26. want to change the destination directory for "make install" to be
  27. something like /usr/local/bin.]
  28.  
  29.  
  30. #! /bin/sh
  31. # This is a shell archive.  Remove anything before this line, then unpack
  32. # it by saving it into a file and typing "sh file".  To overwrite existing
  33. # files, type "sh file -c".  You can also feed this as standard input via
  34. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  35. # will see the following message at the end:
  36. #        "End of archive 1 (of 1)."
  37. # Contents:  COPYING Makefile README faucet.1 faucet.c hose.1 hose.c
  38. #   portname.c
  39. # Wrapped by tp@cognition.pa.dec.com on Wed Sep  9 16:49:24 1992
  40. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  41. if test -f 'COPYING' -a "${1}" != "-c" ; then 
  42.   echo shar: Will not clobber existing file \"'COPYING'\"
  43. else
  44. echo shar: Extracting \"'COPYING'\" \(17981 characters\)
  45. sed "s/^X//" >'COPYING' <<'END_OF_FILE'
  46. X            GNU GENERAL PUBLIC LICENSE
  47. X               Version 2, June 1991
  48. X
  49. X Copyright (C) 1989, 1991 Free Software Foundation, Inc.
  50. X                          675 Mass Ave, Cambridge, MA 02139, USA
  51. X Everyone is permitted to copy and distribute verbatim copies
  52. X of this license document, but changing it is not allowed.
  53. X
  54. X                Preamble
  55. X
  56. X  The licenses for most software are designed to take away your
  57. Xfreedom to share and change it.  By contrast, the GNU General Public
  58. XLicense is intended to guarantee your freedom to share and change free
  59. Xsoftware--to make sure the software is free for all its users.  This
  60. XGeneral Public License applies to most of the Free Software
  61. XFoundation's software and to any other program whose authors commit to
  62. Xusing it.  (Some other Free Software Foundation software is covered by
  63. Xhe GNU Library General Public License instead.)  You can apply it to
  64. Xyour programs, too.
  65. X
  66. X  When we speak of free software, we are referring to freedom, not
  67. Xprice.  Our General Public Licenses are designed to make sure that you
  68. Xhave the freedom to distribute copies of free software (and charge for
  69. Xthis service if you wish), that you receive source code or can get it
  70. Xif you want it, that you can change the software or use pieces of it
  71. Xin new free programs; and that you know you can do these things.
  72. X
  73. X  To protect your rights, we need to make restrictions that forbid
  74. Xanyone to deny you these rights or to ask you to surrender the rights.
  75. XThese restrictions translate to certain responsibilities for you if you
  76. Xdistribute copies of the software, or if you modify it.
  77. X
  78. X  For example, if you distribute copies of such a program, whether
  79. Xgratis or for a fee, you must give the recipients all the rights that
  80. Xyou have.  You must make sure that they, too, receive or can get the
  81. Xsource code.  And you must show them these terms so they know their
  82. Xrights.
  83. X
  84. X  We protect your rights with two steps: (1) copyright the software, and
  85. X(2) offer you this license which gives you legal permission to copy,
  86. Xdistribute and/or modify the software.
  87. X
  88. X  Also, for each author's protection and ours, we want to make certain
  89. Xthat everyone understands that there is no warranty for this free
  90. Xsoftware.  If the software is modified by someone else and passed on, we
  91. Xwant its recipients to know that what they have is not the original, so
  92. Xthat any problems introduced by others will not reflect on the original
  93. Xauthors' reputations.
  94. X
  95. X  Finally, any free program is threatened constantly by software
  96. Xpatents.  We wish to avoid the danger that redistributors of a free
  97. Xprogram will individually obtain patent licenses, in effect making the
  98. Xprogram proprietary.  To prevent this, we have made it clear that any
  99. Xpatent must be licensed for everyone's free use or not licensed at all.
  100. X
  101. X  The precise terms and conditions for copying, distribution and
  102. Xmodification follow.
  103. X
  104. X            GNU GENERAL PUBLIC LICENSE
  105. X   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
  106. X
  107. X  0. This License applies to any program or other work which contains
  108. Xa notice placed by the copyright holder saying it may be distributed
  109. Xunder the terms of this General Public License.  The "Program", below,
  110. Xrefers to any such program or work, and a "work based on the Program"
  111. Xmeans either the Program or any derivative work under copyright law:
  112. Xthat is to say, a work containing the Program or a portion of it,
  113. Xeither verbatim or with modifications and/or translated into another
  114. Xlanguage.  (Hereinafter, translation is included without limitation in
  115. Xthe term "modification".)  Each licensee is addressed as "you".
  116. X
  117. XActivities other than copying, distribution and modification are not
  118. Xcovered by this License; they are outside its scope.  The act of
  119. Xrunning the Program is not restricted, and the output from the Program
  120. Xis covered only if its contents constitute a work based on the
  121. XProgram (independent of having been made by running the Program).
  122. XWhether that is true depends on what the Program does.
  123. X
  124. X  1. You may copy and distribute verbatim copies of the Program's
  125. Xsource code as you receive it, in any medium, provided that you
  126. Xconspicuously and appropriately publish on each copy an appropriate
  127. Xcopyright notice and disclaimer of warranty; keep intact all the
  128. Xnotices that refer to this License and to the absence of any warranty;
  129. Xand give any other recipients of the Program a copy of this License
  130. Xalong with the Program.
  131. X
  132. XYou may charge a fee for the physical act of transferring a copy, and
  133. Xyou may at your option offer warranty protection in exchange for a fee.
  134. X
  135. X  2. You may modify your copy or copies of the Program or any portion
  136. Xof it, thus forming a work based on the Program, and copy and
  137. Xdistribute such modifications or work under the terms of Section 1
  138. Xabove, provided that you also meet all of these conditions:
  139. X
  140. X    a) You must cause the modified files to carry prominent notices
  141. X    stating that you changed the files and the date of any change.
  142. X
  143. X    b) You must cause any work that you distribute or publish, that in
  144. X    whole or in part contains or is derived from the Program or any
  145. X    part thereof, to be licensed as a whole at no charge to all third
  146. X    parties under the terms of this License.
  147. X
  148. X    c) If the modified program normally reads commands interactively
  149. X    when run, you must cause it, when started running for such
  150. X    interactive use in the most ordinary way, to print or display an
  151. X    announcement including an appropriate copyright notice and a
  152. X    notice that there is no warranty (or else, saying that you provide
  153. X    a warranty) and that users may redistribute the program under
  154. X    these conditions, and telling the user how to view a copy of this
  155. X    License.  (Exception: if the Program itself is interactive but
  156. X    does not normally print such an announcement, your work based on
  157. X    the Program is not required to print an announcement.)
  158. X
  159. XThese requirements apply to the modified work as a whole.  If
  160. Xidentifiable sections of that work are not derived from the Program,
  161. Xand can be reasonably considered independent and separate works in
  162. Xthemselves, then this License, and its terms, do not apply to those
  163. Xsections when you distribute them as separate works.  But when you
  164. Xdistribute the same sections as part of a whole which is a work based
  165. Xon the Program, the distribution of the whole must be on the terms of
  166. Xthis License, whose permissions for other licensees extend to the
  167. Xentire whole, and thus to each and every part regardless of who wrote it.
  168. X
  169. XThus, it is not the intent of this section to claim rights or contest
  170. Xyour rights to work written entirely by you; rather, the intent is to
  171. Xexercise the right to control the distribution of derivative or
  172. Xcollective works based on the Program.
  173. X
  174. XIn addition, mere aggregation of another work not based on the Program
  175. Xwith the Program (or with a work based on the Program) on a volume of
  176. Xa storage or distribution medium does not bring the other work under
  177. Xthe scope of this License.
  178. X
  179. X  3. You may copy and distribute the Program (or a work based on it,
  180. Xunder Section 2) in object code or executable form under the terms of
  181. XSections 1 and 2 above provided that you also do one of the following:
  182. X
  183. X    a) Accompany it with the complete corresponding machine-readable
  184. X    source code, which must be distributed under the terms of Sections
  185. X    1 and 2 above on a medium customarily used for software interchange; or,
  186. X
  187. X    b) Accompany it with a written offer, valid for at least three
  188. X    years, to give any third party, for a charge no more than your
  189. X    cost of physically performing source distribution, a complete
  190. X    machine-readable copy of the corresponding source code, to be
  191. X    distributed under the terms of Sections 1 and 2 above on a medium
  192. X    customarily used for software interchange; or,
  193. X
  194. X    c) Accompany it with the information you received as to the offer
  195. X    to distribute corresponding source code.  (This alternative is
  196. X    allowed only for noncommercial distribution and only if you
  197. X    received the program in object code or executable form with such
  198. X    an offer, in accord with Subsection b above.)
  199. X
  200. XThe source code for a work means the preferred form of the work for
  201. Xmaking modifications to it.  For an executable work, complete source
  202. Xcode means all the source code for all modules it contains, plus any
  203. Xassociated interface definition files, plus the scripts used to
  204. Xcontrol compilation and installation of the executable.  However, as a
  205. Xspecial exception, the source code distributed need not include
  206. Xanything that is normally distributed (in either source or binary
  207. Xform) with the major components (compiler, kernel, and so on) of the
  208. Xoperating system on which the executable runs, unless that component
  209. Xitself accompanies the executable.
  210. X
  211. XIf distribution of executable or object code is made by offering
  212. Xaccess to copy from a designated place, then offering equivalent
  213. Xaccess to copy the source code from the same place counts as
  214. Xdistribution of the source code, even though third parties are not
  215. Xcompelled to copy the source along with the object code.
  216. X
  217. X  4. You may not copy, modify, sublicense, or distribute the Program
  218. Xexcept as expressly provided under this License.  Any attempt
  219. Xotherwise to copy, modify, sublicense or distribute the Program is
  220. Xvoid, and will automatically terminate your rights under this License.
  221. XHowever, parties who have received copies, or rights, from you under
  222. Xthis License will not have their licenses terminated so long as such
  223. Xparties remain in full compliance.
  224. X
  225. X  5. You are not required to accept this License, since you have not
  226. Xsigned it.  However, nothing else grants you permission to modify or
  227. Xdistribute the Program or its derivative works.  These actions are
  228. Xprohibited by law if you do not accept this License.  Therefore, by
  229. Xmodifying or distributing the Program (or any work based on the
  230. XProgram), you indicate your acceptance of this License to do so, and
  231. Xall its terms and conditions for copying, distributing or modifying
  232. Xthe Program or works based on it.
  233. X
  234. X  6. Each time you redistribute the Program (or any work based on the
  235. XProgram), the recipient automatically receives a license from the
  236. Xoriginal licensor to copy, distribute or modify the Program subject to
  237. Xthese terms and conditions.  You may not impose any further
  238. Xrestrictions on the recipients' exercise of the rights granted herein.
  239. XYou are not responsible for enforcing compliance by third parties to
  240. Xthis License.
  241. X
  242. X  7. If, as a consequence of a court judgment or allegation of patent
  243. Xinfringement or for any other reason (not limited to patent issues),
  244. Xconditions are imposed on you (whether by court order, agreement or
  245. Xotherwise) that contradict the conditions of this License, they do not
  246. Xexcuse you from the conditions of this License.  If you cannot
  247. Xdistribute so as to satisfy simultaneously your obligations under this
  248. XLicense and any other pertinent obligations, then as a consequence you
  249. Xmay not distribute the Program at all.  For example, if a patent
  250. Xlicense would not permit royalty-free redistribution of the Program by
  251. Xall those who receive copies directly or indirectly through you, then
  252. Xthe only way you could satisfy both it and this License would be to
  253. Xrefrain entirely from distribution of the Program.
  254. X
  255. XIf any portion of this section is held invalid or unenforceable under
  256. Xany particular circumstance, the balance of the section is intended to
  257. Xapply and the section as a whole is intended to apply in other
  258. Xcircumstances.
  259. X
  260. XIt is not the purpose of this section to induce you to infringe any
  261. Xpatents or other property right claims or to contest validity of any
  262. Xsuch claims; this section has the sole purpose of protecting the
  263. Xintegrity of the free software distribution system, which is
  264. Ximplemented by public license practices.  Many people have made
  265. Xgenerous contributions to the wide range of software distributed
  266. Xthrough that system in reliance on consistent application of that
  267. Xsystem; it is up to the author/donor to decide if he or she is willing
  268. Xto distribute software through any other system and a licensee cannot
  269. Ximpose that choice.
  270. X
  271. XThis section is intended to make thoroughly clear what is believed to
  272. Xbe a consequence of the rest of this License.
  273. X
  274. X  8. If the distribution and/or use of the Program is restricted in
  275. Xcertain countries either by patents or by copyrighted interfaces, the
  276. Xoriginal copyright holder who places the Program under this License
  277. Xmay add an explicit geographical distribution limitation excluding
  278. Xthose countries, so that distribution is permitted only in or among
  279. Xcountries not thus excluded.  In such case, this License incorporates
  280. Xthe limitation as if written in the body of this License.
  281. X
  282. X  9. The Free Software Foundation may publish revised and/or new versions
  283. Xof the General Public License from time to time.  Such new versions will
  284. Xbe similar in spirit to the present version, but may differ in detail to
  285. Xaddress new problems or concerns.
  286. X
  287. XEach version is given a distinguishing version number.  If the Program
  288. Xspecifies a version number of this License which applies to it and "any
  289. Xlater version", you have the option of following the terms and conditions
  290. Xeither of that version or of any later version published by the Free
  291. XSoftware Foundation.  If the Program does not specify a version number of
  292. Xthis License, you may choose any version ever published by the Free Software
  293. XFoundation.
  294. X
  295. X  10. If you wish to incorporate parts of the Program into other free
  296. Xprograms whose distribution conditions are different, write to the author
  297. Xto ask for permission.  For software which is copyrighted by the Free
  298. XSoftware Foundation, write to the Free Software Foundation; we sometimes
  299. Xmake exceptions for this.  Our decision will be guided by the two goals
  300. Xof preserving the free status of all derivatives of our free software and
  301. Xof promoting the sharing and reuse of software generally.
  302. X
  303. X                NO WARRANTY
  304. X
  305. X  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
  306. XFOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
  307. XOTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
  308. XPROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
  309. XOR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  310. XMERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
  311. XTO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
  312. XPROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
  313. XREPAIR OR CORRECTION.
  314. X
  315. X  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
  316. XWILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
  317. XREDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
  318. XINCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
  319. XOUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
  320. XTO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
  321. XYOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
  322. XPROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
  323. XPOSSIBILITY OF SUCH DAMAGES.
  324. X
  325. X             END OF TERMS AND CONDITIONS
  326. X
  327. X    Appendix: How to Apply These Terms to Your New Programs
  328. X
  329. X  If you develop a new program, and you want it to be of the greatest
  330. Xpossible use to the public, the best way to achieve this is to make it
  331. Xfree software which everyone can redistribute and change under these terms.
  332. X
  333. X  To do so, attach the following notices to the program.  It is safest
  334. Xto attach them to the start of each source file to most effectively
  335. Xconvey the exclusion of warranty; and each file should have at least
  336. Xthe "copyright" line and a pointer to where the full notice is found.
  337. X
  338. X    <one line to give the program's name and a brief idea of what it does.>
  339. X    Copyright (C) 19yy  <name of author>
  340. X
  341. X    This program is free software; you can redistribute it and/or modify
  342. X    it under the terms of the GNU General Public License as published by
  343. X    the Free Software Foundation; either version 2 of the License, or
  344. X    (at your option) any later version.
  345. X
  346. X    This program is distributed in the hope that it will be useful,
  347. X    but WITHOUT ANY WARRANTY; without even the implied warranty of
  348. X    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  349. X    GNU General Public License for more details.
  350. X
  351. X    You should have received a copy of the GNU General Public License
  352. X    along with this program; if not, write to the Free Software
  353. X    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  354. X
  355. XAlso add information on how to contact you by electronic and paper mail.
  356. X
  357. XIf the program is interactive, make it output a short notice like this
  358. Xwhen it starts in an interactive mode:
  359. X
  360. X    Gnomovision version 69, Copyright (C) 19yy name of author
  361. X    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
  362. X    This is free software, and you are welcome to redistribute it
  363. X    under certain conditions; type `show c' for details.
  364. X
  365. XThe hypothetical commands `show w' and `show c' should show the appropriate
  366. Xparts of the General Public License.  Of course, the commands you use may
  367. Xbe called something other than `show w' and `show c'; they could even be
  368. Xmouse-clicks or menu items--whatever suits your program.
  369. X
  370. XYou should also get your employer (if you work as a programmer) or your
  371. Xschool, if any, to sign a "copyright disclaimer" for the program, if
  372. Xnecessary.  Here is a sample; alter the names:
  373. X
  374. X  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
  375. X  `Gnomovision' (which makes passes at compilers) written by James Hacker.
  376. X
  377. X  <signature of Ty Coon>, 1 April 1989
  378. X  Ty Coon, President of Vice
  379. X
  380. XThis General Public License does not permit incorporating your program into
  381. Xproprietary programs.  If your program is a subroutine library, you may
  382. Xconsider it more useful to permit linking proprietary applications with the
  383. Xlibrary.  If this is what you want to do, use the GNU Library General
  384. XPublic License instead of this License.
  385. END_OF_FILE
  386. if test 17981 -ne `wc -c <'COPYING'`; then
  387.     echo shar: \"'COPYING'\" unpacked with wrong size!
  388. fi
  389. # end of 'COPYING'
  390. fi
  391. if test -f 'Makefile' -a "${1}" != "-c" ; then 
  392.   echo shar: Will not clobber existing file \"'Makefile'\"
  393. else
  394. echo shar: Extracting \"'Makefile'\" \(1244 characters\)
  395. sed "s/^X//" >'Makefile' <<'END_OF_FILE'
  396. X#    faucet and hose: network pipe utilities
  397. X#    Copyright (C) 1992 Robert Forsman
  398. X#
  399. X#    This program is free software; you can redistribute it and/or modify
  400. X#    it under the terms of the GNU General Public License as published by
  401. X#    the Free Software Foundation; either version 2 of the License, or
  402. X#    (at your option) any later version.
  403. X#
  404. X#    This program is distributed in the hope that it will be useful,
  405. X#    but WITHOUT ANY WARRANTY; without even the implied warranty of
  406. X#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  407. X#    GNU General Public License for more details.
  408. X#
  409. X#    You should have received a copy of the GNU General Public License
  410. X#    along with this program; if not, write to the Free Software
  411. X#    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  412. X
  413. X#
  414. X# under HPUX you will probably have to make using LDLIBS=-lBSD
  415. X#
  416. X
  417. XCFLAGS = 
  418. X
  419. XFOBJS = faucet.o portname.o
  420. XHOBJS = hose.o portname.o
  421. X
  422. Xall    : faucet hose
  423. X
  424. Xfaucet    : ${FOBJS}
  425. X    ${CC} ${CFLAGS} -o $@ ${FOBJS} ${LDLIBS}
  426. X
  427. Xhose    : ${HOBJS}
  428. X    ${CC} ${CFLAGS} -o $@ ${HOBJS} ${LDLIBS}
  429. X
  430. Xinstall : all
  431. X    cp faucet hose ${HOME}/bin/`mach`
  432. X    cp faucet.1 hose.1 ${HOME}/man/man1
  433. X
  434. Xclean    :
  435. X    rm -f ${FOBJS}  ${HOBJS} 
  436. X
  437. Xspotless: clean
  438. X    rm -f *~ core  hose faucet
  439. END_OF_FILE
  440. if test 1244 -ne `wc -c <'Makefile'`; then
  441.     echo shar: \"'Makefile'\" unpacked with wrong size!
  442. fi
  443. # end of 'Makefile'
  444. fi
  445. if test -f 'README' -a "${1}" != "-c" ; then 
  446.   echo shar: Will not clobber existing file \"'README'\"
  447. else
  448. echo shar: Extracting \"'README'\" \(6701 characters\)
  449. sed "s/^X//" >'README' <<'END_OF_FILE'
  450. X
  451. X"Mutant" Bob Forsman and his amazing 43 burner stove present
  452. X------------------------------------------------------------
  453. X            "stuff"
  454. X------------------------------------------------------------
  455. X
  456. X  This directory contains faucet and hose.
  457. X
  458. X
  459. X
  460. Xfaucet and hose:
  461. X
  462. X  These two utilities are useful for connecting arbitrary programs
  463. Xover sockets.  The power of the '|' characeter in the shell can now be
  464. Xused over the network.
  465. X  As an example of what they can do, compile them and on one machine
  466. Xtype
  467. X
  468. Xlightning:21 % ./faucet 3000 "tar cf - ." out
  469. X
  470. X and on another type
  471. X
  472. Xsprings:3 % ./hose lightning 3000 "tar tvf -" in
  473. X
  474. X  You will get output (from machine springs) that looks like this.
  475. X
  476. Xrwxr-xr-x771/50      0 Jul  7 11:53 1990 ./
  477. Xrw-r-----771/50   9266 Jun 30 21:41 1990 ./faucet.c~
  478. Xrw-r--r--771/50   6086 Mar  6 21:40 1990 ./server.cc
  479. Xrw-r--r--771/50   1203 Jul  7 11:49 1990 ./Makefile
  480. Xrw-r-----771/50   9757 Jul  7 11:49 1990 ./faucet.c
  481. Xrw-r--r--771/50   4241 Jun 23 04:09 1990 ./hose.c~
  482. Xrwxr-xr-x771/50  24576 Jul  7 11:50 1990 ./hose
  483. Xrw-r--r--771/50   4041 Jul  7 11:50 1990 ./hose.c
  484. Xrw-r-----771/50    592 Jul  7 11:48 1990 ./portname.c
  485. Xrw-r--r--771/50    317 Jul  7 11:48 1990 ./portname.o
  486. Xrwxr-xr-x771/50  24576 Jul  7 11:50 1990 ./faucet
  487. Xrw-r--r--771/50   3378 Jul  7 11:50 1990 ./hose.o
  488. Xrw-r--r--771/50   1069 Jun 23 02:42 1990 ./Makefile~
  489. Xrw-r--r--771/50   4662 Jul  7 11:50 1990 ./faucet.o
  490. Xrw-r-----771/50    377 Jul  7 11:53 1990 ./#README#
  491. Xrw-r-----771/50    371 Jul  7 11:53 1990 ./README
  492. Xrw-r--r--771/50   2917 Mar  6 22:13 1990 ./client.cc
  493. X
  494. X  The 3000 is the port number to connect to.  Normal users can use any
  495. Xnumber over 1023.  You can also specify a service name in place of a
  496. Xnumber since the program can look it up from the services database.
  497. X  The argument in ""s (argv[2] for faucet, argv[3] for hose) is the
  498. Xcommand to be connected to the socket.  The flags in, out and err
  499. Xgovorn which file descriptors get connected to the socket after the
  500. Xconnection is successful.
  501. X  hose is a one-shot program.  It connects to the foreign server
  502. Xsocket and execs the command.  faucet is an undying server.  Every
  503. Xtime it recieves a connection on its socket it forks and execs a "csh
  504. X-c".  faucet can be limited to one-shot by the "once" flag.
  505. X
  506. XSYNTAX
  507. X
  508. X   faucet <port> <command> (in|out|err)+ [once] [verb(|ose)] [quiet]
  509. X        [unix] [foreignport <port>] [foreignhost <host>]
  510. X
  511. X   hose <hostname> <port> <command> (in|out|err)+ [unix] [localport <port>]}
  512. X
  513. X  Host names can be be the name of the machine or (if no name is
  514. Xfound) the internet number.  The individual numbers are sscanfed with
  515. X%i so 0x or 0 prefixes mean hex or octal instead of decimal for that
  516. Xone byte.
  517. X  You must chose at least one of in, out, and err.  The other flags
  518. Xare optional and listed below
  519. X   unix.........causes the program to go into unix-domain socket mode.
  520. X        hose can also be forced into unix-domain operation by
  521. X        specifying -unix- as the hostname (those dashes are
  522. X        part of the arg) or by being run with argv[0] as the
  523. X        string "uhose" (possible by hardlinking the binary).
  524. X        Port names are then treated as unix domain socket
  525. X        addresses (filenames) as opposed to internet port
  526. X        numbers.
  527. X   localport....(only on hose) asks hose to bind to a specific local
  528. X        port.
  529. X   once.........(only on faucet) the faucet command will not fork, but
  530. X        will exec the command, and when the command exits
  531. X        you're done.
  532. X   verbose|quiet (only on faucet) enables|disables the printing of
  533. X        extra information such as what host and port faucet is
  534. X        getting connections from.
  535. X   foreignport..(only on faucet) causes faucet to refuse (close
  536. X        immediately) any connection from a machine that hasn't
  537. X        bound its socket to the port specified immediately
  538. X        after the foreignport flag.  This can be used with the
  539. X        localport option of hose to perform crude
  540. X        authentication.  If the foreignport is <1024 then only
  541. X        a foreign root user will be able to connect to your
  542. X        faucet because only root can bind to a port number
  543. X        below 1024.
  544. X   foreignhost..(only on faucet) causes faucet to refuse (close
  545. X        immediately) any connection from any machine other
  546. X        than the host specified immediately after the
  547. X        foreignhost flag.
  548. X
  549. X  Be aware that addresses and ports can be spoofed if your network
  550. Xisn't secure (yours probably isn't).  If you have PCs or other
  551. Xnon-UNIX boxes connected to the network, then it's DISGUSTINGLY easy
  552. Xfor ANYONE to spoof the network.
  553. X
  554. X
  555. X
  556. XEXAMPLES
  557. X
  558. X    FAUCET                    HOSE
  559. X
  560. Xreef:100 % ./faucet chat "echo send
  561. X$14M and 2 airline stewardesses or
  562. Xyou'll never see Hoffa alive"
  563. Xforeignhost azalea verbose out
  564. X
  565. X                reef:40 % ./hose reef chat cat in
  566. X
  567. Xrefusing connection from host 128.
  568. X227.224.61(reef.cis.ufl.edu).
  569. X
  570. X                azalea:20 % ./hose reef chat cat in
  571. X
  572. X./faucet: Got connection from 128.
  573. X227.224.55(azalea.cis.ufl.edu) port
  574. X1687
  575. XUnmatched '.
  576. X                /* darn, screwed up the shell quoting */
  577. X^C
  578. X
  579. Xreef:107 % ./faucet /tmp/blah 'echo
  580. Xsend '\'\$14M\'' and 2 airline
  581. Xstewardesses or you'\\\''ll never
  582. Xsee Hoffa alive' foreignhost azalea
  583. Xverbose out foreignport /tmp/auth unix
  584. X./faucet: foreignhost parameter makes no
  585. Xsense with UNIX domain sockets, ignoring.
  586. X                /* %#@)*, bite me */
  587. X
  588. X                reef:41 % ./hose -unix- /tmp/blah cat in
  589. X
  590. X./faucet: refusing connection from port
  591. X
  592. X                reef:43 % ./hose -unix- /tmp/blah cat in
  593. X                localport /tmp/auth
  594. X
  595. X./faucet: Got connection from /tmp/auth
  596. X
  597. X                send $14M and 2 airline stewardesses or
  598. X                you'll never see Hoffa alive
  599. X
  600. X
  601. X  Notice the elaborate quoting on that one.  faucet+hose fork a "csh
  602. X-c " to interpret the command.  The echo command had to be quoted so
  603. Xthat faucet saw:
  604. X
  605. Xecho send '$14M' and 2 airline stewardesses or you\'ll never see Hoffa alive
  606. X
  607. X  faucet then performed this system call
  608. X
  609. Xexecl("/bin/csh","csh","-c",argv[2],NULL);
  610. X
  611. X  and the "$14M" and "you'll" were properly quoted to survive THAT csh
  612. Xas well.  Commands to hose must be similarly protected.
  613. X
  614. X  Why use csh?
  615. X   1) This allows you to have pipelines and other fancy stuff inside
  616. X    the command, and
  617. X   2) I don't have to write code to parse the command!
  618. X
  619. X
  620. X
  621. XBUGS
  622. X
  623. X  Hoohoohoo, god knows what sort of bugs are waiting to rip your
  624. Xankles off.  I'm the only one who's extensively used these.  They were
  625. Xdeveloped on Sun3s and Sun4s.  They have been compiled (but not
  626. Xextensively tested) on Sonys, DECstations and HPs.  If your machine
  627. Xneeds different include files, start grepping and mail me the results.
  628. X
  629. X  If anything is not crystal clear, check the source and mail me.
  630. XI'll try to put it in the README.
  631. X
  632. X
  633. XAUTHOR
  634. X
  635. X  Robert H. Forsman Jr.        <thoth@lightning.cis.ufl.edu>
  636. X  former underpaid Systems Programmer
  637. X  now piddly underpaid Research Assistant
  638. X  University of Florida
  639. X  Department of Computer
  640. X  and Information Science
  641. END_OF_FILE
  642. if test 6701 -ne `wc -c <'README'`; then
  643.     echo shar: \"'README'\" unpacked with wrong size!
  644. fi
  645. # end of 'README'
  646. fi
  647. if test -f 'faucet.1' -a "${1}" != "-c" ; then 
  648.   echo shar: Will not clobber existing file \"'faucet.1'\"
  649. else
  650. echo shar: Extracting \"'faucet.1'\" \(4160 characters\)
  651. sed "s/^X//" >'faucet.1' <<'END_OF_FILE'
  652. X.\" faucet.1 Copyright 3/30/1992 by Robert Forsman
  653. X.TH FAUCET 1 "Mar 30 1992"
  654. X.SH NAME
  655. Xfaucet - a fixture for a BSD network pipe
  656. X.SH SYNOPSIS
  657. X\fBfaucet\fP \fIport\fP \fIcommand\fP (\fBin\fP|\fBout\fP|\fBerr\fP)
  658. X[\fBonce\fP] [\fBverbose\fP] [\fBquiet\fP] [\fBunix\fP]
  659. X[\fBforeignhost\fP \fIhost\fP] [\fBforeignport\fP \fIport\fP]
  660. X
  661. X.SH DESCRIPTION
  662. X.LP
  663. X.B faucet
  664. Xattempts to provide the functionality of pipes over the network.
  665. XIt behaves as the server end of a server\-client connection.
  666. XWhen used with
  667. X.B hose(1)
  668. Xit can function as a replacement for
  669. X.IP
  670. Xtar \-cf \- . | rsh other "cd destdir; tar -xf -"
  671. X.LP
  672. X.B faucet
  673. Xand
  674. X.B hose
  675. Xare especially useful when you don't have easy access to the
  676. Xdestination machine.
  677. X
  678. X.LP
  679. X.B faucet
  680. Xcreates a BSD socket, binds it to the
  681. X.I port
  682. Xspecified on the command line, and listens for connections.
  683. XEvery time
  684. X.B faucet
  685. Xgets a connection it forks the
  686. X.I command
  687. Xwith stdin, stdout, and/or stderr redirected according to the 
  688. X.B in out err
  689. Xflags.  If the
  690. X.B once
  691. Xflag is specified,
  692. X.B faucet
  693. Xwill exec(2) the
  694. X.I command
  695. Xinstead of fork(2)ing and exec(2)ing.  
  696. X.B once
  697. Xmeans that the network pipe
  698. Xis only good for one shot.
  699. XThe
  700. X.B verbose
  701. Xflag specifies that
  702. X.B faucet
  703. Xshould print information about connecting hosts .  This information
  704. Xincludes the numeric host address, host names, and foreign port numbers.
  705. XThe
  706. X.B quiet
  707. Xflag specifies that
  708. X.B faucet
  709. Xshould NOT print such info.
  710. X.B quiet
  711. Xis the default. The
  712. X.B unix
  713. Xflag specifies that the
  714. X.I port
  715. Xis not an internet port number or service name, but instead it is a
  716. Xfilename for a UNIX domain socket.  The
  717. X.B foreignhost
  718. Xoption specifies that faucet should reject all connections that do not
  719. Xcome from the
  720. X.I host
  721. Xmachine.  Similarly
  722. X.B foreignport
  723. Xspecifies that faucet should reject all connections that are not bound
  724. Xon their local machine to the
  725. X.I port
  726. Xargument.  The above two options allow a crude form of authentication.
  727. XNote that on most systems only root can bind a socket to a port number
  728. Xbelow 1024.
  729. X
  730. X.SH "EXAMPLES"
  731. X.LP
  732. XThis creates a TCP\-IP socket on the local machine bound to port 3000.
  733. X.IP
  734. Xexample% faucet 3000 "tar -cf - ." out verbose
  735. X.LP
  736. XEvery time some process (from any machine) attempts to connect to
  737. Xport 3000 on this machine the
  738. X.B faucet
  739. Xprogram will fork(2) a process and the child will exec(2) a
  740. X.IP
  741. X/bin/csh -c "tar -cf - ."
  742. X.LP
  743. XThe
  744. X.B out
  745. Xoption means that the output of the child process will have been
  746. Xredirected into the new socket retrieved by the accept(2) call.
  747. X.B verbose
  748. Xmeans that faucet will print information about each new connection.
  749. X
  750. X.LP
  751. XThis creates a UNIX domain socket in the current directory
  752. X.IP
  753. Xexample% faucet u-socket "dd if=angio.pgm" out err once
  754. X.LP
  755. XThe
  756. X.B out err
  757. Xoption means that stdout and stderr will be redirected in the child
  758. Xprocess.  The
  759. X.B once
  760. Xoption means that the faucet will not fork(2), but exec(2) the process
  761. Xso that only the first process can connect to the u-socket before the
  762. Xfaucet becomes unavailable.
  763. X
  764. X.SH "SEE ALSO"
  765. X.BR hose (1),
  766. X.BR socket (2),
  767. X.BR bind (2),
  768. X.BR listen (2),
  769. X.BR accept (2),
  770. X.BR services (5),
  771. X.BR gethostbyaddr (3)
  772. X
  773. X.SH "NOTES"
  774. X.LP
  775. XDoubtless there are bugs in this program, especially in the unix domain
  776. Xsocket portions.  I welcome problem reports and would like to make
  777. Xthese programs as "clean" (no leftover files, sockets) as possible.
  778. X
  779. X.SH "COPYRIGHT"
  780. XCopyright (C) 1992 Robert Forsman
  781. X
  782. XThis program is free software; you can redistribute it and/or modify
  783. Xit under the terms of the GNU General Public License as published by
  784. Xthe Free Software Foundation; either version 2 of the License, or
  785. X(at your option) any later version.
  786. X
  787. XThis program is distributed in the hope that it will be useful,
  788. Xbut WITHOUT ANY WARRANTY; without even the implied warranty of
  789. XMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  790. XGNU General Public License for more details.
  791. X
  792. XYou should have received a copy of the GNU General Public License
  793. Xalong with this program; if not, write to the Free Software
  794. XFoundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  795. X
  796. X.SH "AUTHOR"
  797. X Robert Forsman
  798. X thoth@lightning.cis.ufl.edu
  799. X University of Florida
  800. X Department of Computer and Information Science
  801. END_OF_FILE
  802. if test 4160 -ne `wc -c <'faucet.1'`; then
  803.     echo shar: \"'faucet.1'\" unpacked with wrong size!
  804. fi
  805. # end of 'faucet.1'
  806. fi
  807. if test -f 'faucet.c' -a "${1}" != "-c" ; then 
  808.   echo shar: Will not clobber existing file \"'faucet.c'\"
  809. else
  810. echo shar: Extracting \"'faucet.c'\" \(9476 characters\)
  811. sed "s/^X//" >'faucet.c' <<'END_OF_FILE'
  812. X/*
  813. X
  814. X    faucet.c, part of
  815. X    faucet and hose: network pipe utilities
  816. X    Copyright (C) 1992 Robert Forsman
  817. X
  818. X    This program is free software; you can redistribute it and/or modify
  819. X    it under the terms of the GNU General Public License as published by
  820. X    the Free Software Foundation; either version 2 of the License, or
  821. X    (at your option) any later version.
  822. X
  823. X    This program is distributed in the hope that it will be useful,
  824. X    but WITHOUT ANY WARRANTY; without even the implied warranty of
  825. X    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  826. X    GNU General Public License for more details.
  827. X
  828. X    You should have received a copy of the GNU General Public License
  829. X    along with this program; if not, write to the Free Software
  830. X    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  831. X
  832. X    */
  833. X
  834. Xstatic char info[] = "faucet: a network utility for sockets\nWritten 1992 by Robert Forsman <thoth@ufl.edu>\n";
  835. X#include    <stdio.h>
  836. X#include    <fcntl.h>
  837. X#include    <errno.h>
  838. X#ifdef hpux
  839. X#include    <signal.h>
  840. X#include    <sgtty.h>
  841. X#endif
  842. X#include    <sys/wait.h>
  843. X#include    <sys/param.h>
  844. X#include    <sys/file.h>
  845. X#include    <sys/ioctl.h>
  846. X#include    <sys/socket.h>
  847. X#include    <sys/un.h>
  848. X#include    <netinet/in.h>
  849. X#include    <netdb.h>
  850. X
  851. Xint    mastersocket;
  852. X#define    DOSTDOUT    (1<<0)
  853. X#define    DOSTDIN        (1<<1)
  854. X#define    DOSTDERR    (1<<2)
  855. X#define    DOONCE        (1<<3)
  856. X#define    DOVERBOSE    (1<<4)
  857. X#define    DOUNIX        (1<<5)
  858. Xlong    doflags=0;
  859. Xint    running=1;
  860. X
  861. Xchar    *foreignhost=NULL,*foreignport=NULL;
  862. Xint    foreignPORT;
  863. Xstruct in_addr    foreignHOST;
  864. X
  865. Xchar    *programname;
  866. Xextern int errno;
  867. Xextern char *sys_errlist[];
  868. X
  869. X
  870. Xint name_to_inet_port();
  871. X
  872. Xvoid nice_shutdown()
  873. X/* This procedure gets called when we are killed with one of the reasonable
  874. X   signals (TERM, HUP, that kind of thing).  The main while loop then
  875. X   terminates and we get a chance to clean up. */
  876. X{
  877. X  running = 0;
  878. X}
  879. X
  880. X
  881. X/* print an internet host address prettily */
  882. Xprinthost(addr)
  883. X     struct in_addr    *addr;
  884. X{
  885. X  struct hostent    *h;
  886. X  char    *s,**p;
  887. X  int    i;
  888. X
  889. X  h = gethostbyaddr(addr, sizeof(*addr),AF_INET);
  890. X  s = (h==NULL) ? NULL : h->h_name;
  891. X
  892. X  printf("%d", ((u_char*)addr)[0]);
  893. X  for (i=1; i<sizeof(*addr); i++)
  894. X    printf(".%d",((u_char*)addr)[i]);
  895. X
  896. X  printf("(%s",s?s:"name unknown");
  897. X  if (s)
  898. X    for (p=h->h_aliases; *p; p++)
  899. X      printf(",%s",*p);
  900. X  printf(")");
  901. X}
  902. X
  903. Xint setup_socket(name)
  904. Xchar *name;
  905. X/* This procedure creates a socket and handles retries on the inet domain.
  906. X   Sockets seem to "stick" on my system (SunOS [43].x) */
  907. X{
  908. X  int    sock;
  909. X
  910. X  sock = socket((doflags&DOUNIX)?AF_UNIX:AF_INET, SOCK_STREAM, 0);
  911. X  /* I need a real value for the protocol eventually.  IPPROTO_TCP sounds
  912. X     like a good value, but what about AF_UNIX sockets?  It seems to have
  913. X     worked so far... */
  914. X
  915. X  if (sock <0) {
  916. X      perror("opening stream socket");
  917. X      exit(1);
  918. X    }
  919. X
  920. X  if (!bindlocal(sock, name, (doflags&DOUNIX)?AF_UNIX:AF_INET)) {
  921. X      fprintf(stderr,"%s: error binding stream socket %s (%s)",
  922. X          programname,name,sys_errlist[errno]);
  923. X      exit(1);
  924. X    }
  925. X
  926. X  listen(sock,NOFILE);
  927. X
  928. X  return(sock);
  929. X}
  930. X
  931. X
  932. Xvoid waitonchild()
  933. X
  934. X{
  935. X  union wait status;
  936. X#if 0
  937. X  unsigned char    reason,signal,rval;
  938. X  char    buf[32];
  939. X#endif
  940. X  int    childpid;
  941. X  
  942. X  childpid = wait3(&status,WNOHANG,NULL);
  943. X  /* What a pity I can't easily print out child statuses */
  944. X#if 0
  945. X  if (childpid==-1) {
  946. X    fputs(stderr,programname);
  947. X    fputs(stderr,": error in wait3 while handling SIGCHLD (");
  948. X    fputs(stderr,sys_errlist[errno]);
  949. X    fputs(stderr,")\n");
  950. X    return;
  951. X  }
  952. X  reason = status.w_status & 0xff;
  953. X  if (reason==0) {
  954. X    rval = reason >> 8;
  955. X    if (rval!=0) {
  956. X      fputs(stderr,programname);
  957. X      fputs(stderr,": Child ");
  958. X      sprintf(buf,"%d",childpid);    fputs(stderr,buf);
  959. X      fputs(stderr," gave abnormal exit code ");
  960. X      sprintf(buf,"%d",rval);    fputs(stderr,buf);
  961. X      fputs(stderr,"\n");
  962. X    }
  963. X  } else if (reason!=0177) {
  964. X    signal = reason & 0x7f;
  965. X    fputs(stderr,programname);
  966. X    fputs(stderr,": Child ");
  967. X    sprintf(buf,"%d",childpid);    fputs(stderr,buf);
  968. X    fputs(stderr," killed by signal ");
  969. X    sprintf(buf,"%d",signal);        fputs(stderr,buf);
  970. X    fputs(stderr," (");
  971. X    fputs(stderr,(signal<=SIGUSR2)?signames[signal]:"bogus signal number");
  972. X    fputs(stderr,")\n");
  973. X  }
  974. X#endif
  975. X}
  976. X
  977. X
  978. Xint
  979. Xauthorize_address(sin)
  980. X     struct sockaddr    *sin;
  981. X{
  982. X  if (doflags&DOUNIX) {
  983. X    struct sockaddr_un     *srv = (struct sockaddr_un*)sin;
  984. X    
  985. X    if (foreignport != NULL && 0!=strcmp(foreignport, srv->sun_path)) {
  986. X      if (doflags&DOVERBOSE) {
  987. X    printf("%s: refusing connection from port %s\n",
  988. X           programname, srv->sun_path);
  989. X      }
  990. X      return 0;
  991. X    }
  992. X  } else {
  993. X    struct sockaddr_in    *srv = (struct sockaddr_in*)sin;
  994. X    
  995. X    if (foreignhost!=NULL &&
  996. X    0!=bcmp(&srv->sin_addr,
  997. X        &foreignHOST, sizeof(foreignHOST))) {
  998. X      if (doflags&DOVERBOSE) {
  999. X    printf("refusing connection from host ");
  1000. X    printhost(&srv->sin_addr);
  1001. X    printf(".\n");
  1002. X      }
  1003. X      return 0;
  1004. X    }
  1005. X    
  1006. X    if (foreignport!=NULL && foreignPORT != srv->sin_port) {
  1007. X      if (doflags&DOVERBOSE) {
  1008. X    printf("refusing connection from port %d.\n",
  1009. X           ntohs(srv->sin_port));
  1010. X      }
  1011. X      return 0;
  1012. X    }
  1013. X  }
  1014. X  
  1015. X  return 1;
  1016. X}
  1017. X
  1018. X
  1019. Xmain (argc,argv)
  1020. Xint argc;
  1021. Xchar ** argv;
  1022. X
  1023. X{
  1024. X  int    rval,length;
  1025. X  struct sockaddr    saddr;
  1026. X  struct sockaddr_in    *sinp = (struct sockaddr_in*)&saddr;
  1027. X  struct sockaddr_un    *sunp = (struct sockaddr_un*)&saddr;
  1028. X  
  1029. X  programname = argv[0];
  1030. X  
  1031. X  if (argc<3) {
  1032. X    fprintf(stderr,"Usage : %s <port> <command> (in|out|err)+ [once] [verb(|ose)] [quiet] [unix] [foreignport <port>] [foreignhost <host>]\n", programname);
  1033. X    exit(1);
  1034. X  }
  1035. X  
  1036. X  /* parse trailing args */
  1037. X  for (length=3; length<argc; length++) {
  1038. X    if (strcmp(argv[length],"in")==0)
  1039. X      doflags |= DOSTDIN;
  1040. X    else if (strcmp(argv[length],"out")==0)
  1041. X      doflags |= DOSTDOUT;
  1042. X    else if (strcmp(argv[length],"err")==0)
  1043. X      doflags |= DOSTDERR;
  1044. X    else if (strcmp(argv[length],"once")==0)
  1045. X      doflags |= DOONCE;
  1046. X    else if (strcmp(argv[length],"verbose")==0
  1047. X         || strcmp(argv[length],"verb")==0)
  1048. X      doflags |= DOVERBOSE;
  1049. X    else if (strcmp(argv[length],"quiet")==0)
  1050. X      doflags &= ~DOVERBOSE;
  1051. X    else if (strcmp(argv[length],"unix")==0)
  1052. X      doflags |= DOUNIX;
  1053. X    else if (strcmp(argv[length],"foreignport")==0) {
  1054. X      if (length+1<argc)
  1055. X    foreignport=argv[++length];
  1056. X      else
  1057. X    fprintf(stderr,"%s: foreignport requires port name or number.\n",
  1058. X        programname);
  1059. X    } else if (strcmp(argv[length],"foreignhost")==0) {
  1060. X      if (length+1<argc)
  1061. X    foreignhost=argv[++length];
  1062. X      else
  1063. X    fprintf(stderr,"%s: foreignhost requires host name or number.\n",
  1064. X        programname);
  1065. X    } else
  1066. X      fprintf(stderr,"%s: Bogus extra command line flag \"%s\".\n",
  1067. X          programname,argv[length]);
  1068. X  }
  1069. X  
  1070. X  if ( ! (doflags&(DOSTDIN|DOSTDERR|DOSTDOUT)) ) {
  1071. X    fprintf(stderr,"%s: Need at least one {in|out|err}.\n",programname);
  1072. X    exit(1);
  1073. X  }
  1074. X  
  1075. X  if ( (doflags&DOUNIX) && foreignhost!=NULL ) {
  1076. X    fprintf(stderr, "%s: foreignhost parameter makes no sense with UNIX domain sockets, ignoring.\n", programname);
  1077. X    foreignhost = NULL;
  1078. X  }
  1079. X  
  1080. X  signal(SIGCHLD,waitonchild);
  1081. X  
  1082. X  mastersocket = setup_socket(argv[1]);
  1083. X  
  1084. X  signal(SIGHUP, nice_shutdown);
  1085. X  signal(SIGINT, nice_shutdown);
  1086. X  signal(SIGPIPE, nice_shutdown);
  1087. X  signal(SIGALRM, nice_shutdown);
  1088. X  signal(SIGTERM, nice_shutdown);
  1089. X  
  1090. X  if (foreignhost != NULL && !convert_hostname(foreignhost, &foreignHOST)) {
  1091. X    fprintf(stderr, "%s: could not translate %s to a host address\n",
  1092. X        programname, foreignhost);
  1093. X    exit(1);
  1094. X  }
  1095. X  
  1096. X  if (foreignport!=NULL && !(doflags&DOUNIX) &&
  1097. X      0 == (foreignPORT = name_to_inet_port(foreignport)) ) {
  1098. X    fprintf(stderr,"%s: port %s unknown.\n",programname,foreignport);
  1099. X    exit(1);
  1100. X  }
  1101. X  
  1102. X  while (running) {
  1103. X    
  1104. X    length = sizeof(saddr);
  1105. X    
  1106. X    rval = accept(mastersocket,&saddr,&length);
  1107. X    
  1108. X    if (rval<0) {
  1109. X      if (errno==EWOULDBLOCK) {
  1110. X    printf("%s: No more connections to talk to.\n",programname);
  1111. X      } else if (errno!=EINTR) {
  1112. X    fprintf(stderr,"%s: error in accept (%s).",
  1113. X        programname,sys_errlist[errno]);
  1114. X    exit(1);
  1115. X      }
  1116. X      continue;
  1117. X    }
  1118. X    
  1119. X    if (!authorize_address(&saddr)) {
  1120. X      close(rval);
  1121. X      continue;
  1122. X    }
  1123. X    
  1124. X    if ( doflags&DOVERBOSE ) {
  1125. X      printf("%s: Got connection from ",programname);
  1126. X      if ( doflags&DOUNIX ) {
  1127. X    printf("%s\n", sunp->sun_path);
  1128. X      } else {
  1129. X    printhost(&sinp->sin_addr);
  1130. X    printf(" port %d\n",ntohs(sinp->sin_port));
  1131. X      }
  1132. X    }
  1133. X    
  1134. X    fflush(stdout);
  1135. X    
  1136. X    if ( doflags&DOONCE || fork()==0 ) {
  1137. X      /* child process: frob descriptors and exec */
  1138. X      char    *s;
  1139. X      
  1140. X      if ( (doflags&(DOONCE|DOUNIX)) == (DOONCE|DOUNIX) )
  1141. X    unlink(argv[1]);
  1142. X      /* We don't want the unix domain socket anymore */
  1143. X      
  1144. X      dup2(fileno(stderr),mastersocket);
  1145. X      ioctl(mastersocket,FIOCLEX,NULL);
  1146. X      /* We don't need old stderr hanging around after an exec.
  1147. X     The mastersocket has been closed by the dup2 */
  1148. X      
  1149. X      if (doflags & DOSTDIN)
  1150. X    dup2(rval,fileno(stdin));
  1151. X      if (doflags & DOSTDOUT)
  1152. X    dup2(rval,fileno(stdout));
  1153. X      if (doflags & DOSTDERR)
  1154. X    dup2(rval,fileno(stderr));
  1155. X      
  1156. X      close(rval); /* rval has been properly duplicated */
  1157. X      
  1158. X      execl("/bin/csh","csh","-c",argv[2],NULL);
  1159. X      s ="exec failed\n";
  1160. X      write(mastersocket,s,strlen(s));
  1161. X      exit(0);
  1162. X    } else {
  1163. X      /* parent: close socket.
  1164. X     Signal will arrive upon death of child. */
  1165. X      close(rval);
  1166. X    }
  1167. X  }
  1168. X  
  1169. X  /* clean up the socket when we're done */
  1170. X  if (doflags&DOUNIX)
  1171. X    unlink(argv[1]);
  1172. X  close(mastersocket);
  1173. X  
  1174. X}
  1175. END_OF_FILE
  1176. if test 9476 -ne `wc -c <'faucet.c'`; then
  1177.     echo shar: \"'faucet.c'\" unpacked with wrong size!
  1178. fi
  1179. # end of 'faucet.c'
  1180. fi
  1181. if test -f 'hose.1' -a "${1}" != "-c" ; then 
  1182.   echo shar: Will not clobber existing file \"'hose.1'\"
  1183. else
  1184. echo shar: Extracting \"'hose.1'\" \(3029 characters\)
  1185. sed "s/^X//" >'hose.1' <<'END_OF_FILE'
  1186. X.\" hose.1 Copyright 3/30/1992 by Robert Forsman
  1187. X.TH HOSE 1 "Mar 30 1992"
  1188. X.SH NAME
  1189. Xhose - the client end of a BSD network pipe
  1190. X.SH SYNOPSIS
  1191. X\fBhose\fP \fIhostname\fP \fIport\fP \fIcommand\fP
  1192. X(\fBin\fP|\fBout\fP|\fBerr\fP) [\fBunix\fP] [\fBlocalport\fP \fIport\fP]
  1193. X
  1194. X.SH DESCRIPTION
  1195. X.LP
  1196. X.B hose
  1197. Xattempts to provide the functionality of pipes over the network.
  1198. XIt behaves as the client end of a server\-client connection.
  1199. XWhen used with
  1200. X.B faucet(1)
  1201. Xit can function as a replacement for
  1202. X.IP
  1203. Xtar \-cf \- . | rsh other "cd destdir; tar -xf -"
  1204. X.LP
  1205. X.B faucet
  1206. Xand
  1207. X.B hose
  1208. Xare especially useful when you don't have easy access to the
  1209. Xdestination machine.
  1210. X
  1211. X.LP
  1212. X.B hose
  1213. Xcreates a BSD socket and, if the
  1214. X.B localport
  1215. Xoption is used, binds it to the port number (or service name)
  1216. Xspecified immediately afterwards.
  1217. X.B hose
  1218. Xthen tries to connect to the foreign machine
  1219. X.I hostname
  1220. Xwith foreign port
  1221. X.I port
  1222. X .  If successful
  1223. X.B hose
  1224. Xredirects stdin, stdout, and/or stderr
  1225. Xaccording to the
  1226. X.B in out err
  1227. Xflags.
  1228. X.B hose
  1229. Xthen exec(2)s a csh -f "\fIcommand\fP".
  1230. XThe
  1231. X.B unix
  1232. Xflag specifies that the
  1233. X.I port
  1234. Xis not an internet port number or service name, but instead it is a
  1235. Xfilename for a UNIX domain socket.  This option may be simulated by
  1236. Xusing 
  1237. X.B -unix-
  1238. Xas the host name to connect to, or by renaming the
  1239. X.B hose
  1240. Xprogram to \fBuhose\fP.
  1241. X
  1242. X.SH "EXAMPLES"
  1243. X.LP
  1244. XThis will connect to port 3000 on the machine reef and connect the socket
  1245. Xto the stdin of a tar command.
  1246. X.IP
  1247. Xexample% hose reef 3000 "tar -xf - ." in
  1248. X.LP
  1249. XThe command actually exec(2)ed by the
  1250. X.B hose
  1251. Xprogram is
  1252. X.IP
  1253. X/bin/csh -c "tar -xf - ."
  1254. X.LP
  1255. XThe
  1256. X.B in
  1257. Xoption means that the input of the child process will have been
  1258. Xredirected into the socket connected to reef.
  1259. X
  1260. X.LP
  1261. XThis connects to a UNIX domain socket in the current directory
  1262. X.IP
  1263. Xexample% hose u-socket "dd of=sample.pgm" in
  1264. X.LP
  1265. X
  1266. X.SH "SEE ALSO"
  1267. X.BR faucet (1),
  1268. X.BR socket (2),
  1269. X.BR bind (2),
  1270. X.BR listen (2),
  1271. X.BR accept (2),
  1272. X.BR services (5),
  1273. X.BR gethostbyaddr (3)
  1274. X
  1275. X.SH "NOTES"
  1276. X.LP
  1277. XDoubtless there are bugs in this program, especially in the unix domain
  1278. Xsocket portions.  I welcome problem reports and would like to make
  1279. Xthese programs as "clean" (no leftover files, sockets) as possible.
  1280. X
  1281. X.SH "COPYRIGHT"
  1282. XCopyright (C) 1992 Robert Forsman
  1283. X
  1284. XThis program is free software; you can redistribute it and/or modify
  1285. Xit under the terms of the GNU General Public License as published by
  1286. Xthe Free Software Foundation; either version 2 of the License, or
  1287. X(at your option) any later version.
  1288. X
  1289. XThis program is distributed in the hope that it will be useful,
  1290. Xbut WITHOUT ANY WARRANTY; without even the implied warranty of
  1291. XMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  1292. XGNU General Public License for more details.
  1293. X
  1294. XYou should have received a copy of the GNU General Public License
  1295. Xalong with this program; if not, write to the Free Software
  1296. XFoundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  1297. X
  1298. X.SH "AUTHOR"
  1299. X Robert Forsman
  1300. X thoth@lightning.cis.ufl.edu
  1301. X University of Florida
  1302. X Department of Computer and Information Science
  1303. END_OF_FILE
  1304. if test 3029 -ne `wc -c <'hose.1'`; then
  1305.     echo shar: \"'hose.1'\" unpacked with wrong size!
  1306. fi
  1307. # end of 'hose.1'
  1308. fi
  1309. if test -f 'hose.c' -a "${1}" != "-c" ; then 
  1310.   echo shar: Will not clobber existing file \"'hose.c'\"
  1311. else
  1312. echo shar: Extracting \"'hose.c'\" \(5611 characters\)
  1313. sed "s/^X//" >'hose.c' <<'END_OF_FILE'
  1314. X/*
  1315. X
  1316. X    hose.c, part of
  1317. X    faucet and hose: network pipe utilities
  1318. X    Copyright (C) 1992 Robert Forsman
  1319. X
  1320. X    This program is free software; you can redistribute it and/or modify
  1321. X    it under the terms of the GNU General Public License as published by
  1322. X    the Free Software Foundation; either version 2 of the License, or
  1323. X    (at your option) any later version.
  1324. X
  1325. X    This program is distributed in the hope that it will be useful,
  1326. X    but WITHOUT ANY WARRANTY; without even the implied warranty of
  1327. X    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  1328. X    GNU General Public License for more details.
  1329. X
  1330. X    You should have received a copy of the GNU General Public License
  1331. X    along with this program; if not, write to the Free Software
  1332. X    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  1333. X
  1334. X    */
  1335. X
  1336. Xstatic char info[] = "hose: a network utility for sockets\nWritten 1992 by Robert Forsman <thoth@ufl.edu>\n";
  1337. X#include    <stdio.h>
  1338. X#include    <fcntl.h>
  1339. X#ifdef hpux
  1340. X#include    <sgtty.h>
  1341. X#endif
  1342. X#include    <signal.h>
  1343. X#include    <sys/errno.h>
  1344. X#include    <sys/param.h>
  1345. X#include    <sys/file.h>
  1346. X#include    <sys/ioctl.h>
  1347. X#include    <sys/socket.h>
  1348. X#include    <sys/un.h>
  1349. X#include    <netinet/in.h>
  1350. X#include    <netdb.h>
  1351. X
  1352. X#define    DOSTDOUT    (1<<0)
  1353. X#define    DOSTDIN        (1<<1)
  1354. X#define    DOSTDERR    (1<<2)
  1355. X#define    DOUNIX        (1<<3)
  1356. X#define    DOJAM        (1<<4)
  1357. Xint    doflags=0;
  1358. Xchar    *localport=NULL;
  1359. Xchar    *programname;
  1360. Xextern int    errno;
  1361. Xextern char *sys_errlist[];
  1362. X
  1363. X
  1364. Xint name_to_inet_port();
  1365. X
  1366. X
  1367. Xint setup_socket(hostname,portname)
  1368. Xchar    *hostname;
  1369. Xchar    *portname;
  1370. X
  1371. X{
  1372. X  int    sock;
  1373. X  struct sockaddr    server;
  1374. X  int length;
  1375. X  
  1376. X  sock = socket((doflags&DOUNIX)?AF_UNIX:AF_INET, SOCK_STREAM, 0);
  1377. X  if (sock <0) {
  1378. X    perror("opening stream socket");
  1379. X    exit(1);
  1380. X  }
  1381. X  
  1382. X  length = sizeof(server);
  1383. X  
  1384. X  if (localport != NULL &&
  1385. X      !bindlocal(sock, localport, (doflags&DOUNIX)?AF_UNIX:AF_INET) ) {
  1386. X    fprintf(stderr,"%s: error binding stream socket %s (%s)",
  1387. X        programname,localport,sys_errlist[errno]);
  1388. X    exit(1);
  1389. X  }
  1390. X  
  1391. X  if (doflags&DOUNIX) {
  1392. X    /* ignore the hostname parameter */
  1393. X    ((struct sockaddr_un*)&server)->sun_family = AF_UNIX;
  1394. X    strcpy( ((struct sockaddr_un*)&server)->sun_path, portname);
  1395. X  } else {
  1396. X    struct sockaddr_in *svr=(struct sockaddr_in *)&server;
  1397. X    
  1398. X    ((struct sockaddr_in*)&server)->sin_family = AF_INET;
  1399. X    
  1400. X    if (!convert_hostname(hostname, &svr->sin_addr)) {
  1401. X      fprintf(stderr, "%s: could not translate %s to a host address\n",
  1402. X          programname, hostname);
  1403. X      exit(1);
  1404. X    }
  1405. X    
  1406. X    svr->sin_port = name_to_inet_port(portname);
  1407. X    if (svr->sin_port==0) {
  1408. X      fprintf(stderr,"%s: bogus port number %s\n",programname,portname);
  1409. X      exit(1);
  1410. X    }
  1411. X  }
  1412. X  
  1413. X  if (connect(sock,(struct sockaddr*)&server,sizeof(server)) < 0) {
  1414. X    perror("connecting");
  1415. X    exit(1);
  1416. X  }
  1417. X  
  1418. X  return(sock);
  1419. X}
  1420. X
  1421. X
  1422. Xvoid endjam()
  1423. X{
  1424. X  doflags &= ~DOJAM;
  1425. X}
  1426. X
  1427. X
  1428. Xmain (argc,argv)
  1429. X     int argc;
  1430. X     char ** argv;
  1431. X     
  1432. X{
  1433. X  int    rval,length;
  1434. X  int    jampipe[2];
  1435. X  
  1436. X  programname=argv[0];
  1437. X  
  1438. X  if (argc<4) {
  1439. X    fprintf(stderr,"Usage : %s <hostname> <port> <command> (in|out|err)+ [unix] [localport <port>]}\n",programname);
  1440. X    exit(1);
  1441. X  }
  1442. X  if (strcmp(argv[1],"-unix-")==0 || strcmp(programname,"uhose")==0 )
  1443. X    doflags |= DOUNIX;
  1444. X  for (length=4; length<argc; length++) {
  1445. X    if (strcmp(argv[length],"in")==0)
  1446. X      doflags |= DOSTDIN;
  1447. X    else if (strcmp(argv[length],"out")==0)
  1448. X      doflags |= DOSTDOUT;
  1449. X    else if (strcmp(argv[length],"err")==0)
  1450. X      doflags |= DOSTDERR;
  1451. X    else if (strcmp(argv[length],"unix")==0)
  1452. X      doflags |= DOUNIX;
  1453. X    else if (strcmp(argv[length],"jam")==0)
  1454. X      doflags |= DOJAM;
  1455. X    else if (strcmp(argv[length],"localport")==0) {
  1456. X      if (length+1<argc)
  1457. X    localport=argv[++length];
  1458. X      else
  1459. X    fprintf(stderr,"%s: localport requires port name or number after.\n",
  1460. X        programname);
  1461. X    } else
  1462. X      fprintf(stderr,"%s: Bogus extra command line flag \"%s\".\n",
  1463. X          programname,argv[length]);
  1464. X  }
  1465. X  
  1466. X  if ( ! (doflags&(DOSTDIN|DOSTDERR|DOSTDOUT)) ) {
  1467. X    fprintf(stderr,"%s: Need at least one {in|out|err}.\n",programname);
  1468. X    exit(1);
  1469. X  }
  1470. X
  1471. X  /* this wierd setup is to flood a socket with connections */
  1472. X  if (doflags&DOJAM) {
  1473. X    signal(SIGCHLD, endjam);
  1474. X    if (0>pipe(jampipe)) {
  1475. X      perror("opening jampipe");
  1476. X      exit(1);
  1477. X    }
  1478. X  }
  1479. X
  1480. X  while ( (doflags & DOJAM) && fork() ) {
  1481. X    char    ch;
  1482. X    close (jampipe[1]);
  1483. X    while (1==read(jampipe[0], &ch, 1))
  1484. X      ;
  1485. X    close (jampipe[0]);
  1486. X    jampipe[0] = -1;
  1487. X    if (0>pipe(jampipe)) {
  1488. X      perror("opening jampipe");
  1489. X      exit(1);
  1490. X    }
  1491. X  }
  1492. X
  1493. X  if (doflags&DOJAM)
  1494. X    close (jampipe[0]);
  1495. X
  1496. X  rval = setup_socket(argv[1],argv[2]);
  1497. X  
  1498. X  if (doflags&DOUNIX && localport!=NULL)
  1499. X    unlink(localport);
  1500. X  
  1501. X#if 0
  1502. X  if (!fork()) {
  1503. X    int sparefd;
  1504. X    char *s;
  1505. X    
  1506. X    sparefd = dup(fileno(stderr));
  1507. X    ioctl(sparefd,FIOCLEX,NULL);
  1508. X    
  1509. X    if (!(doflags & DOSTDIN))
  1510. X      dup2(rval,fileno(stdin));
  1511. X    if (!(doflags & DOSTDOUT))
  1512. X      dup2(rval,fileno(stdin));
  1513. X    if (!(doflags & DOSTDERR))
  1514. X      dup2(rval,fileno(stderr));
  1515. X    close(rval);
  1516. X    
  1517. X    execl("/bin/cat",NULL);
  1518. X    s ="exec failed\n";
  1519. X    write(sparefd,s,strlen(s));
  1520. X    exit(1);
  1521. X  }
  1522. X#endif
  1523. X  {
  1524. X    int sparefd;
  1525. X    char *s;
  1526. X    
  1527. X    sparefd = dup(fileno(stderr));
  1528. X    ioctl(sparefd,FIOCLEX,NULL);
  1529. X    
  1530. X    if (doflags & DOSTDIN)
  1531. X      dup2(rval,fileno(stdin));
  1532. X    if (doflags & DOSTDOUT)
  1533. X      dup2(rval,fileno(stdout));
  1534. X    if (doflags & DOSTDERR)
  1535. X      dup2(rval,fileno(stderr));
  1536. X    close(rval);
  1537. X    
  1538. X    if (doflags&DOJAM)
  1539. X      close (jampipe[1]);
  1540. X
  1541. X    execl("/bin/csh","csh","-c",argv[3],NULL);
  1542. X    s ="exec failed\n";
  1543. X    write(sparefd,s,strlen(s));
  1544. X    exit(1);
  1545. X  }
  1546. X}
  1547. END_OF_FILE
  1548. if test 5611 -ne `wc -c <'hose.c'`; then
  1549.     echo shar: \"'hose.c'\" unpacked with wrong size!
  1550. fi
  1551. # end of 'hose.c'
  1552. fi
  1553. if test -f 'portname.c' -a "${1}" != "-c" ; then 
  1554.   echo shar: Will not clobber existing file \"'portname.c'\"
  1555. else
  1556. echo shar: Extracting \"'portname.c'\" \(2973 characters\)
  1557. sed "s/^X//" >'portname.c' <<'END_OF_FILE'
  1558. X/*
  1559. X
  1560. X    portname.c, part of
  1561. X    faucet and hose: network pipe utilities
  1562. X    Copyright (C) 1992 Robert Forsman
  1563. X
  1564. X    This program is free software; you can redistribute it and/or modify
  1565. X    it under the terms of the GNU General Public License as published by
  1566. X    the Free Software Foundation; either version 2 of the License, or
  1567. X    (at your option) any later version.
  1568. X
  1569. X    This program is distributed in the hope that it will be useful,
  1570. X    but WITHOUT ANY WARRANTY; without even the implied warranty of
  1571. X    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  1572. X    GNU General Public License for more details.
  1573. X
  1574. X    You should have received a copy of the GNU General Public License
  1575. X    along with this program; if not, write to the Free Software
  1576. X    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  1577. X
  1578. X    */
  1579. X
  1580. X#include    <stdio.h>
  1581. X#include    <fcntl.h>
  1582. X#include    <errno.h>
  1583. X#include    <sys/socket.h>
  1584. X#include    <sys/un.h>
  1585. X#include    <netdb.h>
  1586. X#include    <netinet/in.h>
  1587. X
  1588. Xint name_to_inet_port(portname)
  1589. Xchar *portname;
  1590. X/* This procedure converts a character string to a port number.  It looks
  1591. X   up the service by name and if there is none, then it converts the string
  1592. X   to a number with sscanf */
  1593. X{
  1594. X  struct servent    *p;
  1595. X
  1596. X  if (portname==NULL)
  1597. X    return 0;
  1598. X
  1599. X  p = getservbyname(portname,"tcp");
  1600. X  if (p!=NULL)
  1601. X    {
  1602. X      return p->s_port;
  1603. X    }
  1604. X  else
  1605. X    {
  1606. X      int    port;
  1607. X      if (sscanf(portname,"%i",&port)!=1)
  1608. X    {
  1609. X      return 0;
  1610. X    }
  1611. X      else
  1612. X    return htons(port);
  1613. X    }
  1614. X}
  1615. X
  1616. Xint
  1617. Xconvert_hostname(name, addr)
  1618. X     char    *name;
  1619. X     struct in_addr    *addr;
  1620. X{
  1621. X  struct hostent    *hp;
  1622. X  int        len;
  1623. X
  1624. X  hp = gethostbyname(name);
  1625. X  if (hp != NULL)
  1626. X    bcopy(hp->h_addr,addr,hp->h_length);
  1627. X  else
  1628. X    {
  1629. X      int    count;
  1630. X      unsigned int    a1,a2,a3,a4;
  1631. X      count = sscanf(name,"%i.%i.%i.%i%n", &a1, &a2, &a3, &a4, &len);
  1632. X      if (4!=count || 0!=name[len] )
  1633. X    return 0;
  1634. X      addr->S_un.S_un_b.s_b1 = a1;
  1635. X      addr->S_un.S_un_b.s_b2 = a2;
  1636. X      addr->S_un.S_un_b.s_b3 = a3;
  1637. X      addr->S_un.S_un_b.s_b4 = a4;
  1638. X    }
  1639. X  return 1;
  1640. X}
  1641. X
  1642. X
  1643. Xint
  1644. Xbindlocal(fd, name, domain)
  1645. X     int    fd, domain;
  1646. X     char    *name;
  1647. X{
  1648. X  struct sockaddr    laddr;
  1649. X  int    countdown;
  1650. X  int    rval;
  1651. X  
  1652. X  if (domain==AF_INET)
  1653. X    {
  1654. X      struct sockaddr_in    *srv = (struct sockaddr_in*)&laddr;
  1655. X      
  1656. X      srv->sin_family = AF_INET;
  1657. X      srv->sin_addr.s_addr = INADDR_ANY;
  1658. X      
  1659. X      srv->sin_port = name_to_inet_port(name);
  1660. X      
  1661. X      if (srv->sin_port==0)
  1662. X    {
  1663. X      fprintf(stderr, "port %s unknown\n", name);
  1664. X      return 0;
  1665. X    }
  1666. X    }
  1667. X  else
  1668. X    {
  1669. X      struct sockaddr_un    *srv = (struct sockaddr_un *)&laddr;
  1670. X      
  1671. X      srv->sun_family = AF_UNIX;
  1672. X      strcpy(srv->sun_path, name);
  1673. X    }
  1674. X  
  1675. X  countdown= (domain==AF_UNIX)?1:10;
  1676. X  do {
  1677. X    rval = bind(fd, &laddr, sizeof(laddr));
  1678. X    if (rval)
  1679. X      if (errno==EADDRINUSE && --countdown>0)
  1680. X    {
  1681. X      fprintf(stderr,"Address %s in use, sleeping 10.\n",
  1682. X          name);
  1683. X      sleep (10);
  1684. X      fprintf(stderr,"Trying again . . .\n");
  1685. X    }
  1686. X      else
  1687. X    return 0;
  1688. X  } while (rval);
  1689. X
  1690. X  return 1;
  1691. X}
  1692. END_OF_FILE
  1693. if test 2973 -ne `wc -c <'portname.c'`; then
  1694.     echo shar: \"'portname.c'\" unpacked with wrong size!
  1695. fi
  1696. # end of 'portname.c'
  1697. fi
  1698. echo shar: End of archive 1 \(of 1\).
  1699. cp /dev/null ark1isdone
  1700. MISSING=""
  1701. for I in 1 ; do
  1702.     if test ! -f ark${I}isdone ; then
  1703.     MISSING="${MISSING} ${I}"
  1704.     fi
  1705. done
  1706. if test "${MISSING}" = "" ; then
  1707.     echo You have the archive.
  1708.     rm -f ark[1-9]isdone
  1709. else
  1710.     echo You still need to unpack the following archives:
  1711.     echo "        " ${MISSING}
  1712. fi
  1713. ##  End of shell archive.
  1714. exit 0
  1715.