Le 18 mai 04, 23:20, Yukihiro Matsumoto a ˝─rit :
> I like the idea.  But I don't want to merge it if it's Linux
> specific.  Any idea?
>

Two ideas.

1) This works fine too:
class UNIXSocket
   def getpeercredentials
     getsockopt(Socket::SOL_SOCKET, Socket::SO_PEERCRED).unpack("i3")
   end
end

No need for C code. Tested on Linux. A web search tells me that the 
SO_PEERCRED option is supported on the BSD family as well. The closest 
thing to a BSD machine I have is a MacOS X box, which doesn't support 
it. Can anybody try this piece of code on *BSD?

2) There seems to be a similar mechanism as the Linux one to pass this 
information as ancillary data and *BSD, with the SCM_CREDS cmsg type 
and struct cmsgcred. But once again, Apple is failing on me: the 
definition of struct cmsgcred is surrounded by #ifndef __APPLE__  ... 
#endif.

The advantage of sending ancillary data compared to getsockopt is that 
you can send you euid and egid instead of uid and gid.

Guillaume.