lkml.org 
[lkml]   [2000]   [Mar]   [5]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectHELP!!! 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/

\
 
 \ /
  Last update: 2005-03-22 13:56    [W:2.536 / U:0.008 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site