getpeername() on stdin?
Roy Smith
roy at panix.com
Fri Nov 1 20:26:50 EDT 2013
In article <mailman.1937.1383332149.18130.python-list at python.org>,
random832 at fastmail.us wrote:
> On Thu, Oct 31, 2013, at 21:12, Nobody wrote:
> > On Thu, 31 Oct 2013 12:16:23 -0400, Roy Smith wrote:
> >
> > > I want to do getpeername() on stdin. I know I can do this by wrapping a
> > > socket object around stdin, with
> > >
> > > s = socket.fromfd(sys.stdin.fileno(), family, type)
> > >
> > > but that requires that I know what the family and type are. What I want
> > > to do is discover the family and type by looking at what getpeername()
> > > and/or getsockname() return. Can this be done with the standard library?
> >
> > I think that you'd need to use ctypes to access the underlying
> > getpeername() function from libc.
>
> If it's possible to get this information with only the fd, then why does
> socket.fromfd require them?
Because socket.fromfd() is a very simplistic alternate way to create a
socket object, which meets a common use case that happens not to be my
use case.
More information about the Python-list
mailing list