Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 15 Oct 2002 12:30:17 -0500
From:      Dan Nelson <dnelson@allantgroup.com>
To:        alireza mahini <alirezamahini@yahoo.com>
Cc:        questions@FreeBSD.ORG
Subject:   Re: How can i use the socket that created by a child in parent?
Message-ID:  <20021015173016.GB16975@dan.emsphone.com>
In-Reply-To: <20021015171750.59644.qmail@web40702.mail.yahoo.com>
References:  <20021015171750.59644.qmail@web40702.mail.yahoo.com>

next in thread | previous in thread | raw e-mail | index | archive | help
In the last episode (Oct 15), alireza mahini said:
> I create a stream socket in a child process and i want
> to use it outside of child.
> main(){
> int sd;
> int fd[2];
> char buf[20];
>  pipe(fd));
>  if(!fork()){
>    sd=socket();
>    ...
>    ...
>   write(fd[1]....);//write sd to the pipe 
>  }
> read(fd[0],...)//read sd from pipe
> send(sd,....);//error is occured in this line at 
> executing the program
> ...
> }
> I understand that the descriptors don't send via pipe
> to the outside of childs so guide me please.

You'll need to use the sendmsg() and recvmsg() functions to pass the
descriptor.  See the unix(4), and recvmsg(2) manpages for more info.

-- 
	Dan Nelson
	dnelson@allantgroup.com

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20021015173016.GB16975>