Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #58191 > unrolled thread

getpeername() on stdin?

Started byRoy Smith <roy@panix.com>
First post2013-10-31 12:16 -0400
Last post2013-11-03 03:27 +0000
Articles 5 — 3 participants

Back to article view | Back to comp.lang.python


Contents

  getpeername() on stdin? Roy Smith <roy@panix.com> - 2013-10-31 12:16 -0400
    Re: getpeername() on stdin? Nobody <nobody@nowhere.com> - 2013-11-01 01:12 +0000
      Re: getpeername() on stdin? random832@fastmail.us - 2013-11-01 14:55 -0400
        Re: getpeername() on stdin? Roy Smith <roy@panix.com> - 2013-11-01 20:26 -0400
        Re: getpeername() on stdin? Nobody <nobody@nowhere.com> - 2013-11-03 03:27 +0000

#58191 — getpeername() on stdin?

FromRoy Smith <roy@panix.com>
Date2013-10-31 12:16 -0400
Subjectgetpeername() on stdin?
Message-ID<mailman.1885.1383236191.18130.python-list@python.org>
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?

---
Roy Smith
roy@panix.com


[toc] | [next] | [standalone]


#58222

FromNobody <nobody@nowhere.com>
Date2013-11-01 01:12 +0000
Message-ID<pan.2013.11.01.01.12.30.485000@nowhere.com>
In reply to#58191
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.

[toc] | [prev] | [next] | [standalone]


#58285

Fromrandom832@fastmail.us
Date2013-11-01 14:55 -0400
Message-ID<mailman.1937.1383332149.18130.python-list@python.org>
In reply to#58222
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?

[toc] | [prev] | [next] | [standalone]


#58300

FromRoy Smith <roy@panix.com>
Date2013-11-01 20:26 -0400
Message-ID<roy-B1B9CD.20265001112013@news.panix.com>
In reply to#58285
In article <mailman.1937.1383332149.18130.python-list@python.org>,
 random832@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.

[toc] | [prev] | [next] | [standalone]


#58359

FromNobody <nobody@nowhere.com>
Date2013-11-03 03:27 +0000
Message-ID<pan.2013.11.03.03.27.20.540000@nowhere.com>
In reply to#58285
On Fri, 01 Nov 2013 14:55:38 -0400, random832 wrote:

> If it's possible to get this information with only the fd, then why does
> socket.fromfd require them?

The only person who can answer that is whoever came up with
socket.fromfd() in the first place.

I initially suspected that it might have been a Windows limitation, but
socket.fromfd() is only available on Unix.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web