How to reset TCP connection on Linux?

Grant Edwards grant.b.edwards at
Mon Dec 3 14:54:47 EST 2018

On 2018-12-03, Jon Ribbens <jon+usenet at> wrote:
> On 2018-12-03, Grant Edwards <grant.b.edwards at> wrote:
>> How does one reset a TCP connection on Linux?  Note that I want to
>> reset the connection, not close it.
> Something like the following should work I believe, although I have
> not tested it:
>     sock.setsockopt(
>         socket.SOL_SOCKET,
>         socket.SO_LINGER,
>         struct.pack('ii', 1, 0)
>     )
>     sock.close()


Setting SO_LINGER with a 0 timeout is the answer.  I've been googling
for that (on and off) for the past week, and just could not come up
with the right search terms.  Of course adding so_linger to just about
any of my attempts leads immediately to detailed descriptions
including cites to the appropriate section of Stevens and pointers to
where in the kernel it's actually implemented.

Here's a good page:

Grant Edwards               grant.b.edwards        Yow! I had a lease on an
                                  at               OEDIPUS COMPLEX back in
                                '81 ...

More information about the Python-list mailing list