HELP!!! Passing File descriptors

From: A.Srinath Reddy (reddy@peacock.iitm.ernet.in)
Date: Sun Mar 05 2000 - 23:20:50 EST

  • Next message: Andreas Dilger: "Re: cow-links"

    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/



    This archive was generated by hypermail 2b29 : Sun Mar 05 2000 - 23:41:47 EST