Pretty sure it'll work with an unblessed UNIX socket handle too.
my ($pid, $uid, $gid) = IO::Handle::Record::peercred($client);
If not, it should be easy to code in pure Perl since the above function is simply
void smh_peercred(s) PerlIO* s; PROTOTYPE: $ PPCODE: { # ifdef SO_PEERCRED struct ucred uc; socklen_t uc_len=sizeof(uc); if( !getsockopt(PerlIO_fileno(s), SOL_SOCKET, SO_PEERCRED, &uc, &uc_ +len) ) { EXTEND(SP, 3); PUSHs(sv_2mortal(newSViv(uc.pid))); PUSHs(sv_2mortal(newSViv(uc.uid))); PUSHs(sv_2mortal(newSViv(uc.gid))); } # else SETERRNO(EOPNOTSUPP, RMS_IFI); # endif }
and fileno (builtin), getsockopt (builtin), SOL_SOCKET (Socket) and SO_PEERCRED (Socket) are all in core Perl.
Mind you, IO::Socket::UNIX is just a thin layer that greatly simplifies socket calls with no loss of flexibility, so I wonder why you want to try to avoid it.
In reply to Re^2: How to read UNIX socket credentials?
by ikegami
in thread How to read UNIX socket credentials?
by hackman
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |