--- sys/netinet/tcp_usrreq.c.old 2014-12-16 12:06:56.255281206 -0800 +++ sys/netinet/tcp_usrreq.c 2014-12-16 16:15:48.703249522 -0800 @@ -460,8 +461,12 @@ inp = sotoinpcb(so); KASSERT(inp != NULL, ("tcp_usr_connect: inp == NULL")); INP_WLOCK(inp); - if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) { - error = EINVAL; + if (inp->inp_flags & (INP_TIMEWAIT)) { + error = EADDRINUSE; + goto out; + } + if (inp->inp_flags & (INP_DROPPED)) { + error = ECONNREFUSED; goto out; } tp = intotcpcb(inp); @@ -507,8 +512,12 @@ inp = sotoinpcb(so); KASSERT(inp != NULL, ("tcp6_usr_connect: inp == NULL")); INP_WLOCK(inp); - if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) { - error = EINVAL; + if (inp->inp_flags & (INP_TIMEWAIT)) { + error = EADDRINUSE; + goto out; + } + if (inp->inp_flags & (INP_DROPPED)) { + error = ECONNREFUSED; goto out; } tp = intotcpcb(inp); @@ -730,7 +739,7 @@ KASSERT(inp != NULL, ("inp == NULL")); INP_WLOCK(inp); if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) { - error = ECONNRESET; + error = ENOTCONN; goto out; } tp = intotcpcb(inp); @@ -763,7 +772,7 @@ KASSERT(inp != NULL, ("tcp_usr_rcvd: inp == NULL")); INP_WLOCK(inp); if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) { - error = ECONNRESET; + error = ENOTCONN; goto out; } tp = intotcpcb(inp); @@ -814,7 +823,7 @@ m_freem(control); if (m) m_freem(m); - error = ECONNRESET; + error = ENOTCONN; goto out; } #ifdef INET6