From owner-freebsd-questions@FreeBSD.ORG Fri Nov 7 13:03:42 2003 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 7CD3616A4CE for ; Fri, 7 Nov 2003 13:03:42 -0800 (PST) Received: from catseye.mine.nu (d154-5-164-0.bchsia.telus.net [154.5.164.0]) by mx1.FreeBSD.org (Postfix) with SMTP id A81B143FE1 for ; Fri, 7 Nov 2003 13:03:41 -0800 (PST) (envelope-from catseye@catseye.mine.nu) Received: (qmail 73747 invoked by uid 1001); 7 Nov 2003 21:06:15 -0000 Date: Fri, 7 Nov 2003 13:06:15 -0800 From: Chris Pressey To: Charles Swiger Message-Id: <20031107130615.1824d783.cpressey@catseye.mine.nu> In-Reply-To: References: <20031107091909.6d2a0acc.cpressey@catseye.mine.nu> Organization: Cat's Eye Technologies X-Mailer: Sylpheed version 0.9.7 (GTK+ 1.2.10; i386-portbld-freebsd4.9) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit cc: freebsd-questions@freebsd.org Subject: Re: [OT?] Tying a socket to stdin/stdout w/dup2() ? X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 07 Nov 2003 21:03:42 -0000 On Fri, 7 Nov 2003 12:35:55 -0500 Charles Swiger wrote: > On Nov 7, 2003, at 12:19 PM, Chris Pressey wrote: > > I've got a C program that opens a TCP/IP socket and makes a client > > connection. What I'd like to do is to 'tie' the socket to this > > program's standard I/O, so that anything that is fed into this > > program's > > stdin, is immediately sent to the socket, and anything that appears > > on the socket, is immediately sent out this program's stdout. (The > > end effect being a sort of pathologically simple version of what > > telnet,(or inetd or ucspi-tcp) does.) > > Take a look at netcat, from /usr/ports/net/netcat. Ahh great, now I'm blind! :) Seriously - it seems to confirm that I was confused. Looks like you can either: a) dup the socket to stdin/out, then exec a program (a la inetd); or b) keep stdin/out and the socket, and multiplex between them (telnet). Since I want my program to act as a pipe source/sink, rather than exec-ing something else, I'll have to go with b), which means I'll have to face the select(2) music. Anyway, thanks for the pointer... -Chris