Re: select refuses connection with datagrams

Meelis Roos (mroos@tartu.cyber.ee)
Sat, 3 Oct 1998 15:33:58 +0300


MH> I have noticed a problem with Linux that has existed for the last couple
MH> of years. It involves basic networking functionality. I have tried for a
MH> long time to figure out what is wrong but I just can not figure out the
MH> problem. Basically, if you send a datagram with the function sendto you
MH> periodically get the error "Connection refused".

Yes. You probably get it every second try.

That's the correct behavior, linux respects the returning ICMP packets as
some rfc describes. Long time ago linux was broken and didn't respect them
and gave you no chance to see that the packet didn't get through. As you
note, it's working for several years.

What's happnening: you create a udp socket and send a datagram to some
destination. If the destination host is up and there's a socket bound to
the destination port, the message gets through. Otherwise when the host is
up but no socket is bound to the port an ICMP message is generated by the
destination host and sent to you. It basically says "nobody home there".
Linux catches it and sets your socket state.

Now when you send the next packet, the status is read and you get an error
associated with your previous packet. This is normal.

It's a feature, not a bug. It makes possible to see the errors that are
otherwise lost. Usually there's no need to send further packets when nobody
is listening (yes, you might retry later or next day).

-- 
Meelis Roos (mroos@tartu.cyber.ee)

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/