kevent behavior with TCP socket
Adrian Penisoara
ady at freebsd.ady.ro
Mon Aug 10 07:31:46 UTC 2009
Hi,
On Mon, Aug 10, 2009 at 5:17 AM, Denis Berezhnoy
<denis.berezhnoy at gmail.com>wrote:
> Hi Adrian,
> Thank for your answer! I checked that nobody listens for loopback address:
>
> [denis at freebsd ~]$ sockstat -4
> USER COMMAND PID FD PROTO LOCAL ADDRESS FOREIGN ADDRESS
>
> denis sshd 95390 3 tcp4 192.168.1.103:22
> 192.168.11.26:53616
> root sshd 95387 3 tcp4 192.168.1.103:22
> 192.168.11.26:53616
> denis sshd 95324 3 tcp4 192.168.1.103:22
> 192.168.11.26:53608
> root sshd 95321 3 tcp4 192.168.1.103:22
> 192.168.11.26:53608
> root sshd 8149 4 tcp4 *:22 *:*
> root inetd 870 5 tcp4 *:21 *:*
> root inetd 870 6 tcp4 *:23 *:*
> root sendmail 821 4 tcp4 127.0.0.1:25 *:*
> root syslogd 689 7 udp4 *:514 *:*
> [denis at freebsd ~]$
>
>
> I printed out fflags. Here is the result:
>
> Kevent event num 1 wait time 46
> Event filter -2 flag 0 filter flags 0 data 43008
>
>
> When I comment out the part of the code that listens socket then I have the
> following output:
>
> Kevent event num 1 wait time 23
> Event filter -2 flag 32768 filter flags 61 data 32768
>
>
> 61 is ECONNREFUSED
>
>
> And more when I make loopback address listening and try to connect it I
> still get the same output:
>
> Socket test start
> Failed to connect with server 36
> Kevent event num 1 wait time 23
> Event filter -2 flag 0 filter flags 0 data 43008
> Socket test end
>
> but connection is actually accepted. I am totally confused here.
>
Well, actually it's very much evident:
* When you don't make the listen() first, then the connection is correctly
reported as refused
* When you make the listen() on the INADDR_ANY then you will open port
10000 on all local IP addresses, _including_ the loopback address -- that's
why the client connect() succeeds and kevent reports a success event. This
is an expected behavior.
Try to bind the sd descriptor to another port than the one used to connect
onto the loopback address and you will see the connection being refused.
Regards,
Adrian
EnterpriseBSD
More information about the freebsd-net
mailing list