Messages in this thread | | | Date | Mon, 6 Mar 2000 09:50:50 +0530 (IST) | From | "A.Srinath Reddy" <> | Subject | HELP!!! Passing File descriptors |
| |
Hi,
I want to pass file descriptors between two processes.I read man cmsg where the code for sending fds is given.But how do I receive them.I have tried the following one, but not working.Can anybody please help me.
----- CODE start ---
struct msghdr msg = {0}; struct cmsghdr *cmsg; int myfds[NUM_FD];/* Contains the file descriptors to rcv.*/ char buf[CMSG_SPACE(sizeof myfds)];/* ancillary data buffer*/ int *fdptr;
msg.msg_control = buf; msg.msg_controllen = sizeof buf; cmsg = CMSG_FIRSTHDR(&msg); cmsg->cmsg_level = SOL_SOCKET; cmsg->cmsg_type = SCM_RIGHTS; cmsg->cmsg_len = CMSG_LEN(sizeof(int) * NUM_FD); if( recvmsg( socket, &msg, 0 ) < 0 ) return -1;
fdptr = (int *)CMSG_DATA(cmsg); memcpy(myfds, fdptr, NUM_FD * sizeof(int)); ----- CODE ends ----------
TIA. -Srinath.
- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/
| |