Determine socket family at runtime

Giampaolo Rodola' gnewsg at gmail.com
Sun May 4 10:49:55 EDT 2008


Hi there,
since the socket.socket.family attribute has been introduced only in
Python 2.5 and I need to have my application to be backward compatible
with Python 2.3 and 2.4 I'd like to know how could I determine the
family of a socket.socket instance which may be AF_INET or AF_INET6.
Is there some kind of getsockopt() directive I could use?
For now I've been able to determine the family by using:

# self.socket = a connected socket.socket instance
ip, port = self.socket.getsockname()[0:2]
af = socket.getaddrinfo(ip, port)[0][0]

...but I'd like to know if some other solution is preferable.



Thanks.


--- Giampaolo
http://code.google.com/p/pyftpdlib



More information about the Python-list mailing list