home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / unix / ultrix / 8354 < prev    next >
Encoding:
Internet Message Format  |  1992-11-17  |  1.8 KB

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