Socket::PassAccessRights - Perl extension for BSD style file descriptor passing via Unix domain sockets
use Socket::PassAccessRights; Socket::PassAccessRights::sendfd(fileno(SOCKET), fileno(SEND_ME)) or die; $fd = Socket::PassAccessRights::recvfd(fileno(SOCKET)) or die; open FD, ">&=$fd" or die "$!"; # convert int fd to file handle
Implements passing access rights (i.e. file descritors) over Unix domain sockets. Only one fd can be passed at one time and no other data can be sent in the same operation (operation itself involves sending exactly one byte of data to solve EOF detection anomaly).
See test.pl and examples directory for usage examples.
This code has only been tested on
* Linux-2.0.38 with glibc-2.0.7 (libc.so.6) and libc.so.5 (BSD4.4 style) * Linux-2.2.14 with glibc-2.0.7 (libc.so.6) (BSD4.4 style) * Solaris-2.6 using gcc (BSD4.3 style)
Specifically, the code from [Stevens] did not work out of the box. I had to rename msg.msg_accrights* to msg.control* and send at least one byte. General impression from net is that file descripto passing code seems to be buggy - not just in Linux, but on FreeBSD, too.
Sampo Kellomaki <firstname.lastname@example.org>
Copyright (c) 2000 by Sampo Kellomaki <email@example.com>, All Rights Reserved.
This module may be copied under the same terms as perl itself.
Home page: http://www.bacus.pt/Net_SSLeay/modules.html perl(1) recvmsg(2) sendmsg(2) Richard Stevens: Unix Network Programming, Prentice Hall, 1990; chapter 6.10. /usr/include/socketbits.h /usr/include/sys/socket.h