LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-13-2005, 09:28 AM   #1
elmafiacs
LQ Newbie
 
Registered: Apr 2004
Posts: 27

Rep: Reputation: 15
Redirecting socket output to a file


Hi,

I need help on these questions:
a) How do I redirect the data that flows through a socket to a file, without cutting the flow?
b) Can a file number be returned from a function, and when I do a read() or a write() call, will it remain the same? (see below).

What I was thinking for the first question is to:
- create a pipe with the pipe() system call
- make the file descriptor of the "write" side of the pipe to be the same as the file descriptor of the socket
- create a file with the O_ASYNC flag, in so a way that when there's something to be written to the file, a signal is sent.
- make the file descriptor of the "read" side of the pipe to be the same as the file descriptor of this file.

But there are two things:
a) Is there a better approach?
b) How do I open() a file that has the file descriptor number I want?

What I was thinking for the second question was:
Code:
void mkchild(int fd)
{
    struct child_struct child;
    child->sockfd = fd;
    send(child->sockfd, ...);  /* will this work? */
}

void getsock(void)
{
    int sockfd;
    sockfd = accept();
    mkchild(sockfd);
}
But I don't know if it'll work.

Thanks in advance.

Last edited by elmafiacs; 10-13-2005 at 09:30 AM.
 
Old 10-15-2005, 05:18 AM   #2
plastik
LQ Newbie
 
Registered: Oct 2005
Distribution: Slackware
Posts: 2

Rep: Reputation: 0
Quote:
b) How do I open() a file that has the file descriptor number I want?
man 3 fdopen

You might also want to check out:

man 2 dup2
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Redirecting colsole output to file. danimallv Linux - General 4 07-05-2005 02:44 PM
why when redirecting output to a file any file extension seems to be fine? dr_zayus69 Linux - General 1 05-21-2005 04:09 AM
redirecting output of compile to a file halfcan Linux - Hardware 1 02-05-2005 10:01 PM
Redirecting mplayer output driptray Linux - Software 1 10-12-2004 07:42 AM
redirecting cpio screen output to file rawii Solaris / OpenSolaris 1 02-11-2004 09:28 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:21 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration