home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!ukma!darwin.sura.net!sgiblab!munnari.oz.au!yoyo.aarnet.edu.au!news.adelaide.edu.au!andrewr
- From: andrewr@iagu.itd.adelaide.edu.au (Andrew Rutherford)
- Newsgroups: comp.unix.ultrix
- Subject: Re: Sockets on a 5000/120
- Date: 17 Nov 1992 02:40:04 GMT
- Organization: The University of Adelaide
- Lines: 39
- Distribution: world
- Message-ID: <1e9m24INNpde@huon.itd.adelaide.edu.au>
- References: <1du2lrINNiue@iraul1.ira.uka.de>
- NNTP-Posting-Host: iagu.itd.adelaide.edu.au
- X-Newsreader: TIN [version 1.1 PL6]
-
- Juan Uriarte (s_uriart@irau35.ira.uka.de) wrote:
- + stdin and stdout,so it just wont work.And now i just did something
- + like: fd=dup(socket); myfile=fopen(fd,"r+'); and then a dup2 .
- + But as usual the dup2 wont work,giving me the habitual errno 9.
-
- OK, try this for starters: dup returns the number of the file
- descriptor (type int) while the f*() calls want something pointing to
- a FILE type. To create the appropriate FILE structure (which holds
- buffering info, etc) from the file descriptor integer, use fdopen().
-
- So the above should read something like this:
- myfile = fdopen(socket, "r+");
- as fopen() wants a *char where you have an int.
-
- But then, you actually want to replace stdin, stdout, and stderr,
- so this is what you really want to do:
-
- /* Make sure we don't have some stuff going out the socket that
- should have already gone to the screen */
- fflush(stdout);
- fflush(stderr);
-
- /* Duplicate the socket in the fd's (not *FILE's) for stdin, stdout,
- and stderr */
- for (i = 0; i < 3; i++) dup2(socket, i);
-
- close(socket);
-
- At least, I think that's what you're trying to do. E-mail me
- if you want more info.
-
- Cya,
- Andrew.
-
- /*
- * Andrew Rutherford andrewr@itd.adelaide.edu.au
- * +61 8 228 5669 Real Programmers always confuse Christmas and
- * Room 1060, Adelaide Uni Halloween because OCT 31 == DEC 25 !
- */
-