title: Drop an open TCP connection without sending RST
body: <p>Looking into <a href="https://stackoverflow.com/questions/39647668/nginx-ignore-some-requests-without-proper-host-header">nginx: ignore some requests without proper Host header</a> got me thinking that it's not actually possible to <a href="http://mdoc.su/-/close.2" rel="nofollow noreferrer"><code>close(2)</code></a> a TCP connection without the OS properly terminating the underlying TCP connection by sending an <code>RST</code> (and/or <code>FIN</code>) to the other end.</p>
  
  <p><strike>One workaround would be to use something like <a href="http://mdoc.su/-/tcpdrop.8" rel="nofollow noreferrer"><code>tcpdrop(8)</code></a>, however, as can be seen from <a href="http://bxr.su/OpenBSD/usr.sbin/tcpdrop/tcpdrop.c" rel="nofollow noreferrer"><code>usr.sbin/tcpdrop/tcpdrop.c</code> on OpenBSD</a> and <a href="http://bxr.su/f/usr.sbin/tcpdrop/tcpdrop.c" rel="nofollow noreferrer">FreeBSD</a>, it's implemented through a sysctl-based interface, and may have portability issues outside of BSDs. (In fact, it looks like even the sysctl-based implementation may be different enough between OpenBSD and FreeBSD to require a porting layer -- <a href="http://bxr.su/OpenBSD/usr.sbin/tcpdrop/tcpdrop.c#tir" rel="nofollow noreferrer">OpenBSD uses</a> the <a href="http://bxr.su/OpenBSD/sys/netinet/tcp_var.h#tcp_ident_mapping" rel="nofollow noreferrer"><code>tcp_ident_mapping</code></a> structure (which, subsequently, contains two <code>sockaddr_storage</code> elements, plus some other info), whereas <a href="http://bxr.su/f/usr.sbin/tcpdrop/tcpdrop.c#tcpdrop" rel="nofollow noreferrer">FreeBSD</a>, <a href="http://bxr.su/d/usr.sbin/tcpdrop/tcpdrop.c#tcpdrop" rel="nofollow noreferrer">DragonFly</a> and <a href="http://bxr.su/NetBSD/usr.sbin/tcpdrop/tcpdrop.c#sa" rel="nofollow noreferrer">NetBSD</a> use an array of two <code>sockaddr_storage</code> elements directly.)</strike>  It turns out, that OpenBSD's <code>tcpdrop</code> does appear to send the <code>R</code> packet as per <a href="http://mdoc.su/o/tcpdump.8" rel="nofollow noreferrer"><code>tcpdump(8)</code></a>, and can be confirmed by looking at <a href="http://bxr.su/OpenBSD/sys/netinet/tcp_subr.c#tcp_drop" rel="nofollow noreferrer"><code>/sys/netinet/tcp_subr.c :: tcp_drop()</code></a>, which calls <code>tcp_close()</code> in the end (and <code>tcp_close()</code> <a href="//stackoverflow.com/a/23483487/1122270">is confirmed to send <code>RST</code> elsewhere on SO</a>), so, it appears that it wouldn't even work, either.</p>
  
  <p>If I'm establishing the connection myself through C, is there a way to subsequently drop it without an acknowledgement to the other side, e.g., without initiating <code>RST</code>?</p>