Q:

why does ioctl I_SENDFD return no permission (EPERM)?

I want to send a file descriptor of a tcp socket from process A to process B, so that process B can create another tcp socket with the same file descriptor.
the idea is exactly the same as passing file descriptors
the key function call is the following:
ioctl(fd, I_SENDFD, fd_to_send);

but it always returns EPERM /* Operation not permitted */
I verified the domain socket file descriptor fd is working, as I could send normal messages through that fd.
I don't know what's wrong. I googled, nobody seems to mention I_SENDFD has permission issue. I tried using "sudo" to run my programs. It still doesn't work.
I have also tried allowing everything for that file descriptorfcntl(fd_to_send, F_SETFL, S_IRWXU|S_IRUSR|S_IWUSR|S_IXUSR|S_IRWXG|   S_IRGRP|S_IWGRP|S_IXGRP|S_IRWXO|S_IROTH|S_IWOTH|S_IXOTH);
doesn't work either.
how to fix?

A:

I have found the answer to my question.
Linux doesn't support this, but still keeps the API, which is evil.
for details regarding this issue, see ioctl giving Invalid Argument
here is a workaround solution: Can I share a file descriptor to another process on linux or are they local to the process?
(which I haven't tried)

