home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-01-29 | 55.8 KB | 1,699 lines |
- Newsgroups: comp.sources.unix
- From: thoth@raybans.cis.ufl.edu (Robert Forsman)
- Subject: v26i086: faucet - pipe-like functionality over TCP sockets, Part01/01
- Sender: unix-sources-moderator@pa.dec.com
- Approved: vixie@pa.dec.com
-
- Submitted-By: thoth@raybans.cis.ufl.edu (Robert Forsman)
- Posting-Number: Volume 26, Issue 86
- Archive-Name: faucet/part01
-
- This shar has the source for two utilities that give you the power of the
- "|" (pipe) over the network. I'd like to see these two programs become
- standard features on all machines with Berkeley stream sockets.
-
- You may be amused to know that the source code for these programs is smaller
- than the copyright terms. Pretty disgusting that it's so hard to give away
- free software :)
-
- And yes, I *DO* have man pages this time, but they could lose a few rough
- edges. I welcome comments on the documentation and the source code. If it
- doesn't make instantly on your machine, tell me why and I'll try to make it
- easier next time.
-
- thoth@raybans.cis.ufl.edu (Robert Forsman)
-
- #! /bin/sh
- # This is a shell archive. Remove anything before this line, then unpack
- # it by saving it into a file and typing "sh file". To overwrite existing
- # files, type "sh file -c". You can also feed this as standard input via
- # unshar, or by typing "sh <file", e.g.. If this archive is complete, you
- # will see the following message at the end:
- # "End of archive 1 (of 1)."
- # Contents: COPYING MANIFEST Makefile README faucet.1 faucet.c hose.1
- # hose.c portname.c
- # Wrapped by vixie@cognition.pa.dec.com on Sat Jan 30 16:56:52 1993
- PATH=/bin:/usr/bin:/usr/ucb ; export PATH
- if test -f 'COPYING' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'COPYING'\"
- else
- echo shar: Extracting \"'COPYING'\" \(17981 characters\)
- sed "s/^X//" >'COPYING' <<'END_OF_FILE'
- X GNU GENERAL PUBLIC LICENSE
- X Version 2, June 1991
- X
- X Copyright (C) 1989, 1991 Free Software Foundation, Inc.
- X 675 Mass Ave, Cambridge, MA 02139, USA
- X Everyone is permitted to copy and distribute verbatim copies
- X of this license document, but changing it is not allowed.
- X
- X Preamble
- X
- X The licenses for most software are designed to take away your
- freedom to share and change it. By contrast, the GNU General Public
- License is intended to guarantee your freedom to share and change free
- software--to make sure the software is free for all its users. This
- General Public License applies to most of the Free Software
- XFoundation's software and to any other program whose authors commit to
- using it. (Some other Free Software Foundation software is covered by
- he GNU Library General Public License instead.) You can apply it to
- your programs, too.
- X
- X When we speak of free software, we are referring to freedom, not
- price. Our General Public Licenses are designed to make sure that you
- have the freedom to distribute copies of free software (and charge for
- this service if you wish), that you receive source code or can get it
- if you want it, that you can change the software or use pieces of it
- in new free programs; and that you know you can do these things.
- X
- X To protect your rights, we need to make restrictions that forbid
- anyone to deny you these rights or to ask you to surrender the rights.
- These restrictions translate to certain responsibilities for you if you
- distribute copies of the software, or if you modify it.
- X
- X For example, if you distribute copies of such a program, whether
- gratis or for a fee, you must give the recipients all the rights that
- you have. You must make sure that they, too, receive or can get the
- source code. And you must show them these terms so they know their
- rights.
- X
- X We protect your rights with two steps: (1) copyright the software, and
- X(2) offer you this license which gives you legal permission to copy,
- distribute and/or modify the software.
- X
- X Also, for each author's protection and ours, we want to make certain
- that everyone understands that there is no warranty for this free
- software. If the software is modified by someone else and passed on, we
- want its recipients to know that what they have is not the original, so
- that any problems introduced by others will not reflect on the original
- authors' reputations.
- X
- X Finally, any free program is threatened constantly by software
- patents. We wish to avoid the danger that redistributors of a free
- program will individually obtain patent licenses, in effect making the
- program proprietary. To prevent this, we have made it clear that any
- patent must be licensed for everyone's free use or not licensed at all.
- X
- X The precise terms and conditions for copying, distribution and
- modification follow.
- X
- X GNU GENERAL PUBLIC LICENSE
- X TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
- X
- X 0. This License applies to any program or other work which contains
- a notice placed by the copyright holder saying it may be distributed
- under the terms of this General Public License. The "Program", below,
- refers to any such program or work, and a "work based on the Program"
- means either the Program or any derivative work under copyright law:
- that is to say, a work containing the Program or a portion of it,
- either verbatim or with modifications and/or translated into another
- language. (Hereinafter, translation is included without limitation in
- the term "modification".) Each licensee is addressed as "you".
- X
- Activities other than copying, distribution and modification are not
- covered by this License; they are outside its scope. The act of
- running the Program is not restricted, and the output from the Program
- is covered only if its contents constitute a work based on the
- Program (independent of having been made by running the Program).
- Whether that is true depends on what the Program does.
- X
- X 1. You may copy and distribute verbatim copies of the Program's
- source code as you receive it, in any medium, provided that you
- conspicuously and appropriately publish on each copy an appropriate
- copyright notice and disclaimer of warranty; keep intact all the
- notices that refer to this License and to the absence of any warranty;
- and give any other recipients of the Program a copy of this License
- along with the Program.
- X
- You may charge a fee for the physical act of transferring a copy, and
- you may at your option offer warranty protection in exchange for a fee.
- X
- X 2. You may modify your copy or copies of the Program or any portion
- of it, thus forming a work based on the Program, and copy and
- distribute such modifications or work under the terms of Section 1
- above, provided that you also meet all of these conditions:
- X
- X a) You must cause the modified files to carry prominent notices
- X stating that you changed the files and the date of any change.
- X
- X b) You must cause any work that you distribute or publish, that in
- X whole or in part contains or is derived from the Program or any
- X part thereof, to be licensed as a whole at no charge to all third
- X parties under the terms of this License.
- X
- X c) If the modified program normally reads commands interactively
- X when run, you must cause it, when started running for such
- X interactive use in the most ordinary way, to print or display an
- X announcement including an appropriate copyright notice and a
- X notice that there is no warranty (or else, saying that you provide
- X a warranty) and that users may redistribute the program under
- X these conditions, and telling the user how to view a copy of this
- X License. (Exception: if the Program itself is interactive but
- X does not normally print such an announcement, your work based on
- X the Program is not required to print an announcement.)
- X
- These requirements apply to the modified work as a whole. If
- identifiable sections of that work are not derived from the Program,
- and can be reasonably considered independent and separate works in
- themselves, then this License, and its terms, do not apply to those
- sections when you distribute them as separate works. But when you
- distribute the same sections as part of a whole which is a work based
- on the Program, the distribution of the whole must be on the terms of
- this License, whose permissions for other licensees extend to the
- entire whole, and thus to each and every part regardless of who wrote it.
- X
- Thus, it is not the intent of this section to claim rights or contest
- your rights to work written entirely by you; rather, the intent is to
- exercise the right to control the distribution of derivative or
- collective works based on the Program.
- X
- In addition, mere aggregation of another work not based on the Program
- with the Program (or with a work based on the Program) on a volume of
- a storage or distribution medium does not bring the other work under
- the scope of this License.
- X
- X 3. You may copy and distribute the Program (or a work based on it,
- under Section 2) in object code or executable form under the terms of
- Sections 1 and 2 above provided that you also do one of the following:
- X
- X a) Accompany it with the complete corresponding machine-readable
- X source code, which must be distributed under the terms of Sections
- X 1 and 2 above on a medium customarily used for software interchange; or,
- X
- X b) Accompany it with a written offer, valid for at least three
- X years, to give any third party, for a charge no more than your
- X cost of physically performing source distribution, a complete
- X machine-readable copy of the corresponding source code, to be
- X distributed under the terms of Sections 1 and 2 above on a medium
- X customarily used for software interchange; or,
- X
- X c) Accompany it with the information you received as to the offer
- X to distribute corresponding source code. (This alternative is
- X allowed only for noncommercial distribution and only if you
- X received the program in object code or executable form with such
- X an offer, in accord with Subsection b above.)
- X
- The source code for a work means the preferred form of the work for
- making modifications to it. For an executable work, complete source
- code means all the source code for all modules it contains, plus any
- associated interface definition files, plus the scripts used to
- control compilation and installation of the executable. However, as a
- special exception, the source code distributed need not include
- anything that is normally distributed (in either source or binary
- form) with the major components (compiler, kernel, and so on) of the
- operating system on which the executable runs, unless that component
- itself accompanies the executable.
- X
- If distribution of executable or object code is made by offering
- access to copy from a designated place, then offering equivalent
- access to copy the source code from the same place counts as
- distribution of the source code, even though third parties are not
- compelled to copy the source along with the object code.
- X
- X 4. You may not copy, modify, sublicense, or distribute the Program
- except as expressly provided under this License. Any attempt
- otherwise to copy, modify, sublicense or distribute the Program is
- void, and will automatically terminate your rights under this License.
- However, parties who have received copies, or rights, from you under
- this License will not have their licenses terminated so long as such
- parties remain in full compliance.
- X
- X 5. You are not required to accept this License, since you have not
- signed it. However, nothing else grants you permission to modify or
- distribute the Program or its derivative works. These actions are
- prohibited by law if you do not accept this License. Therefore, by
- modifying or distributing the Program (or any work based on the
- Program), you indicate your acceptance of this License to do so, and
- all its terms and conditions for copying, distributing or modifying
- the Program or works based on it.
- X
- X 6. Each time you redistribute the Program (or any work based on the
- Program), the recipient automatically receives a license from the
- original licensor to copy, distribute or modify the Program subject to
- these terms and conditions. You may not impose any further
- restrictions on the recipients' exercise of the rights granted herein.
- You are not responsible for enforcing compliance by third parties to
- this License.
- X
- X 7. If, as a consequence of a court judgment or allegation of patent
- infringement or for any other reason (not limited to patent issues),
- conditions are imposed on you (whether by court order, agreement or
- otherwise) that contradict the conditions of this License, they do not
- excuse you from the conditions of this License. If you cannot
- distribute so as to satisfy simultaneously your obligations under this
- License and any other pertinent obligations, then as a consequence you
- may not distribute the Program at all. For example, if a patent
- license would not permit royalty-free redistribution of the Program by
- all those who receive copies directly or indirectly through you, then
- the only way you could satisfy both it and this License would be to
- refrain entirely from distribution of the Program.
- X
- If any portion of this section is held invalid or unenforceable under
- any particular circumstance, the balance of the section is intended to
- apply and the section as a whole is intended to apply in other
- circumstances.
- X
- It is not the purpose of this section to induce you to infringe any
- patents or other property right claims or to contest validity of any
- such claims; this section has the sole purpose of protecting the
- integrity of the free software distribution system, which is
- implemented by public license practices. Many people have made
- generous contributions to the wide range of software distributed
- through that system in reliance on consistent application of that
- system; it is up to the author/donor to decide if he or she is willing
- to distribute software through any other system and a licensee cannot
- impose that choice.
- X
- This section is intended to make thoroughly clear what is believed to
- be a consequence of the rest of this License.
- X
- X 8. If the distribution and/or use of the Program is restricted in
- certain countries either by patents or by copyrighted interfaces, the
- original copyright holder who places the Program under this License
- may add an explicit geographical distribution limitation excluding
- those countries, so that distribution is permitted only in or among
- countries not thus excluded. In such case, this License incorporates
- the limitation as if written in the body of this License.
- X
- X 9. The Free Software Foundation may publish revised and/or new versions
- of the General Public License from time to time. Such new versions will
- be similar in spirit to the present version, but may differ in detail to
- address new problems or concerns.
- X
- XEach version is given a distinguishing version number. If the Program
- specifies a version number of this License which applies to it and "any
- later version", you have the option of following the terms and conditions
- either of that version or of any later version published by the Free
- Software Foundation. If the Program does not specify a version number of
- this License, you may choose any version ever published by the Free Software
- XFoundation.
- X
- X 10. If you wish to incorporate parts of the Program into other free
- programs whose distribution conditions are different, write to the author
- to ask for permission. For software which is copyrighted by the Free
- Software Foundation, write to the Free Software Foundation; we sometimes
- make exceptions for this. Our decision will be guided by the two goals
- of preserving the free status of all derivatives of our free software and
- of promoting the sharing and reuse of software generally.
- X
- X NO WARRANTY
- X
- X 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
- XFOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
- OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
- PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
- OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
- TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
- PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
- REPAIR OR CORRECTION.
- X
- X 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
- WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
- REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
- INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
- OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
- TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
- YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
- PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
- POSSIBILITY OF SUCH DAMAGES.
- X
- X END OF TERMS AND CONDITIONS
- X
- X Appendix: How to Apply These Terms to Your New Programs
- X
- X If you develop a new program, and you want it to be of the greatest
- possible use to the public, the best way to achieve this is to make it
- free software which everyone can redistribute and change under these terms.
- X
- X To do so, attach the following notices to the program. It is safest
- to attach them to the start of each source file to most effectively
- convey the exclusion of warranty; and each file should have at least
- the "copyright" line and a pointer to where the full notice is found.
- X
- X <one line to give the program's name and a brief idea of what it does.>
- X Copyright (C) 19yy <name of author>
- X
- X This program is free software; you can redistribute it and/or modify
- X it under the terms of the GNU General Public License as published by
- X the Free Software Foundation; either version 2 of the License, or
- X (at your option) any later version.
- X
- X This program is distributed in the hope that it will be useful,
- X but WITHOUT ANY WARRANTY; without even the implied warranty of
- X MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- X GNU General Public License for more details.
- X
- X You should have received a copy of the GNU General Public License
- X along with this program; if not, write to the Free Software
- X Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- X
- Also add information on how to contact you by electronic and paper mail.
- X
- If the program is interactive, make it output a short notice like this
- when it starts in an interactive mode:
- X
- X Gnomovision version 69, Copyright (C) 19yy name of author
- X Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
- X This is free software, and you are welcome to redistribute it
- X under certain conditions; type `show c' for details.
- X
- The hypothetical commands `show w' and `show c' should show the appropriate
- parts of the General Public License. Of course, the commands you use may
- be called something other than `show w' and `show c'; they could even be
- mouse-clicks or menu items--whatever suits your program.
- X
- You should also get your employer (if you work as a programmer) or your
- school, if any, to sign a "copyright disclaimer" for the program, if
- necessary. Here is a sample; alter the names:
- X
- X Yoyodyne, Inc., hereby disclaims all copyright interest in the program
- X `Gnomovision' (which makes passes at compilers) written by James Hacker.
- X
- X <signature of Ty Coon>, 1 April 1989
- X Ty Coon, President of Vice
- X
- This General Public License does not permit incorporating your program into
- proprietary programs. If your program is a subroutine library, you may
- consider it more useful to permit linking proprietary applications with the
- library. If this is what you want to do, use the GNU Library General
- Public License instead of this License.
- END_OF_FILE
- if test 17981 -ne `wc -c <'COPYING'`; then
- echo shar: \"'COPYING'\" unpacked with wrong size!
- fi
- # end of 'COPYING'
- fi
- if test -f 'MANIFEST' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'MANIFEST'\"
- else
- echo shar: Extracting \"'MANIFEST'\" \(393 characters\)
- sed "s/^X//" >'MANIFEST' <<'END_OF_FILE'
- X File Name Archive # Description
- X-----------------------------------------------------------
- X COPYING 1
- X MANIFEST 1 This shipping list
- X Makefile 1
- X README 1
- X faucet.1 1
- X faucet.c 1
- X hose.1 1
- X hose.c 1
- X portname.c 1
- END_OF_FILE
- if test 393 -ne `wc -c <'MANIFEST'`; then
- echo shar: \"'MANIFEST'\" unpacked with wrong size!
- fi
- # end of 'MANIFEST'
- fi
- if test -f 'Makefile' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'Makefile'\"
- else
- echo shar: Extracting \"'Makefile'\" \(1264 characters\)
- sed "s/^X//" >'Makefile' <<'END_OF_FILE'
- X# faucet and hose: network pipe utilities
- X# Copyright (C) 1992 Robert Forsman
- X#
- X# This program is free software; you can redistribute it and/or modify
- X# it under the terms of the GNU General Public License as published by
- X# the Free Software Foundation; either version 2 of the License, or
- X# (at your option) any later version.
- X#
- X# This program is distributed in the hope that it will be useful,
- X# but WITHOUT ANY WARRANTY; without even the implied warranty of
- X# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- X# GNU General Public License for more details.
- X#
- X# You should have received a copy of the GNU General Public License
- X# along with this program; if not, write to the Free Software
- X# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- X
- X#
- X# under HPUX you will probably have to make using LDLIBS=-lBSD
- X#
- X
- CFLAGS =
- X
- XFOBJS = faucet.o portname.o
- HOBJS = hose.o portname.o
- ALL = faucet hose
- X
- all : ${ALL}
- X
- faucet : ${FOBJS}
- X ${CC} ${CFLAGS} -o $@ ${FOBJS} ${LDLIBS}
- X
- hose : ${HOBJS}
- X ${CC} ${CFLAGS} -o $@ ${HOBJS} ${LDLIBS}
- X
- install : all
- X cp faucet hose ${HOME}/bin/`mach`
- X
- clean :
- X rm -f ${FOBJS} ${HOBJS} ${ALL}
- X rm -f *.o *~ *.CKP *.BAK core a.out
- X
- spotless: clean
- X rm -f *~ core hose faucet
- END_OF_FILE
- if test 1264 -ne `wc -c <'Makefile'`; then
- echo shar: \"'Makefile'\" unpacked with wrong size!
- fi
- # end of 'Makefile'
- fi
- if test -f 'README' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'README'\"
- else
- echo shar: Extracting \"'README'\" \(6764 characters\)
- sed "s/^X//" >'README' <<'END_OF_FILE'
- X
- X"Mutant" Bob Forsman and his amazing 43 burner stove present
- X------------------------------------------------------------
- X "stuff"
- X------------------------------------------------------------
- X
- X This directory contains faucet and hose.
- X
- X
- X
- faucet and hose:
- X
- X These two utilities are useful for connecting arbitrary programs
- over sockets. The power of the '|' characeter in the shell can now be
- used over the network.
- X As an example of what they can do, compile them and on one machine
- type
- X
- lightning:21 % ./faucet 3000 "tar cf - ." out
- X
- X and on another type
- X
- springs:3 % ./hose lightning 3000 "tar tvf -" in
- X
- X You will get output (from machine springs) that looks like this.
- X
- rwxr-xr-x771/50 0 Jul 7 11:53 1990 ./
- rw-r-----771/50 9266 Jun 30 21:41 1990 ./faucet.c~
- rw-r--r--771/50 6086 Mar 6 21:40 1990 ./server.cc
- rw-r--r--771/50 1203 Jul 7 11:49 1990 ./Makefile
- rw-r-----771/50 9757 Jul 7 11:49 1990 ./faucet.c
- rw-r--r--771/50 4241 Jun 23 04:09 1990 ./hose.c~
- rwxr-xr-x771/50 24576 Jul 7 11:50 1990 ./hose
- rw-r--r--771/50 4041 Jul 7 11:50 1990 ./hose.c
- rw-r-----771/50 592 Jul 7 11:48 1990 ./portname.c
- rw-r--r--771/50 317 Jul 7 11:48 1990 ./portname.o
- rwxr-xr-x771/50 24576 Jul 7 11:50 1990 ./faucet
- rw-r--r--771/50 3378 Jul 7 11:50 1990 ./hose.o
- rw-r--r--771/50 1069 Jun 23 02:42 1990 ./Makefile~
- rw-r--r--771/50 4662 Jul 7 11:50 1990 ./faucet.o
- rw-r-----771/50 377 Jul 7 11:53 1990 ./#README#
- rw-r-----771/50 371 Jul 7 11:53 1990 ./README
- rw-r--r--771/50 2917 Mar 6 22:13 1990 ./client.cc
- X
- X The 3000 is the port number to connect to. Normal users can use any
- number over 1023. You can also specify a service name in place of a
- number since the program can look it up from the services database.
- X The argument in ""s (argv[2] for faucet, argv[3] for hose) is the
- command to be connected to the socket. The flags in, out and err
- govorn which file descriptors get connected to the socket after the
- connection is successful.
- X hose is a one-shot program. It connects to the foreign server
- socket and execs the command. faucet is an undying server. Every
- time it recieves a connection on its socket it forks and execs a "csh
- X-c". faucet can be limited to one-shot by the "once" flag.
- X
- SYNTAX
- X
- X faucet <port> <command> (in|out|err)+ [once] [verb(|ose)] [quiet]
- X [unix] [foreignport <port>] [foreignhost <host>]
- X
- X hose <hostname> <port> <command> (in|out|err)+ [unix] [localport <port>]}
- X
- X Host names can be be the name of the machine or (if no name is
- found) the internet number. The individual numbers are sscanfed with
- X%i so 0x or 0 prefixes mean hex or octal instead of decimal for that
- one byte.
- X You must chose at least one of in, out, and err. The other flags
- are optional and listed below
- X unix.........causes the program to go into unix-domain socket mode.
- X hose can also be forced into unix-domain operation by
- X specifying -unix- as the hostname (those dashes are
- X part of the arg) or by being run with argv[0] as the
- X string "uhose" (possible by hardlinking the binary).
- X Port names are then treated as unix domain socket
- X addresses (filenames) as opposed to internet port
- X numbers.
- X localport....(only on hose) asks hose to bind to a specific local
- X port.
- X once.........(only on faucet) the faucet command will not fork, but
- X will exec the command, and when the command exits
- X you're done.
- X verbose|quiet (only on faucet) enables|disables the printing of
- X extra information such as what host and port faucet is
- X getting connections from.
- X foreignport..(only on faucet) causes faucet to refuse (close
- X immediately) any connection from a machine that hasn't
- X bound its socket to the port specified immediately
- X after the foreignport flag. This can be used with the
- X localport option of hose to perform crude
- X authentication. If the foreignport is <1024 then only
- X a foreign root user will be able to connect to your
- X faucet because only root can bind to a port number
- X below 1024.
- X foreignhost..(only on faucet) causes faucet to refuse (close
- X immediately) any connection from any machine other
- X than the host specified immediately after the
- X foreignhost flag.
- X
- X Be aware that addresses and ports can be spoofed if your network
- isn't secure (yours probably isn't). If you have PCs or other
- non-UNIX boxes connected to the network, then it's DISGUSTINGLY easy
- for ANYONE to spoof the network.
- X
- X
- X
- XEXAMPLES
- X
- X FAUCET HOSE
- X
- reef:100 % ./faucet chat "echo send
- X$14M and 2 airline stewardesses or
- you'll never see Hoffa alive"
- foreignhost azalea verbose out
- X
- X reef:40 % ./hose reef chat cat in
- X
- refusing connection from host 128.
- X227.224.61(reef.cis.ufl.edu).
- X
- X azalea:20 % ./hose reef chat cat in
- X
- X./faucet: Got connection from 128.
- X227.224.55(azalea.cis.ufl.edu) port
- X1687
- Unmatched '.
- X /* darn, screwed up the shell quoting */
- X^C
- X
- reef:107 % ./faucet /tmp/blah 'echo
- send '\'\$14M\'' and 2 airline
- stewardesses or you'\\\''ll never
- see Hoffa alive' foreignhost azalea
- verbose out foreignport /tmp/auth unix
- X./faucet: foreignhost parameter makes no
- sense with UNIX domain sockets, ignoring.
- X /* %#@)*, bite me */
- X
- X reef:41 % ./hose -unix- /tmp/blah cat in
- X
- X./faucet: refusing connection from port
- X
- X reef:43 % ./hose -unix- /tmp/blah cat in
- X localport /tmp/auth
- X
- X./faucet: Got connection from /tmp/auth
- X
- X send $14M and 2 airline stewardesses or
- X you'll never see Hoffa alive
- X
- X
- X Notice the elaborate quoting on that one. faucet+hose fork a "csh
- X-c " to interpret the command. The echo command had to be quoted so
- that faucet saw:
- X
- echo send '$14M' and 2 airline stewardesses or you\'ll never see Hoffa alive
- X
- X faucet then performed this system call
- X
- execl("/bin/csh","csh","-c",argv[2],NULL);
- X
- X and the "$14M" and "you'll" were properly quoted to survive THAT csh
- as well. Commands to hose must be similarly protected.
- X
- X Why use csh?
- X 1) This allows you to have pipelines and other fancy stuff inside
- X the command, and
- X 2) I don't have to write code to parse the command!
- X
- X
- X
- BUGS
- X
- X Hoohoohoo, god knows what sort of bugs are waiting to rip your
- ankles off. I'm the only one who's extensively used these. They were
- developed on Sun3s and Sun4s. They have been compiled (but not
- extensively tested) on Sonys, DECstations and HPs. If your machine
- needs different include files, start grepping and mail me the results.
- X
- X If anything is not crystal clear, check the source and mail me.
- I'll try to put it in the README.
- X
- X I need to dragoon someone into writing a man page for this.
- X
- X
- AUTHOR
- X
- X Robert H. Forsman Jr. <thoth@lightning.cis.ufl.edu>
- X former underpaid Systems Programmer
- X now piddly underpaid Research Assistant
- X University of Florida
- X Department of Computer
- X and Information Science
- END_OF_FILE
- if test 6764 -ne `wc -c <'README'`; then
- echo shar: \"'README'\" unpacked with wrong size!
- fi
- # end of 'README'
- fi
- if test -f 'faucet.1' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'faucet.1'\"
- else
- echo shar: Extracting \"'faucet.1'\" \(4160 characters\)
- sed "s/^X//" >'faucet.1' <<'END_OF_FILE'
- X.\" faucet.1 Copyright 3/30/1992 by Robert Forsman
- X.TH FAUCET 1 "Mar 30 1992"
- X.SH NAME
- faucet - a fixture for a BSD network pipe
- X.SH SYNOPSIS
- X\fBfaucet\fP \fIport\fP \fIcommand\fP (\fBin\fP|\fBout\fP|\fBerr\fP)
- X[\fBonce\fP] [\fBverbose\fP] [\fBquiet\fP] [\fBunix\fP]
- X[\fBforeignhost\fP \fIhost\fP] [\fBforeignport\fP \fIport\fP]
- X
- X.SH DESCRIPTION
- X.LP
- X.B faucet
- attempts to provide the functionality of pipes over the network.
- It behaves as the server end of a server\-client connection.
- When used with
- X.B hose(1)
- it can function as a replacement for
- X.IP
- tar \-cf \- . | rsh other "cd destdir; tar -xf -"
- X.LP
- X.B faucet
- and
- X.B hose
- are especially useful when you don't have easy access to the
- destination machine.
- X
- X.LP
- X.B faucet
- creates a BSD socket, binds it to the
- X.I port
- specified on the command line, and listens for connections.
- XEvery time
- X.B faucet
- gets a connection it forks the
- X.I command
- with stdin, stdout, and/or stderr redirected according to the
- X.B in out err
- flags. If the
- X.B once
- flag is specified,
- X.B faucet
- will exec(2) the
- X.I command
- instead of fork(2)ing and exec(2)ing.
- X.B once
- means that the network pipe
- is only good for one shot.
- The
- X.B verbose
- flag specifies that
- X.B faucet
- should print information about connecting hosts . This information
- includes the numeric host address, host names, and foreign port numbers.
- The
- X.B quiet
- flag specifies that
- X.B faucet
- should NOT print such info.
- X.B quiet
- is the default. The
- X.B unix
- flag specifies that the
- X.I port
- is not an internet port number or service name, but instead it is a
- filename for a UNIX domain socket. The
- X.B foreignhost
- option specifies that faucet should reject all connections that do not
- come from the
- X.I host
- machine. Similarly
- X.B foreignport
- specifies that faucet should reject all connections that are not bound
- on their local machine to the
- X.I port
- argument. The above two options allow a crude form of authentication.
- Note that on most systems only root can bind a socket to a port number
- below 1024.
- X
- X.SH "EXAMPLES"
- X.LP
- This creates a TCP\-IP socket on the local machine bound to port 3000.
- X.IP
- example% faucet 3000 "tar -cf - ." out verbose
- X.LP
- XEvery time some process (from any machine) attempts to connect to
- port 3000 on this machine the
- X.B faucet
- program will fork(2) a process and the child will exec(2) a
- X.IP
- X/bin/csh -c "tar -cf - ."
- X.LP
- The
- X.B out
- option means that the output of the child process will have been
- redirected into the new socket retrieved by the accept(2) call.
- X.B verbose
- means that faucet will print information about each new connection.
- X
- X.LP
- This creates a UNIX domain socket in the current directory
- X.IP
- example% faucet u-socket "dd if=angio.pgm" out err once
- X.LP
- The
- X.B out err
- option means that stdout and stderr will be redirected in the child
- process. The
- X.B once
- option means that the faucet will not fork(2), but exec(2) the process
- so that only the first process can connect to the u-socket before the
- faucet becomes unavailable.
- X
- X.SH "SEE ALSO"
- X.BR hose (1),
- X.BR socket (2),
- X.BR bind (2),
- X.BR listen (2),
- X.BR accept (2),
- X.BR services (5),
- X.BR gethostbyaddr (3)
- X
- X.SH "NOTES"
- X.LP
- Doubtless there are bugs in this program, especially in the unix domain
- socket portions. I welcome problem reports and would like to make
- these programs as "clean" (no leftover files, sockets) as possible.
- X
- X.SH "COPYRIGHT"
- Copyright (C) 1992 Robert Forsman
- X
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- X(at your option) any later version.
- X
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- X
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- XFoundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- X
- X.SH "AUTHOR"
- X Robert Forsman
- X thoth@lightning.cis.ufl.edu
- X University of Florida
- X Department of Computer and Information Science
- END_OF_FILE
- if test 4160 -ne `wc -c <'faucet.1'`; then
- echo shar: \"'faucet.1'\" unpacked with wrong size!
- fi
- # end of 'faucet.1'
- fi
- if test -f 'faucet.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'faucet.c'\"
- else
- echo shar: Extracting \"'faucet.c'\" \(9476 characters\)
- sed "s/^X//" >'faucet.c' <<'END_OF_FILE'
- X/*
- X
- X faucet.c, part of
- X faucet and hose: network pipe utilities
- X Copyright (C) 1992 Robert Forsman
- X
- X This program is free software; you can redistribute it and/or modify
- X it under the terms of the GNU General Public License as published by
- X the Free Software Foundation; either version 2 of the License, or
- X (at your option) any later version.
- X
- X This program is distributed in the hope that it will be useful,
- X but WITHOUT ANY WARRANTY; without even the implied warranty of
- X MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- X GNU General Public License for more details.
- X
- X You should have received a copy of the GNU General Public License
- X along with this program; if not, write to the Free Software
- X Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- X
- X */
- X
- static char info[] = "faucet: a network utility for sockets\nWritten 1992 by Robert Forsman <thoth@ufl.edu>\n";
- X#include <stdio.h>
- X#include <fcntl.h>
- X#include <errno.h>
- X#ifdef hpux
- X#include <signal.h>
- X#include <sgtty.h>
- X#endif
- X#include <sys/wait.h>
- X#include <sys/param.h>
- X#include <sys/file.h>
- X#include <sys/ioctl.h>
- X#include <sys/socket.h>
- X#include <sys/un.h>
- X#include <netinet/in.h>
- X#include <netdb.h>
- X
- int mastersocket;
- X#define DOSTDOUT (1<<0)
- X#define DOSTDIN (1<<1)
- X#define DOSTDERR (1<<2)
- X#define DOONCE (1<<3)
- X#define DOVERBOSE (1<<4)
- X#define DOUNIX (1<<5)
- long doflags=0;
- int running=1;
- X
- char *foreignhost=NULL,*foreignport=NULL;
- int foreignPORT;
- struct in_addr foreignHOST;
- X
- char *programname;
- extern int errno;
- extern char *sys_errlist[];
- X
- X
- int name_to_inet_port();
- X
- void nice_shutdown()
- X/* This procedure gets called when we are killed with one of the reasonable
- X signals (TERM, HUP, that kind of thing). The main while loop then
- X terminates and we get a chance to clean up. */
- X{
- X running = 0;
- X}
- X
- X
- X/* print an internet host address prettily */
- printhost(addr)
- X struct in_addr *addr;
- X{
- X struct hostent *h;
- X char *s,**p;
- X int i;
- X
- X h = gethostbyaddr(addr, sizeof(*addr),AF_INET);
- X s = (h==NULL) ? NULL : h->h_name;
- X
- X printf("%d", ((u_char*)addr)[0]);
- X for (i=1; i<sizeof(*addr); i++)
- X printf(".%d",((u_char*)addr)[i]);
- X
- X printf("(%s",s?s:"name unknown");
- X if (s)
- X for (p=h->h_aliases; *p; p++)
- X printf(",%s",*p);
- X printf(")");
- X}
- X
- int setup_socket(name)
- char *name;
- X/* This procedure creates a socket and handles retries on the inet domain.
- X Sockets seem to "stick" on my system (SunOS [43].x) */
- X{
- X int sock;
- X
- X sock = socket((doflags&DOUNIX)?AF_UNIX:AF_INET, SOCK_STREAM, 0);
- X /* I need a real value for the protocol eventually. IPPROTO_TCP sounds
- X like a good value, but what about AF_UNIX sockets? It seems to have
- X worked so far... */
- X
- X if (sock <0) {
- X perror("opening stream socket");
- X exit(1);
- X }
- X
- X if (!bindlocal(sock, name, (doflags&DOUNIX)?AF_UNIX:AF_INET)) {
- X fprintf(stderr,"%s: error binding stream socket %s (%s)",
- X programname,name,sys_errlist[errno]);
- X exit(1);
- X }
- X
- X listen(sock,NOFILE);
- X
- X return(sock);
- X}
- X
- X
- void waitonchild()
- X
- X{
- X union wait status;
- X#if 0
- X unsigned char reason,signal,rval;
- X char buf[32];
- X#endif
- X int childpid;
- X
- X childpid = wait3(&status,WNOHANG,NULL);
- X /* What a pity I can't easily print out child statuses */
- X#if 0
- X if (childpid==-1) {
- X fputs(stderr,programname);
- X fputs(stderr,": error in wait3 while handling SIGCHLD (");
- X fputs(stderr,sys_errlist[errno]);
- X fputs(stderr,")\n");
- X return;
- X }
- X reason = status.w_status & 0xff;
- X if (reason==0) {
- X rval = reason >> 8;
- X if (rval!=0) {
- X fputs(stderr,programname);
- X fputs(stderr,": Child ");
- X sprintf(buf,"%d",childpid); fputs(stderr,buf);
- X fputs(stderr," gave abnormal exit code ");
- X sprintf(buf,"%d",rval); fputs(stderr,buf);
- X fputs(stderr,"\n");
- X }
- X } else if (reason!=0177) {
- X signal = reason & 0x7f;
- X fputs(stderr,programname);
- X fputs(stderr,": Child ");
- X sprintf(buf,"%d",childpid); fputs(stderr,buf);
- X fputs(stderr," killed by signal ");
- X sprintf(buf,"%d",signal); fputs(stderr,buf);
- X fputs(stderr," (");
- X fputs(stderr,(signal<=SIGUSR2)?signames[signal]:"bogus signal number");
- X fputs(stderr,")\n");
- X }
- X#endif
- X}
- X
- X
- int
- authorize_address(sin)
- X struct sockaddr *sin;
- X{
- X if (doflags&DOUNIX) {
- X struct sockaddr_un *srv = (struct sockaddr_un*)sin;
- X
- X if (foreignport != NULL && 0!=strcmp(foreignport, srv->sun_path)) {
- X if (doflags&DOVERBOSE) {
- X printf("%s: refusing connection from port %s\n",
- X programname, srv->sun_path);
- X }
- X return 0;
- X }
- X } else {
- X struct sockaddr_in *srv = (struct sockaddr_in*)sin;
- X
- X if (foreignhost!=NULL &&
- X 0!=bcmp(&srv->sin_addr,
- X &foreignHOST, sizeof(foreignHOST))) {
- X if (doflags&DOVERBOSE) {
- X printf("refusing connection from host ");
- X printhost(&srv->sin_addr);
- X printf(".\n");
- X }
- X return 0;
- X }
- X
- X if (foreignport!=NULL && foreignPORT != srv->sin_port) {
- X if (doflags&DOVERBOSE) {
- X printf("refusing connection from port %d.\n",
- X ntohs(srv->sin_port));
- X }
- X return 0;
- X }
- X }
- X
- X return 1;
- X}
- X
- X
- main (argc,argv)
- int argc;
- char ** argv;
- X
- X{
- X int rval,length;
- X struct sockaddr saddr;
- X struct sockaddr_in *sinp = (struct sockaddr_in*)&saddr;
- X struct sockaddr_un *sunp = (struct sockaddr_un*)&saddr;
- X
- X programname = argv[0];
- X
- X if (argc<3) {
- X fprintf(stderr,"Usage : %s <port> <command> (in|out|err)+ [once] [verb(|ose)] [quiet] [unix] [foreignport <port>] [foreignhost <host>]\n", programname);
- X exit(1);
- X }
- X
- X /* parse trailing args */
- X for (length=3; length<argc; length++) {
- X if (strcmp(argv[length],"in")==0)
- X doflags |= DOSTDIN;
- X else if (strcmp(argv[length],"out")==0)
- X doflags |= DOSTDOUT;
- X else if (strcmp(argv[length],"err")==0)
- X doflags |= DOSTDERR;
- X else if (strcmp(argv[length],"once")==0)
- X doflags |= DOONCE;
- X else if (strcmp(argv[length],"verbose")==0
- X || strcmp(argv[length],"verb")==0)
- X doflags |= DOVERBOSE;
- X else if (strcmp(argv[length],"quiet")==0)
- X doflags &= ~DOVERBOSE;
- X else if (strcmp(argv[length],"unix")==0)
- X doflags |= DOUNIX;
- X else if (strcmp(argv[length],"foreignport")==0) {
- X if (length+1<argc)
- X foreignport=argv[++length];
- X else
- X fprintf(stderr,"%s: foreignport requires port name or number.\n",
- X programname);
- X } else if (strcmp(argv[length],"foreignhost")==0) {
- X if (length+1<argc)
- X foreignhost=argv[++length];
- X else
- X fprintf(stderr,"%s: foreignhost requires host name or number.\n",
- X programname);
- X } else
- X fprintf(stderr,"%s: Bogus extra command line flag \"%s\".\n",
- X programname,argv[length]);
- X }
- X
- X if ( ! (doflags&(DOSTDIN|DOSTDERR|DOSTDOUT)) ) {
- X fprintf(stderr,"%s: Need at least one {in|out|err}.\n",programname);
- X exit(1);
- X }
- X
- X if ( (doflags&DOUNIX) && foreignhost!=NULL ) {
- X fprintf(stderr, "%s: foreignhost parameter makes no sense with UNIX domain sockets, ignoring.\n", programname);
- X foreignhost = NULL;
- X }
- X
- X signal(SIGCHLD,waitonchild);
- X
- X mastersocket = setup_socket(argv[1]);
- X
- X signal(SIGHUP, nice_shutdown);
- X signal(SIGINT, nice_shutdown);
- X signal(SIGPIPE, nice_shutdown);
- X signal(SIGALRM, nice_shutdown);
- X signal(SIGTERM, nice_shutdown);
- X
- X if (foreignhost != NULL && !convert_hostname(foreignhost, &foreignHOST)) {
- X fprintf(stderr, "%s: could not translate %s to a host address\n",
- X programname, foreignhost);
- X exit(1);
- X }
- X
- X if (foreignport!=NULL && !(doflags&DOUNIX) &&
- X 0 == (foreignPORT = name_to_inet_port(foreignport)) ) {
- X fprintf(stderr,"%s: port %s unknown.\n",programname,foreignport);
- X exit(1);
- X }
- X
- X while (running) {
- X
- X length = sizeof(saddr);
- X
- X rval = accept(mastersocket,&saddr,&length);
- X
- X if (rval<0) {
- X if (errno==EWOULDBLOCK) {
- X printf("%s: No more connections to talk to.\n",programname);
- X } else if (errno!=EINTR) {
- X fprintf(stderr,"%s: error in accept (%s).",
- X programname,sys_errlist[errno]);
- X exit(1);
- X }
- X continue;
- X }
- X
- X if (!authorize_address(&saddr)) {
- X close(rval);
- X continue;
- X }
- X
- X if ( doflags&DOVERBOSE ) {
- X printf("%s: Got connection from ",programname);
- X if ( doflags&DOUNIX ) {
- X printf("%s\n", sunp->sun_path);
- X } else {
- X printhost(&sinp->sin_addr);
- X printf(" port %d\n",ntohs(sinp->sin_port));
- X }
- X }
- X
- X fflush(stdout);
- X
- X if ( doflags&DOONCE || fork()==0 ) {
- X /* child process: frob descriptors and exec */
- X char *s;
- X
- X if ( (doflags&(DOONCE|DOUNIX)) == (DOONCE|DOUNIX) )
- X unlink(argv[1]);
- X /* We don't want the unix domain socket anymore */
- X
- X dup2(fileno(stderr),mastersocket);
- X ioctl(mastersocket,FIOCLEX,NULL);
- X /* We don't need old stderr hanging around after an exec.
- X The mastersocket has been closed by the dup2 */
- X
- X if (doflags & DOSTDIN)
- X dup2(rval,fileno(stdin));
- X if (doflags & DOSTDOUT)
- X dup2(rval,fileno(stdout));
- X if (doflags & DOSTDERR)
- X dup2(rval,fileno(stderr));
- X
- X close(rval); /* rval has been properly duplicated */
- X
- X execl("/bin/csh","csh","-c",argv[2],NULL);
- X s ="exec failed\n";
- X write(mastersocket,s,strlen(s));
- X exit(0);
- X } else {
- X /* parent: close socket.
- X Signal will arrive upon death of child. */
- X close(rval);
- X }
- X }
- X
- X /* clean up the socket when we're done */
- X if (doflags&DOUNIX)
- X unlink(argv[1]);
- X close(mastersocket);
- X
- X}
- END_OF_FILE
- if test 9476 -ne `wc -c <'faucet.c'`; then
- echo shar: \"'faucet.c'\" unpacked with wrong size!
- fi
- # end of 'faucet.c'
- fi
- if test -f 'hose.1' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'hose.1'\"
- else
- echo shar: Extracting \"'hose.1'\" \(3029 characters\)
- sed "s/^X//" >'hose.1' <<'END_OF_FILE'
- X.\" hose.1 Copyright 3/30/1992 by Robert Forsman
- X.TH HOSE 1 "Mar 30 1992"
- X.SH NAME
- hose - the client end of a BSD network pipe
- X.SH SYNOPSIS
- X\fBhose\fP \fIhostname\fP \fIport\fP \fIcommand\fP
- X(\fBin\fP|\fBout\fP|\fBerr\fP) [\fBunix\fP] [\fBlocalport\fP \fIport\fP]
- X
- X.SH DESCRIPTION
- X.LP
- X.B hose
- attempts to provide the functionality of pipes over the network.
- It behaves as the client end of a server\-client connection.
- When used with
- X.B faucet(1)
- it can function as a replacement for
- X.IP
- tar \-cf \- . | rsh other "cd destdir; tar -xf -"
- X.LP
- X.B faucet
- and
- X.B hose
- are especially useful when you don't have easy access to the
- destination machine.
- X
- X.LP
- X.B hose
- creates a BSD socket and, if the
- X.B localport
- option is used, binds it to the port number (or service name)
- specified immediately afterwards.
- X.B hose
- then tries to connect to the foreign machine
- X.I hostname
- with foreign port
- X.I port
- X . If successful
- X.B hose
- redirects stdin, stdout, and/or stderr
- according to the
- X.B in out err
- flags.
- X.B hose
- then exec(2)s a csh -f "\fIcommand\fP".
- The
- X.B unix
- flag specifies that the
- X.I port
- is not an internet port number or service name, but instead it is a
- filename for a UNIX domain socket. This option may be simulated by
- using
- X.B -unix-
- as the host name to connect to, or by renaming the
- X.B hose
- program to \fBuhose\fP.
- X
- X.SH "EXAMPLES"
- X.LP
- This will connect to port 3000 on the machine reef and connect the socket
- to the stdin of a tar command.
- X.IP
- example% hose reef 3000 "tar -xf - ." in
- X.LP
- The command actually exec(2)ed by the
- X.B hose
- program is
- X.IP
- X/bin/csh -c "tar -xf - ."
- X.LP
- The
- X.B in
- option means that the input of the child process will have been
- redirected into the socket connected to reef.
- X
- X.LP
- This connects to a UNIX domain socket in the current directory
- X.IP
- example% hose u-socket "dd of=sample.pgm" in
- X.LP
- X
- X.SH "SEE ALSO"
- X.BR faucet (1),
- X.BR socket (2),
- X.BR bind (2),
- X.BR listen (2),
- X.BR accept (2),
- X.BR services (5),
- X.BR gethostbyaddr (3)
- X
- X.SH "NOTES"
- X.LP
- Doubtless there are bugs in this program, especially in the unix domain
- socket portions. I welcome problem reports and would like to make
- these programs as "clean" (no leftover files, sockets) as possible.
- X
- X.SH "COPYRIGHT"
- Copyright (C) 1992 Robert Forsman
- X
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- X(at your option) any later version.
- X
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- X
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- XFoundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- X
- X.SH "AUTHOR"
- X Robert Forsman
- X thoth@lightning.cis.ufl.edu
- X University of Florida
- X Department of Computer and Information Science
- END_OF_FILE
- if test 3029 -ne `wc -c <'hose.1'`; then
- echo shar: \"'hose.1'\" unpacked with wrong size!
- fi
- # end of 'hose.1'
- fi
- if test -f 'hose.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'hose.c'\"
- else
- echo shar: Extracting \"'hose.c'\" \(4891 characters\)
- sed "s/^X//" >'hose.c' <<'END_OF_FILE'
- X/*
- X
- X hose.c, part of
- X faucet and hose: network pipe utilities
- X Copyright (C) 1992 Robert Forsman
- X
- X This program is free software; you can redistribute it and/or modify
- X it under the terms of the GNU General Public License as published by
- X the Free Software Foundation; either version 2 of the License, or
- X (at your option) any later version.
- X
- X This program is distributed in the hope that it will be useful,
- X but WITHOUT ANY WARRANTY; without even the implied warranty of
- X MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- X GNU General Public License for more details.
- X
- X You should have received a copy of the GNU General Public License
- X along with this program; if not, write to the Free Software
- X Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- X
- X */
- X
- static char info[] = "hose: a network utility for sockets\nWritten 1992 by Robert Forsman <thoth@ufl.edu>\n";
- X#include <stdio.h>
- X#include <fcntl.h>
- X#ifdef hpux
- X#include <sgtty.h>
- X#endif
- X#include <sys/errno.h>
- X#include <sys/param.h>
- X#include <sys/file.h>
- X#include <sys/ioctl.h>
- X#include <sys/socket.h>
- X#include <sys/un.h>
- X#include <netinet/in.h>
- X#include <netdb.h>
- X
- X#define DOSTDOUT (1<<0)
- X#define DOSTDIN (1<<1)
- X#define DOSTDERR (1<<2)
- X#define DOUNIX (1<<3)
- int doflags=0;
- char *localport=NULL;
- char *programname;
- extern int errno;
- extern char *sys_errlist[];
- X
- X
- int name_to_inet_port();
- X
- X
- int setup_socket(hostname,portname)
- char *hostname;
- char *portname;
- X
- X{
- X int sock;
- X struct sockaddr server;
- X int length;
- X
- X sock = socket((doflags&DOUNIX)?AF_UNIX:AF_INET, SOCK_STREAM, 0);
- X if (sock <0) {
- X perror("opening stream socket");
- X exit(1);
- X }
- X
- X length = sizeof(server);
- X
- X if (localport != NULL &&
- X !bindlocal(sock, localport, (doflags&DOUNIX)?AF_UNIX:AF_INET) ) {
- X fprintf(stderr,"%s: error binding stream socket %s (%s)",
- X programname,localport,sys_errlist[errno]);
- X exit(1);
- X }
- X
- X if (doflags&DOUNIX) {
- X /* ignore the hostname parameter */
- X ((struct sockaddr_un*)&server)->sun_family = AF_UNIX;
- X strcpy( ((struct sockaddr_un*)&server)->sun_path, portname);
- X } else {
- X struct sockaddr_in *svr=(struct sockaddr_in *)&server;
- X
- X ((struct sockaddr_in*)&server)->sin_family = AF_INET;
- X
- X if (!convert_hostname(hostname, &svr->sin_addr)) {
- X fprintf(stderr, "%s: could not translate %s to a host address\n",
- X programname, hostname);
- X exit(1);
- X }
- X
- X svr->sin_port = name_to_inet_port(portname);
- X if (svr->sin_port==0) {
- X fprintf(stderr,"%s: bogus port number %s\n",programname,portname);
- X exit(1);
- X }
- X }
- X
- X if (connect(sock,(struct sockaddr*)&server,sizeof(server)) < 0) {
- X perror("connecting");
- X exit(1);
- X }
- X
- X return(sock);
- X}
- X
- X
- X
- X
- main (argc,argv)
- X int argc;
- X char ** argv;
- X
- X{
- X int rval,length;
- X
- X programname=argv[0];
- X
- X if (argc<4) {
- X fprintf(stderr,"Usage : %s <hostname> <port> <command> (in|out|err)+ [unix] [localport <port>]}\n",programname);
- X exit(1);
- X }
- X if (strcmp(argv[1],"-unix-")==0 || strcmp(programname,"uhose")==0 )
- X doflags |= DOUNIX;
- X for (length=4; length<argc; length++) {
- X if (strcmp(argv[length],"in")==0)
- X doflags |= DOSTDIN;
- X else if (strcmp(argv[length],"out")==0)
- X doflags |= DOSTDOUT;
- X else if (strcmp(argv[length],"err")==0)
- X doflags |= DOSTDERR;
- X else if (strcmp(argv[length],"unix")==0)
- X doflags |= DOUNIX;
- X else if (strcmp(argv[length],"localport")==0) {
- X if (length+1<argc)
- X localport=argv[++length];
- X else
- X fprintf(stderr,"%s: localport requires port name or number after.\n",
- X programname);
- X } else
- X fprintf(stderr,"%s: Bogus extra command line flag \"%s\".\n",
- X programname,argv[length]);
- X }
- X
- X if ( ! (doflags&(DOSTDIN|DOSTDERR|DOSTDOUT)) ) {
- X fprintf(stderr,"%s: Need at least one {in|out|err}.\n",programname);
- X exit(1);
- X }
- X
- X rval = setup_socket(argv[1],argv[2]);
- X
- X if (doflags&DOUNIX && localport!=NULL)
- X unlink(localport);
- X
- X#if 0
- X if (!fork()) {
- X int sparefd;
- X char *s;
- X
- X sparefd = dup(fileno(stderr));
- X ioctl(sparefd,FIOCLEX,NULL);
- X
- X if (!(doflags & DOSTDIN))
- X dup2(rval,fileno(stdin));
- X if (!(doflags & DOSTDOUT))
- X dup2(rval,fileno(stdin));
- X if (!(doflags & DOSTDERR))
- X dup2(rval,fileno(stderr));
- X close(rval);
- X
- X execl("/bin/cat",NULL);
- X s ="exec failed\n";
- X write(sparefd,s,strlen(s));
- X exit(1);
- X }
- X#endif
- X {
- X int sparefd;
- X char *s;
- X
- X sparefd = dup(fileno(stderr));
- X ioctl(sparefd,FIOCLEX,NULL);
- X
- X if (doflags & DOSTDIN)
- X dup2(rval,fileno(stdin));
- X if (doflags & DOSTDOUT)
- X dup2(rval,fileno(stdout));
- X if (doflags & DOSTDERR)
- X dup2(rval,fileno(stderr));
- X close(rval);
- X
- X execl("/bin/csh","csh","-c",argv[3],NULL);
- X s ="exec failed\n";
- X write(sparefd,s,strlen(s));
- X exit(1);
- X }
- X}
- END_OF_FILE
- if test 4891 -ne `wc -c <'hose.c'`; then
- echo shar: \"'hose.c'\" unpacked with wrong size!
- fi
- # end of 'hose.c'
- fi
- if test -f 'portname.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'portname.c'\"
- else
- echo shar: Extracting \"'portname.c'\" \(2973 characters\)
- sed "s/^X//" >'portname.c' <<'END_OF_FILE'
- X/*
- X
- X portname.c, part of
- X faucet and hose: network pipe utilities
- X Copyright (C) 1992 Robert Forsman
- X
- X This program is free software; you can redistribute it and/or modify
- X it under the terms of the GNU General Public License as published by
- X the Free Software Foundation; either version 2 of the License, or
- X (at your option) any later version.
- X
- X This program is distributed in the hope that it will be useful,
- X but WITHOUT ANY WARRANTY; without even the implied warranty of
- X MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- X GNU General Public License for more details.
- X
- X You should have received a copy of the GNU General Public License
- X along with this program; if not, write to the Free Software
- X Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- X
- X */
- X
- X#include <stdio.h>
- X#include <fcntl.h>
- X#include <errno.h>
- X#include <sys/socket.h>
- X#include <sys/un.h>
- X#include <netdb.h>
- X#include <netinet/in.h>
- X
- int name_to_inet_port(portname)
- char *portname;
- X/* This procedure converts a character string to a port number. It looks
- X up the service by name and if there is none, then it converts the string
- X to a number with sscanf */
- X{
- X struct servent *p;
- X
- X if (portname==NULL)
- X return 0;
- X
- X p = getservbyname(portname,"tcp");
- X if (p!=NULL)
- X {
- X return p->s_port;
- X }
- X else
- X {
- X int port;
- X if (sscanf(portname,"%i",&port)!=1)
- X {
- X return 0;
- X }
- X else
- X return htons(port);
- X }
- X}
- X
- int
- convert_hostname(name, addr)
- X char *name;
- X struct in_addr *addr;
- X{
- X struct hostent *hp;
- X int len;
- X
- X hp = gethostbyname(name);
- X if (hp != NULL)
- X bcopy(hp->h_addr,addr,hp->h_length);
- X else
- X {
- X int count;
- X unsigned int a1,a2,a3,a4;
- X count = sscanf(name,"%i.%i.%i.%i%n", &a1, &a2, &a3, &a4, &len);
- X if (4!=count || 0!=name[len] )
- X return 0;
- X addr->S_un.S_un_b.s_b1 = a1;
- X addr->S_un.S_un_b.s_b2 = a2;
- X addr->S_un.S_un_b.s_b3 = a3;
- X addr->S_un.S_un_b.s_b4 = a4;
- X }
- X return 1;
- X}
- X
- X
- int
- bindlocal(fd, name, domain)
- X int fd, domain;
- X char *name;
- X{
- X struct sockaddr laddr;
- X int countdown;
- X int rval;
- X
- X if (domain==AF_INET)
- X {
- X struct sockaddr_in *srv = (struct sockaddr_in*)&laddr;
- X
- X srv->sin_family = AF_INET;
- X srv->sin_addr.s_addr = INADDR_ANY;
- X
- X srv->sin_port = name_to_inet_port(name);
- X
- X if (srv->sin_port==0)
- X {
- X fprintf(stderr, "port %s unknown\n", name);
- X return 0;
- X }
- X }
- X else
- X {
- X struct sockaddr_un *srv = (struct sockaddr_un *)&laddr;
- X
- X srv->sun_family = AF_UNIX;
- X strcpy(srv->sun_path, name);
- X }
- X
- X countdown= (domain==AF_UNIX)?1:10;
- X do {
- X rval = bind(fd, &laddr, sizeof(laddr));
- X if (rval)
- X if (errno==EADDRINUSE && --countdown>0)
- X {
- X fprintf(stderr,"Address %s in use, sleeping 10.\n",
- X name);
- X sleep (10);
- X fprintf(stderr,"Trying again . . .\n");
- X }
- X else
- X return 0;
- X } while (rval);
- X
- X return 1;
- X}
- END_OF_FILE
- if test 2973 -ne `wc -c <'portname.c'`; then
- echo shar: \"'portname.c'\" unpacked with wrong size!
- fi
- # end of 'portname.c'
- fi
- echo shar: End of archive 1 \(of 1\).
- cp /dev/null ark1isdone
- MISSING=""
- for I in 1 ; do
- if test ! -f ark${I}isdone ; then
- MISSING="${MISSING} ${I}"
- fi
- done
- if test "${MISSING}" = "" ; then
- echo You have the archive.
- rm -f ark[1-9]isdone
- else
- echo You still need to unpack the following archives:
- echo " " ${MISSING}
- fi
- ## End of shell archive.
- exit 0
-