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.
-----------------------------------------------------------------------
For more information on the LIH mailing list see:
http://lists.linux-india.org/lists/LIH