From owner-freebsd-questions@FreeBSD.ORG Fri Nov 7 09:16:31 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 C7B8116A4CE for ; Fri, 7 Nov 2003 09:16:31 -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 0DEB64401E for ; Fri, 7 Nov 2003 09:16:31 -0800 (PST) (envelope-from catseye@catseye.mine.nu) Received: (qmail 71057 invoked by uid 1001); 7 Nov 2003 17:19:09 -0000 Date: Fri, 7 Nov 2003 09:19:09 -0800 From: Chris Pressey To: FreeBSD-Questions Message-Id: <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 Subject: [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 17:16:31 -0000 Hi all, Sorry if this question is a little off topic since it's not strongly FreeBSD-specific. 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.) Trying to figure this out using Google, the best lead I got was to try something like this: fclose(stdin); fclose(stdout); dup2(sd, 0); dup2(sd, 1); But it doesn't seem to do much good. (At best, I think this means the program can communicate with the socket as if it were stdio - but from the program user's point of view, stdio disappears completely.) I'd rather not resort to getting my hands dirty with select(2), but I guess if there's really no other way, I'll have to. TIA, -Chris