home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / unix / volume26 / netpipes / part01 < prev    next >
Encoding:
Text File  |  1992-09-07  |  56.0 KB  |  1,709 lines

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