Skip to content

Instantly share code, notes, and snippets.

@polynomial
Last active May 7, 2017 02:35
Show Gist options
  • Save polynomial/833793df1e1d5d2b4a7ef48869b711d2 to your computer and use it in GitHub Desktop.
Save polynomial/833793df1e1d5d2b4a7ef48869b711d2 to your computer and use it in GitHub Desktop.
start a listener and then 'suspend it' so that the connections will be accepted by the kernel but not the process:
bsmith1pts/8bsmith-y900~ nc -vvvlp 8080
Listening on any address 8080 (http-alt)
^Z
[1] + 7303 suspended nc -vvvlp 8080
verify its listening:
bsmith148pts/8bsmith-y900~ netstat -an | grep 8080
tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN
open some connections:
$ echo test | nc localhost 8080 &
[3] 7313
$ echo test | nc localhost 8080 &
[4] 7315
bsmith0pts/8bsmith-y900~ netstat -an | grep 8080
tcp 1 0 0.0.0.0:8080 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:48736 127.0.0.1:8080 ESTABLISHED
tcp 5 0 127.0.0.1:8080 127.0.0.1:48736 ESTABLISHED
open some more (same nc & as above): after 5 we see a SYN_RECV:
which agrees with [1] and [2]
bsmith0pts/8bsmith-y900~ netstat -an | grep 8080
tcp 5 0 0.0.0.0:8080 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:48816 127.0.0.1:8080 ESTABLISHED
tcp 5 0 127.0.0.1:8080 127.0.0.1:48816 ESTABLISHED
tcp 5 0 127.0.0.1:8080 127.0.0.1:48812 ESTABLISHED
tcp 0 5 127.0.0.1:48826 127.0.0.1:8080 ESTABLISHED
tcp 0 0 127.0.0.1:48812 127.0.0.1:8080 ESTABLISHED
tcp 5 0 127.0.0.1:8080 127.0.0.1:48822 ESTABLISHED
tcp 0 0 127.0.0.1:8080 127.0.0.1:48826 SYN_RECV
tcp 0 0 127.0.0.1:48822 127.0.0.1:8080 ESTABLISHED
tcp 5 0 127.0.0.1:8080 127.0.0.1:48802 ESTABLISHED
tcp 0 0 127.0.0.1:48736 127.0.0.1:8080 ESTABLISHED
tcp 5 0 127.0.0.1:8080 127.0.0.1:48736 ESTABLISHED
tcp 0 0 127.0.0.1:48802 127.0.0.1:8080 ESTABLISHED
if we open more (more nc &) we see them go into SYN_RECV too
bsmith0pts/8bsmith-y900~ netstat -an | grep 8080
tcp 5 0 0.0.0.0:8080 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:48816 127.0.0.1:8080 ESTABLISHED
tcp 5 0 127.0.0.1:8080 127.0.0.1:48816 ESTABLISHED
tcp 5 0 127.0.0.1:8080 127.0.0.1:48812 ESTABLISHED
tcp 0 5 127.0.0.1:48826 127.0.0.1:8080 ESTABLISHED
tcp 0 0 127.0.0.1:48812 127.0.0.1:8080 ESTABLISHED
tcp 5 0 127.0.0.1:8080 127.0.0.1:48822 ESTABLISHED
tcp 0 0 127.0.0.1:8080 127.0.0.1:48826 SYN_RECV
tcp 0 0 127.0.0.1:48822 127.0.0.1:8080 ESTABLISHED
tcp 5 0 127.0.0.1:8080 127.0.0.1:48802 ESTABLISHED
tcp 0 0 127.0.0.1:48736 127.0.0.1:8080 ESTABLISHED
tcp 5 0 127.0.0.1:8080 127.0.0.1:48736 ESTABLISHED
tcp 0 0 127.0.0.1:48802 127.0.0.1:8080 ESTABLISHED
bsmith0pts/8bsmith-y900~ netstat -an | grep 8080
tcp 5 0 0.0.0.0:8080 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:48816 127.0.0.1:8080 ESTABLISHED
tcp 5 0 127.0.0.1:8080 127.0.0.1:48816 ESTABLISHED
tcp 0 5 127.0.0.1:48880 127.0.0.1:8080 ESTABLISHED
tcp 5 0 127.0.0.1:8080 127.0.0.1:48812 ESTABLISHED
tcp 0 5 127.0.0.1:48826 127.0.0.1:8080 ESTABLISHED
tcp 0 0 127.0.0.1:48812 127.0.0.1:8080 ESTABLISHED
tcp 5 0 127.0.0.1:8080 127.0.0.1:48822 ESTABLISHED
tcp 0 0 127.0.0.1:8080 127.0.0.1:48826 SYN_RECV
tcp 0 0 127.0.0.1:48822 127.0.0.1:8080 ESTABLISHED
tcp 5 0 127.0.0.1:8080 127.0.0.1:48802 ESTABLISHED
tcp 0 0 127.0.0.1:48736 127.0.0.1:8080 ESTABLISHED
tcp 0 0 127.0.0.1:8080 127.0.0.1:48880 SYN_RECV
tcp 5 0 127.0.0.1:8080 127.0.0.1:48736 ESTABLISHED
tcp 0 0 127.0.0.1:48802 127.0.0.1:8080 ESTABLISHED
1: http://man7.org/linux/man-pages/man2/listen.2.html
2: line 656-657 https://sourceforge.net/p/netcat/code/HEAD/tree/trunk/src/network.c#l657
@Ralhp
Copy link

Ralhp commented May 7, 2017

Hello

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment