Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #58191 > unrolled thread
| Started by | Roy Smith <roy@panix.com> |
|---|---|
| First post | 2013-10-31 12:16 -0400 |
| Last post | 2013-11-03 03:27 +0000 |
| Articles | 5 — 3 participants |
Back to article view | Back to comp.lang.python
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
| From | Roy Smith <roy@panix.com> |
|---|---|
| Date | 2013-10-31 12:16 -0400 |
| Subject | getpeername() 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]
| From | Nobody <nobody@nowhere.com> |
|---|---|
| Date | 2013-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]
| From | random832@fastmail.us |
|---|---|
| Date | 2013-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]
| From | Roy Smith <roy@panix.com> |
|---|---|
| Date | 2013-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]
| From | Nobody <nobody@nowhere.com> |
|---|---|
| Date | 2013-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