[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to reset TCP connection on Linux?

On 2018-12-03, Jon Ribbens <jon+usenet at unequivocal.eu> wrote:
> On 2018-12-03, Grant Edwards <grant.b.edwards at gmail.com> 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
                              gmail.com            '81 ...