I have a socket proxy written in Python which when it receives a RST from a pair of communicating peers will close the connection to both peers by letting the sockets be garbage collected. This results in the other peer seeing a FIN rather than a RST.
This means the proxy effectively translates RST into FIN, which I don't think is ideal.
I found that in Linux it possible to reset a TCP connnection by calling connect with an address of family AF_UNSPEC
. But I haven't found a way to do this from a Python program.
How do I connect
to an AF_UNSPEC
address in Python?
What I have tried so far
I tried looking at the help
output for the relevant connect
method and found this:
Help on built-in function connect:
connect(...)
connect(address)
Connect the socket to a remote address. For IP sockets, the address
is a pair (host, port).
Unfortunately that doesn't tell me what the address
argument has to be in order to construct a AF_UNSPEC
address.
I attempted to wrap the original socket fd in a new socket object with family AF_UNSPEC
like this:
socket.fromfd(s.fileno(), socket.AF_UNSPEC, 0)
The resulting object produce the same help text and any attempt to call connect
on the newly constructed socket object results in
socket.error: getsockaddrarg: bad family
So it looks like using socket.fromfd
is probably not the answer to my question.