getpeername() on stdin?

R

Roy Smith

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?
 
N

Nobody

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.
 
R

random832

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?
 
R

Roy Smith

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.
 
N

Nobody

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top