LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   using a socket decriptor opened by anoter process (https://www.linuxquestions.org/questions/programming-9/using-a-socket-decriptor-opened-by-anoter-process-171206/)

sudheernair 04-17-2004 04:02 AM

using a socket decriptor opened by anoter process
 
when i start using( send data) the socket descriptor that another process had opened and passed it to current program i got bad descriptor error. any idea how to transfer the permissions or security clearance for an file descriptor.
Thanks Sudheer

Hko 04-17-2004 06:21 AM

How did you pass it to the other process?

TedMaul 04-17-2004 08:47 PM

If you're using unix-domain sockets to pass the fd, there's some arcane feature you can use to do this. I can't remember the details, but `man 7 unix` should give you a brief overview.

aluser 04-17-2004 09:57 PM

To clarify, it sounds like the OP was just sending the int for the file descriptor over a regular pipe or socket. This isn't enough information: that integer is not unique between processes.

So you have to use this crazy feature of unix domain sockets with sendmsg() so the kernel can effectively dup() your descriptor for the other process.. Cool feature, a little weird though.

sudheernair 04-19-2004 01:17 AM

I passed it through shared memory. now let me try your suggessions. thank you all for replaying.
Sudheer

sudheernair 04-19-2004 10:15 AM

okay, i tried dup2 and fcntl functions but it didn't work. if the process that created the socket discriptor calls these function then further communication on the duplicate descriptor works. But if it is with the another process then fails. :(
Sudheer

TedMaul 04-19-2004 11:20 AM

Well, yes - that's as expected. If you call dup() or dup2(), all it does it duplicate the fd for the calling process. To use that fd in another process, you have to pass it through a unix-domain socket, using SCM_RIGHTS.


All times are GMT -5. The time now is 05:32 PM.