in reply to Re: How to read UNIX socket credentials?
in thread How to read UNIX socket credentials?
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: How to read UNIX socket credentials?
by hackman (Acolyte) on Jan 08, 2011 at 10:32 UTC | |
by sayotte (Initiate) on Feb 09, 2012 at 18:28 UTC |