Slightly OT: detecting the socket type of a descriptor

Heiko Wundram modelnine at
Tue Jan 3 20:15:32 EST 2006

Hi all!

I'm currently in the process of implementing SCM_RIGHTS support for Python
in the socket module, and I'm stuck at wrapping socket descriptors in an
appropriate socket object.

The problem boils down to the fact that I can test for the type of a file
descriptor being a socket, but after I know that it's a socket I can't seem
to test for the address and/or protocol family, which is kinda important to
create the appropriate Python socket object. (for files, creating an
appropriate python file object is easier, as the file open type can be
gotten from the stat structure)

Anyway, is there a way to reliably detect this? Thanks for any insight!

btw. if you're interested in the socket module's extension, have a look at

for the complete bowels of the enhanced _socket module implementation,
especially the recvmsg() function.

--- Heiko.

More information about the Python-list mailing list